From c467c946d428b66e029814d0caabe10aa1235d06 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 22 Mar 2025 17:52:16 +0100 Subject: [PATCH] Bugfix/fix symbol validation in Yahoo Finance service (#4472) * Fix symbol validation * Add test cases --- .../data-enhancer/yahoo-finance/yahoo-finance.service.ts | 2 +- test/import/invalid-symbol-btc-usd.csv | 2 ++ test/import/ok-btcusd.csv | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/import/invalid-symbol-btc-usd.csv create mode 100644 test/import/ok-btcusd.csv diff --git a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts index 78644726..d876b42c 100644 --- a/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service.ts @@ -170,7 +170,7 @@ export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { symbol = quotes[0].symbol; } } catch {} - } else if (symbol?.includes('-')) { + } else if (symbol?.endsWith(`-${DEFAULT_CURRENCY}`)) { throw new Error(`${symbol} is not valid`); } else { symbol = this.convertToYahooFinanceSymbol(symbol); diff --git a/test/import/invalid-symbol-btc-usd.csv b/test/import/invalid-symbol-btc-usd.csv new file mode 100644 index 00000000..d2c91be7 --- /dev/null +++ b/test/import/invalid-symbol-btc-usd.csv @@ -0,0 +1,2 @@ +Date,Code,Currency,Price,Quantity,Action,Fee +12/12/2021,BTC-USD,USD,44558.42,1,buy,0 diff --git a/test/import/ok-btcusd.csv b/test/import/ok-btcusd.csv new file mode 100644 index 00000000..8cddc127 --- /dev/null +++ b/test/import/ok-btcusd.csv @@ -0,0 +1,2 @@ +Date,Code,Currency,Price,Quantity,Action,Fee +12/12/2021,BTCUSD,USD,44558.42,1,buy,0