From 6e1935899f4f4250e53e075a7ccb111a8dccc521 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 6 Oct 2022 15:15:36 +0200 Subject: [PATCH] Bugfix/fix cryptocurrency symbols with less than 3 characters (#1325) * Fix cryptocurrency symbols with less than 3 characters * Update changelog --- CHANGELOG.md | 4 ++++ .../yahoo-finance/yahoo-finance.service.ts | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d922bd9..37357865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the caching of the benchmarks in the markets overview (only cache if fetching was successful) +### Fixed + +- Fixed the support for cryptocurrencies having a symbol with less than 3 characters (e.g. `SC-USD`) + ## 1.201.0 - 01.10.2022 ### Added diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index bc408ca4..64d318ac 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -58,8 +58,15 @@ export class YahooFinanceService implements DataProviderInterface { * DOGEUSD -> DOGE-USD */ public convertToYahooFinanceSymbol(aSymbol: string) { - if (aSymbol.includes(this.baseCurrency) && aSymbol.length >= 6) { - if (isCurrency(aSymbol.substring(0, aSymbol.length - 3))) { + if ( + aSymbol.includes(this.baseCurrency) && + aSymbol.length > this.baseCurrency.length + ) { + if ( + isCurrency( + aSymbol.substring(0, aSymbol.length - this.baseCurrency.length) + ) + ) { return `${aSymbol}=X`; } else if ( this.cryptocurrencyService.isCryptocurrency(