Browse Source
Feature/add fallback for loading currencies (#315)
* Add fallback for loading currencies
* Update changelog
pull/316/head
Thomas Kaul
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
20 additions and
1 deletions
-
CHANGELOG.md
-
apps/api/src/services/exchange-rate-data.service.ts
|
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
### Added |
|
|
|
|
|
|
|
- Extended the data management of symbol profile data by countries (automated for stocks) |
|
|
|
- Added a fallback for initially loading currencies if historical data is not yet available |
|
|
|
|
|
|
|
## 1.42.0 - 22.08.2021 |
|
|
|
|
|
|
|
|
|
@ -3,7 +3,7 @@ import { DATE_FORMAT, getYesterday } from '@ghostfolio/common/helper'; |
|
|
|
import { Injectable } from '@nestjs/common'; |
|
|
|
import { Currency } from '@prisma/client'; |
|
|
|
import { format } from 'date-fns'; |
|
|
|
import { isNumber } from 'lodash'; |
|
|
|
import { isEmpty, isNumber } from 'lodash'; |
|
|
|
|
|
|
|
import { DataProviderService } from './data-provider/data-provider.service'; |
|
|
|
|
|
|
@ -35,6 +35,24 @@ export class ExchangeRateDataService { |
|
|
|
getYesterday() |
|
|
|
); |
|
|
|
|
|
|
|
if (isEmpty(result)) { |
|
|
|
// Load currencies directly from data provider as a fallback
|
|
|
|
// if historical data is not yet available
|
|
|
|
const historicalData = await this.dataProviderService.get( |
|
|
|
this.currencyPairs.map((currencyPair) => { |
|
|
|
return currencyPair; |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
Object.keys(historicalData).forEach((key) => { |
|
|
|
result[key] = { |
|
|
|
[format(getYesterday(), DATE_FORMAT)]: { |
|
|
|
marketPrice: historicalData[key].marketPrice |
|
|
|
} |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const resultExtended = result; |
|
|
|
|
|
|
|
Object.keys(result).forEach((pair) => { |
|
|
|