diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d77c5578..96f7dc20f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed the calculations of the exchange rate service by changing `USD` to the base currency - Fixed the missing assets during the local development ## 1.192.0 - 11.09.2022 diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index d6a6a8412..2a7e93ed6 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -183,10 +183,10 @@ export class YahooFinanceService implements DataProviderInterface { for (const historicalItem of historicalResult) { let marketPrice = historicalItem.close; - if (symbol === 'USDGBp') { + if (symbol === `${this.baseCurrency}GBp`) { // Convert GPB to GBp (pence) marketPrice = new Big(marketPrice).mul(100).toNumber(); - } else if (symbol === 'USDILA') { + } else if (symbol === `${this.baseCurrency}ILA`) { // Convert ILS to ILA marketPrice = new Big(marketPrice).mul(100).toNumber(); } @@ -246,9 +246,12 @@ export class YahooFinanceService implements DataProviderInterface { marketPrice: quote.regularMarketPrice || 0 }; - if (symbol === 'USDGBP' && yahooFinanceSymbols.includes('USDGBp=X')) { + if ( + symbol === `${this.baseCurrency}GBP` && + yahooFinanceSymbols.includes(`${this.baseCurrency}GBp=X`) + ) { // Convert GPB to GBp (pence) - response['USDGBp'] = { + response[`${this.baseCurrency}GBp`] = { ...response[symbol], currency: 'GBp', marketPrice: new Big(response[symbol].marketPrice) @@ -256,11 +259,11 @@ export class YahooFinanceService implements DataProviderInterface { .toNumber() }; } else if ( - symbol === 'USDILS' && - yahooFinanceSymbols.includes('USDILA=X') + symbol === `${this.baseCurrency}ILS` && + yahooFinanceSymbols.includes(`${this.baseCurrency}ILA=X`) ) { // Convert ILS to ILA - response['USDILA'] = { + response[`${this.baseCurrency}ILA`] = { ...response[symbol], currency: 'ILA', marketPrice: new Big(response[symbol].marketPrice) @@ -270,9 +273,9 @@ export class YahooFinanceService implements DataProviderInterface { } } - if (yahooFinanceSymbols.includes('USDUSX=X')) { + if (yahooFinanceSymbols.includes(`${this.baseCurrency}USX=X`)) { // Convert USD to USX (cent) - response['USDUSX'] = { + response[`${this.baseCurrency}USX`] = { currency: 'USX', dataSource: this.getName(), marketPrice: new Big(1).mul(100).toNumber(), diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index 7900fc781..60a7e0e56 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -99,10 +99,12 @@ export class ExchangeRateDataService { this.exchangeRates[symbol] = resultExtended[symbol]?.[date]?.marketPrice; if (!this.exchangeRates[symbol]) { - // Not found, calculate indirectly via USD + // Not found, calculate indirectly via base currency this.exchangeRates[symbol] = - resultExtended[`${currency1}${'USD'}`]?.[date]?.marketPrice * - resultExtended[`${'USD'}${currency2}`]?.[date]?.marketPrice; + resultExtended[`${currency1}${this.baseCurrency}`]?.[date] + ?.marketPrice * + resultExtended[`${this.baseCurrency}${currency2}`]?.[date] + ?.marketPrice; // Calculate the opposite direction this.exchangeRates[`${currency2}${currency1}`] = @@ -126,9 +128,11 @@ export class ExchangeRateDataService { if (this.exchangeRates[`${aFromCurrency}${aToCurrency}`]) { factor = this.exchangeRates[`${aFromCurrency}${aToCurrency}`]; } else { - // Calculate indirectly via USD - const factor1 = this.exchangeRates[`${aFromCurrency}${'USD'}`]; - const factor2 = this.exchangeRates[`${'USD'}${aToCurrency}`]; + // Calculate indirectly via base currency + const factor1 = + this.exchangeRates[`${aFromCurrency}${this.baseCurrency}`]; + const factor2 = + this.exchangeRates[`${this.baseCurrency}${aToCurrency}`]; factor = factor1 * factor2;