Browse Source

Migrate to stable API version

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

41
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(

Loading…
Cancel
Save