Browse Source

addressed pr comments

pull/3723/head
Shaunak Das 12 months ago
parent
commit
dad0107b63
  1. 36
      apps/api/src/services/data-provider/manual/manual.service.ts

36
apps/api/src/services/data-provider/manual/manual.service.ts

@ -166,35 +166,39 @@ export class ManualService implements DataProviderInterface {
} }
}); });
const profilesWithScraping = symbolProfiles.filter( const symbolProfilesWithScraperConfiguration = symbolProfiles.filter(
({ scraperConfiguration }) => { ({ scraperConfiguration }) => {
return !!scraperConfiguration?.url; return !!scraperConfiguration?.url;
} }
); );
const scrapingPromises = profilesWithScraping.map( const scraperResultPromises = symbolProfilesWithScraperConfiguration.map(
({ symbol, scraperConfiguration }) => { ({ scraperConfiguration, symbol }) => {
return this.scrape(scraperConfiguration) return this.scrape(scraperConfiguration)
.then((marketPrice) => ({ .then((marketPrice) => {
symbol, return { marketPrice, symbol };
marketPrice })
}))
.catch((error) => { .catch((error) => {
Logger.error(`Error scraping ${symbol}:`, error); Logger.error(
return { symbol, marketPrice: 0 }; `Could not get quote for ${symbol} (${this.getName()}): [${error.name}] ${error.message}`,
'ManualService'
);
return { symbol, marketPrice: undefined };
}); });
} }
); );
// Wait for all scraping requests to complete concurrently // Wait for all scraping requests to complete concurrently
const scrapedResults = await Promise.all(scrapingPromises); const scraperResults = await Promise.all(scraperResultPromises);
for (const { currency, symbol, scraperConfiguration } of symbolProfiles) { for (const { currency, symbol } of symbolProfiles) {
const scrapedResult = scrapedResults.find( let { marketPrice } =
(result) => result.symbol === symbol scraperResults.find((result) => {
); return result.symbol === symbol;
let marketPrice = }) ?? {};
scrapedResult?.marketPrice ??
marketPrice =
marketPrice ??
marketData.find((marketDataItem) => { marketData.find((marketDataItem) => {
return marketDataItem.symbol === symbol; return marketDataItem.symbol === symbol;
})?.marketPrice ?? })?.marketPrice ??

Loading…
Cancel
Save