Bugfix/use base currency in exchange rate service instead of usd (#1255)
* Change from USD to base currency * Update changelog
This commit is contained in:
parent
91678028b5
commit
7d27cb3398
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed the calculations of the exchange rate service by changing `USD` to the base currency
|
||||||
- Fixed the missing assets during the local development
|
- Fixed the missing assets during the local development
|
||||||
|
|
||||||
## 1.192.0 - 11.09.2022
|
## 1.192.0 - 11.09.2022
|
||||||
|
@ -183,10 +183,10 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
for (const historicalItem of historicalResult) {
|
for (const historicalItem of historicalResult) {
|
||||||
let marketPrice = historicalItem.close;
|
let marketPrice = historicalItem.close;
|
||||||
|
|
||||||
if (symbol === 'USDGBp') {
|
if (symbol === `${this.baseCurrency}GBp`) {
|
||||||
// Convert GPB to GBp (pence)
|
// Convert GPB to GBp (pence)
|
||||||
marketPrice = new Big(marketPrice).mul(100).toNumber();
|
marketPrice = new Big(marketPrice).mul(100).toNumber();
|
||||||
} else if (symbol === 'USDILA') {
|
} else if (symbol === `${this.baseCurrency}ILA`) {
|
||||||
// Convert ILS to ILA
|
// Convert ILS to ILA
|
||||||
marketPrice = new Big(marketPrice).mul(100).toNumber();
|
marketPrice = new Big(marketPrice).mul(100).toNumber();
|
||||||
}
|
}
|
||||||
@ -246,9 +246,12 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
marketPrice: quote.regularMarketPrice || 0
|
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)
|
// Convert GPB to GBp (pence)
|
||||||
response['USDGBp'] = {
|
response[`${this.baseCurrency}GBp`] = {
|
||||||
...response[symbol],
|
...response[symbol],
|
||||||
currency: 'GBp',
|
currency: 'GBp',
|
||||||
marketPrice: new Big(response[symbol].marketPrice)
|
marketPrice: new Big(response[symbol].marketPrice)
|
||||||
@ -256,11 +259,11 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
.toNumber()
|
.toNumber()
|
||||||
};
|
};
|
||||||
} else if (
|
} else if (
|
||||||
symbol === 'USDILS' &&
|
symbol === `${this.baseCurrency}ILS` &&
|
||||||
yahooFinanceSymbols.includes('USDILA=X')
|
yahooFinanceSymbols.includes(`${this.baseCurrency}ILA=X`)
|
||||||
) {
|
) {
|
||||||
// Convert ILS to ILA
|
// Convert ILS to ILA
|
||||||
response['USDILA'] = {
|
response[`${this.baseCurrency}ILA`] = {
|
||||||
...response[symbol],
|
...response[symbol],
|
||||||
currency: 'ILA',
|
currency: 'ILA',
|
||||||
marketPrice: new Big(response[symbol].marketPrice)
|
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)
|
// Convert USD to USX (cent)
|
||||||
response['USDUSX'] = {
|
response[`${this.baseCurrency}USX`] = {
|
||||||
currency: 'USX',
|
currency: 'USX',
|
||||||
dataSource: this.getName(),
|
dataSource: this.getName(),
|
||||||
marketPrice: new Big(1).mul(100).toNumber(),
|
marketPrice: new Big(1).mul(100).toNumber(),
|
||||||
|
@ -99,10 +99,12 @@ export class ExchangeRateDataService {
|
|||||||
this.exchangeRates[symbol] = resultExtended[symbol]?.[date]?.marketPrice;
|
this.exchangeRates[symbol] = resultExtended[symbol]?.[date]?.marketPrice;
|
||||||
|
|
||||||
if (!this.exchangeRates[symbol]) {
|
if (!this.exchangeRates[symbol]) {
|
||||||
// Not found, calculate indirectly via USD
|
// Not found, calculate indirectly via base currency
|
||||||
this.exchangeRates[symbol] =
|
this.exchangeRates[symbol] =
|
||||||
resultExtended[`${currency1}${'USD'}`]?.[date]?.marketPrice *
|
resultExtended[`${currency1}${this.baseCurrency}`]?.[date]
|
||||||
resultExtended[`${'USD'}${currency2}`]?.[date]?.marketPrice;
|
?.marketPrice *
|
||||||
|
resultExtended[`${this.baseCurrency}${currency2}`]?.[date]
|
||||||
|
?.marketPrice;
|
||||||
|
|
||||||
// Calculate the opposite direction
|
// Calculate the opposite direction
|
||||||
this.exchangeRates[`${currency2}${currency1}`] =
|
this.exchangeRates[`${currency2}${currency1}`] =
|
||||||
@ -126,9 +128,11 @@ export class ExchangeRateDataService {
|
|||||||
if (this.exchangeRates[`${aFromCurrency}${aToCurrency}`]) {
|
if (this.exchangeRates[`${aFromCurrency}${aToCurrency}`]) {
|
||||||
factor = this.exchangeRates[`${aFromCurrency}${aToCurrency}`];
|
factor = this.exchangeRates[`${aFromCurrency}${aToCurrency}`];
|
||||||
} else {
|
} else {
|
||||||
// Calculate indirectly via USD
|
// Calculate indirectly via base currency
|
||||||
const factor1 = this.exchangeRates[`${aFromCurrency}${'USD'}`];
|
const factor1 =
|
||||||
const factor2 = this.exchangeRates[`${'USD'}${aToCurrency}`];
|
this.exchangeRates[`${aFromCurrency}${this.baseCurrency}`];
|
||||||
|
const factor2 =
|
||||||
|
this.exchangeRates[`${this.baseCurrency}${aToCurrency}`];
|
||||||
|
|
||||||
factor = factor1 * factor2;
|
factor = factor1 * factor2;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user