Browse Source

Feature/improve data gathering for currencies (#581)

* Improve data gathering for currencies, add warning if it fails

* Update changelog
pull/582/head
Thomas Kaul 3 years ago
committed by GitHub
parent
commit
0043b44670
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      CHANGELOG.md
  2. 36
      apps/api/src/services/data-gathering.service.ts

5
CHANGELOG.md

@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Added a warning to the log if the data gathering fails
### Fixed ### Fixed
- Filtered potential `null` currencies - Filtered potential `null` currencies
- Improved the 7d data gathering optimization for currencies
## 1.94.0 - 25.12.2021 ## 1.94.0 - 25.12.2021

36
apps/api/src/services/data-gathering.service.ts

@ -334,16 +334,25 @@ export class DataGatheringService {
?.marketPrice; ?.marketPrice;
} }
try { if (lastMarketPrice) {
await this.prismaService.marketData.create({ try {
data: { await this.prismaService.marketData.create({
dataSource, data: {
symbol, dataSource,
date: currentDate, symbol,
marketPrice: lastMarketPrice date: currentDate,
} marketPrice: lastMarketPrice
}); }
} catch {} });
} catch {}
} else {
Logger.warn(
`Failed to gather data for symbol ${symbol} at ${format(
currentDate,
DATE_FORMAT
)}.`
);
}
// Count month one up for iteration // Count month one up for iteration
currentDate = new Date( currentDate = new Date(
@ -492,8 +501,8 @@ export class DataGatheringService {
} }
}) })
) )
.filter((symbolProfile) => { .filter(({ symbol }) => {
return symbolsToGather.includes(symbolProfile.symbol); return symbolsToGather.includes(symbol);
}) })
.map((symbolProfile) => { .map((symbolProfile) => {
return { return {
@ -504,6 +513,9 @@ export class DataGatheringService {
const currencyPairsToGather = this.exchangeRateDataService const currencyPairsToGather = this.exchangeRateDataService
.getCurrencyPairs() .getCurrencyPairs()
.filter(({ symbol }) => {
return symbolsToGather.includes(symbol);
})
.map(({ dataSource, symbol }) => { .map(({ dataSource, symbol }) => {
return { return {
dataSource, dataSource,

Loading…
Cancel
Save