From 2388c494dfd6641ccbbf819da23675f44b522b3f Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 10 Jul 2022 22:24:27 +0200 Subject: [PATCH] Feature/handle currency pair inconsistency in yahoo finance service (#1069) * Handle occasional currency pair inconsistency: GBP=X instead of USDGBP=X * Update changelog --- CHANGELOG.md | 4 ++++ .../data-provider/yahoo-finance/yahoo-finance.service.ts | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e5c25ec..8586116b4 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 - Extended the investment timeline grouped by month +### Changed + +- Handled an occasional currency pair inconsistency in the _Yahoo Finance_ service (`GBP=X` instead of `USDGBP=X`) + ### Fixed - Fixed the content height of the account detail dialog 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 b2c79284b..34556b061 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 @@ -37,10 +37,15 @@ export class YahooFinanceService implements DataProviderInterface { } public convertFromYahooFinanceSymbol(aYahooFinanceSymbol: string) { - const symbol = aYahooFinanceSymbol.replace( + let symbol = aYahooFinanceSymbol.replace( new RegExp(`-${this.baseCurrency}$`), this.baseCurrency ); + + if (symbol.includes('=X') && !symbol.includes(this.baseCurrency)) { + symbol = `${this.baseCurrency}${symbol}`; + } + return symbol.replace('=X', ''); }