From 1ae5ba7f8a2e6c83ff67feabd002dc87d3238b23 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 21 Apr 2025 07:42:32 +0200 Subject: [PATCH] Feature/parallelize asset profile requests in get quotes functionality of Financial Modeling Prep service (#4569) * Parallelize asset profile requests * Update changelog --- CHANGELOG.md | 1 + .../financial-modeling-prep.service.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd4c0a2c..5e836484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Made the historical market data editor expandable in the admin control panel +- Parallelized the requests in the get quotes functionality of the _Financial Modeling Prep_ service ### Fixed 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 32aff438..518056df 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 @@ -357,6 +357,10 @@ export class FinancialModelingPrepService implements DataProviderInterface { } try { + const currencyBySymbolMap: { + [symbol: string]: Pick; + } = {}; + const quotes = await fetch( `${this.getUrl({ version: 'stable' })}/batch-quote-short?symbols=${symbols.join(',')}&apikey=${this.apiKey}`, { @@ -364,11 +368,17 @@ export class FinancialModelingPrepService implements DataProviderInterface { } ).then((res) => res.json()); - for (const { price, symbol } of quotes) { - const { currency } = await this.getAssetProfile({ symbol }); + await Promise.all( + quotes.map(({ symbol }) => { + return this.getAssetProfile({ symbol }).then(({ currency }) => { + currencyBySymbolMap[symbol] = { currency }; + }); + }) + ); + for (const { price, symbol } of quotes) { response[symbol] = { - currency, + currency: currencyBySymbolMap[symbol]?.currency, dataProviderInfo: this.getDataProviderInfo(), dataSource: DataSource.FINANCIAL_MODELING_PREP, marketPrice: price,