From 137d24eedad071cca8014b3eb4e63c7e7ae2cf9a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 28 Aug 2026 11:56:35 +0200 Subject: [PATCH] Improve handling of indices --- .../financial-modeling-prep.service.ts | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 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 26cf43a5c..da3d20a07 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 @@ -591,28 +591,17 @@ export class FinancialModelingPrepService }; }); } else { - const queryParams = new URLSearchParams({ - query, - apikey: this.apiKey - }); - const [nameResults, symbolResults] = await Promise.all([ - this.fetchService - .fetch( - `${this.getUrl({ version: 'stable' })}/search-name?${queryParams.toString()}`, - { - signal: AbortSignal.timeout(requestTimeout) - } - ) - .then((res) => res.json()), - this.fetchService - .fetch( - `${this.getUrl({ version: 'stable' })}/search-symbol?${queryParams.toString()}`, - { - signal: AbortSignal.timeout(requestTimeout) - } - ) - .then((res) => res.json()) + this.getSearchResults({ + query, + requestTimeout, + endpoint: 'search-name' + }), + this.getSearchResults({ + query, + requestTimeout, + endpoint: 'search-symbol' + }) ]); const result = uniqBy( @@ -682,20 +671,12 @@ export class FinancialModelingPrepService requestTimeout: number; symbol: string; }): Promise> { - const queryParams = new URLSearchParams({ - apikey: this.apiKey, + const results = await this.getSearchResults({ + requestTimeout, + endpoint: 'search-symbol', query: symbol }); - const results = await this.fetchService - .fetch( - `${this.getUrl({ version: 'stable' })}/search-symbol?${queryParams.toString()}`, - { - signal: AbortSignal.timeout(requestTimeout) - } - ) - .then((res) => res.json()); - const index = results?.find(({ exchange, symbol: symbolOfResult }) => { return exchange === 'INDEX' && symbolOfResult === symbol; }); @@ -710,6 +691,30 @@ export class FinancialModelingPrepService }; } + private async getSearchResults({ + endpoint, + query, + requestTimeout + }: { + endpoint: 'search-name' | 'search-symbol'; + query: string; + requestTimeout: number; + }) { + const queryParams = new URLSearchParams({ + query, + apikey: this.apiKey + }); + + return this.fetchService + .fetch( + `${this.getUrl({ version: 'stable' })}/${endpoint}?${queryParams.toString()}`, + { + signal: AbortSignal.timeout(requestTimeout) + } + ) + .then((res) => res.json()); + } + private getUrl({ version }: { version: number | 'stable' }) { const baseUrl = 'https://financialmodelingprep.com';