Feature/add fallback for loading currencies (#315)
* Add fallback for loading currencies * Update changelog
This commit is contained in:
parent
d8782b0d4c
commit
fe975945d1
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user