From 1b2de6a2af69dbb3bff330819d95f83eb7379ea8 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 26 Jul 2025 13:37:30 +0200 Subject: [PATCH] Migrate to stable API version --- .../financial-modeling-prep.service.ts | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 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 e61e69054..2dcb689a7 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 @@ -132,41 +132,34 @@ export class FinancialModelingPrepService implements DataProviderInterface { } ); - const [etfInformation] = await fetch( - `${this.getUrl({ version: 4 })}/etf-info?symbol=${symbol}&apikey=${this.apiKey}`, + const etfHoldings = await fetch( + `${this.getUrl({ version: 'stable' })}/etf/holdings?symbol=${symbol}&apikey=${this.apiKey}`, { signal: AbortSignal.timeout(requestTimeout) } ).then((res) => res.json()); - if (etfInformation.website) { - response.url = etfInformation.website; - } + const sortedTopHoldings = etfHoldings + .sort((a, b) => { + return b.weightPercentage - a.weightPercentage; + }) + .slice(0, 10); + + response.holdings = sortedTopHoldings.map( + ({ name, weightPercentage }) => { + return { name, weight: weightPercentage / 100 }; + } + ); - const [portfolioDate] = await fetch( - `${this.getUrl({ version: 4 })}/etf-holdings/portfolio-date?symbol=${symbol}&apikey=${this.apiKey}`, + const [etfInformation] = await fetch( + `${this.getUrl({ version: 'stable' })}/etf/info?symbol=${symbol}&apikey=${this.apiKey}`, { signal: AbortSignal.timeout(requestTimeout) } ).then((res) => res.json()); - if (portfolioDate) { - const etfHoldings = await fetch( - `${this.getUrl({ version: 4 })}/etf-holdings?date=${portfolioDate.date}&symbol=${symbol}&apikey=${this.apiKey}`, - { - signal: AbortSignal.timeout(requestTimeout) - } - ).then((res) => res.json()); - - const sortedTopHoldings = etfHoldings - .sort((a, b) => { - return b.pctVal - a.pctVal; - }) - .slice(0, 10); - - response.holdings = sortedTopHoldings.map(({ name, pctVal }) => { - return { name, weight: pctVal / 100 }; - }); + if (etfInformation.website) { + response.url = etfInformation.website; } const etfSectorWeightings = await fetch(