Browse Source

Use asset profile resolutions in getQuotes()

pull/5750/head
Thomas Kaul 3 months ago
parent
commit
a81b76b954
  1. 30
      apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

30
apps/api/src/services/data-provider/financial-modeling-prep/financial-modeling-prep.service.ts

@ -373,26 +373,42 @@ export class FinancialModelingPrepService implements DataProviderInterface {
{ {
signal: AbortSignal.timeout(requestTimeout) signal: AbortSignal.timeout(requestTimeout)
} }
).then((res) => res.json()) ).then(
(res) => res.json() as unknown as { price: number; symbol: string }[]
)
]); ]);
if (assetProfileResolutions.length === symbols.length) {
for (const { currency, symbolTarget } of assetProfileResolutions) { for (const { currency, symbolTarget } of assetProfileResolutions) {
currencyBySymbolMap[symbolTarget] = { currency }; currencyBySymbolMap[symbolTarget] = { currency };
} }
} else {
const resolvedSymbols = assetProfileResolutions.map(
({ symbolTarget }) => {
return symbolTarget;
}
);
const symbolsToFetch = quotes
.map(({ symbol }) => {
return symbol;
})
.filter((symbol) => {
return !resolvedSymbols.includes(symbol);
});
if (symbolsToFetch.length > 0) {
await Promise.all( await Promise.all(
quotes.map(({ symbol }) => { symbolsToFetch.map(async (symbol) => {
return this.getAssetProfile({ const assetProfile = await this.getAssetProfile({
requestTimeout, requestTimeout,
symbol symbol
}).then((assetProfile) => { });
if (assetProfile?.currency) { if (assetProfile?.currency) {
currencyBySymbolMap[symbol] = { currencyBySymbolMap[symbol] = {
currency: assetProfile.currency currency: assetProfile.currency
}; };
} }
});
}) })
); );
} }

Loading…
Cancel
Save