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