|
|
@ -64,7 +64,8 @@ export class ExchangeRateDataService { |
|
|
|
} = {}; |
|
|
|
|
|
|
|
for (let currency of currencies) { |
|
|
|
exchangeRatesByCurrency[currency] = await this.getExchangeRates({ |
|
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`] = |
|
|
|
await this.getExchangeRates({ |
|
|
|
startDate, |
|
|
|
currencyFrom: currency, |
|
|
|
currencyTo: targetCurrency |
|
|
@ -82,17 +83,25 @@ export class ExchangeRateDataService { |
|
|
|
let dateString = format(date, DATE_FORMAT); |
|
|
|
|
|
|
|
// Check if the exchange rate for the current date is missing
|
|
|
|
if (isNaN(exchangeRatesByCurrency[currency][dateString])) { |
|
|
|
if ( |
|
|
|
isNaN( |
|
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`][dateString] |
|
|
|
) |
|
|
|
) { |
|
|
|
// If missing, fill with the previous exchange rate
|
|
|
|
exchangeRatesByCurrency[currency][dateString] = previousExchangeRate; |
|
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`][dateString] = |
|
|
|
previousExchangeRate; |
|
|
|
|
|
|
|
if (currency === DEFAULT_CURRENCY) { |
|
|
|
Logger.error( |
|
|
|
`No exchange rate has been found for ${DEFAULT_CURRENCY}${currency} at ${dateString}`, |
|
|
|
`No exchange rate has been found for ${currency}${targetCurrency} at ${dateString}`, |
|
|
|
'ExchangeRateDataService' |
|
|
|
); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// If available, update the previous exchange rate
|
|
|
|
previousExchangeRate = exchangeRatesByCurrency[currency][dateString]; |
|
|
|
previousExchangeRate = |
|
|
|
exchangeRatesByCurrency[`${currency}${targetCurrency}`][dateString]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -136,9 +145,6 @@ export class ExchangeRateDataService { |
|
|
|
getYesterday() |
|
|
|
); |
|
|
|
|
|
|
|
if (Object.keys(result).length !== this.currencyPairs.length) { |
|
|
|
// Load currencies directly from data provider as a fallback
|
|
|
|
// if historical data is not fully available
|
|
|
|
const quotes = await this.dataProviderService.getQuotes({ |
|
|
|
items: this.currencyPairs.map(({ dataSource, symbol }) => { |
|
|
|
return { dataSource, symbol }; |
|
|
@ -155,7 +161,6 @@ export class ExchangeRateDataService { |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const resultExtended = result; |
|
|
|
|
|
|
@ -253,6 +258,7 @@ export class ExchangeRateDataService { |
|
|
|
`No exchange rate has been found for ${aFromCurrency}${aToCurrency}`, |
|
|
|
'ExchangeRateDataService' |
|
|
|
); |
|
|
|
|
|
|
|
return aValue; |
|
|
|
} |
|
|
|
|
|
|
|