Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Bugfix/use base currency in exchange rate service instead of usd (#1255)
Thomas Kaul7d27cb339891
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7d77c5578b..96f7dc20f4 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.2022diff --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.tsindex d6a6a84123..2a7e93ed6b 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 ILAmarketPrice = 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.tsindex 7900fc781e..60a7e0e569 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 currencythis.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 directionthis.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;