From a81b76b95469fdc98258012f67c7c394e3d11721 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:57:16 +0200 Subject: [PATCH] Use asset profile resolutions in getQuotes() --- .../financial-modeling-prep.service.ts | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts index 3b0d8ba72..7c1395a23 100644 --- a/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts +++ b/apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts @@ -373,26 +373,42 @@ export class FinancialModelingPrepService implements DataProviderInterface { { signal: AbortSignal.timeout(requestTimeout) } - ).then((res) => res.json()) + ).then( + (res) => res.json() as unknown as { price: number; symbol: string }[] + ) ]); - if (assetProfileResolutions.length === symbols.length) { - for (const { currency, symbolTarget } of assetProfileResolutions) { - currencyBySymbolMap[symbolTarget] = { currency }; + for (const { currency, symbolTarget } of assetProfileResolutions) { + currencyBySymbolMap[symbolTarget] = { currency }; + } + + const resolvedSymbols = assetProfileResolutions.map( + ({ symbolTarget }) => { + return symbolTarget; } - } else { + ); + + const symbolsToFetch = quotes + .map(({ symbol }) => { + return symbol; + }) + .filter((symbol) => { + return !resolvedSymbols.includes(symbol); + }); + + if (symbolsToFetch.length > 0) { await Promise.all( - quotes.map(({ symbol }) => { - return this.getAssetProfile({ + symbolsToFetch.map(async (symbol) => { + const assetProfile = await this.getAssetProfile({ requestTimeout, symbol - }).then((assetProfile) => { - if (assetProfile?.currency) { - currencyBySymbolMap[symbol] = { - currency: assetProfile.currency - }; - } }); + + if (assetProfile?.currency) { + currencyBySymbolMap[symbol] = { + currency: assetProfile.currency + }; + } }) ); }