diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f1c41a62..4f32047a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Made the historical market data editor expandable in the admin control panel - Renamed `Subscription` to `subscriptions` in the `User` database schema +- 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 32aff4387..518056dfd 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,