|
@ -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 ?? |
|
|