Browse Source

Migrate to stable API version

pull/5253/head
Thomas Kaul 4 weeks ago
parent
commit
1b2de6a2af
  1. 37
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

37
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( const etfHoldings = await fetch(
`${this.getUrl({ version: 4 })}/etf-info?symbol=${symbol}&apikey=${this.apiKey}`, `${this.getUrl({ version: 'stable' })}/etf/holdings?symbol=${symbol}&apikey=${this.apiKey}`,
{ {
signal: AbortSignal.timeout(requestTimeout) signal: AbortSignal.timeout(requestTimeout)
} }
).then((res) => res.json()); ).then((res) => res.json());
if (etfInformation.website) { const sortedTopHoldings = etfHoldings
response.url = etfInformation.website; .sort((a, b) => {
} return b.weightPercentage - a.weightPercentage;
})
.slice(0, 10);
const [portfolioDate] = await fetch( response.holdings = sortedTopHoldings.map(
`${this.getUrl({ version: 4 })}/etf-holdings/portfolio-date?symbol=${symbol}&apikey=${this.apiKey}`, ({ name, weightPercentage }) => {
{ return { name, weight: weightPercentage / 100 };
signal: AbortSignal.timeout(requestTimeout)
} }
).then((res) => res.json()); );
if (portfolioDate) { const [etfInformation] = await fetch(
const etfHoldings = await fetch( `${this.getUrl({ version: 'stable' })}/etf/info?symbol=${symbol}&apikey=${this.apiKey}`,
`${this.getUrl({ version: 4 })}/etf-holdings?date=${portfolioDate.date}&symbol=${symbol}&apikey=${this.apiKey}`,
{ {
signal: AbortSignal.timeout(requestTimeout) signal: AbortSignal.timeout(requestTimeout)
} }
).then((res) => res.json()); ).then((res) => res.json());
const sortedTopHoldings = etfHoldings if (etfInformation.website) {
.sort((a, b) => { response.url = etfInformation.website;
return b.pctVal - a.pctVal;
})
.slice(0, 10);
response.holdings = sortedTopHoldings.map(({ name, pctVal }) => {
return { name, weight: pctVal / 100 };
});
} }
const etfSectorWeightings = await fetch( const etfSectorWeightings = await fetch(

Loading…
Cancel
Save