|
|
@ -186,28 +186,42 @@ export class ExchangeRateDataService {
|
|
|
|
factor = marketData?.marketPrice;
|
|
|
|
factor = marketData?.marketPrice;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Calculate indirectly via base currency
|
|
|
|
// Calculate indirectly via base currency
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let marketPriceBaseCurrencyFromCurrency: number;
|
|
|
|
|
|
|
|
let marketPriceBaseCurrencyToCurrency: number;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const [
|
|
|
|
if (this.baseCurrency === aFromCurrency) {
|
|
|
|
{ marketPrice: marketPriceBaseCurrencyFromCurrency },
|
|
|
|
marketPriceBaseCurrencyFromCurrency = 1;
|
|
|
|
{ marketPrice: marketPriceBaseCurrencyToCurrency }
|
|
|
|
} else {
|
|
|
|
] = await Promise.all([
|
|
|
|
marketPriceBaseCurrencyFromCurrency = (
|
|
|
|
this.marketDataService.get({
|
|
|
|
await this.marketDataService.get({
|
|
|
|
dataSource,
|
|
|
|
dataSource,
|
|
|
|
date: aDate,
|
|
|
|
date: aDate,
|
|
|
|
symbol: `${this.baseCurrency}${aFromCurrency}`
|
|
|
|
symbol: `${this.baseCurrency}${aFromCurrency}`
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
this.marketDataService.get({
|
|
|
|
)?.marketPrice;
|
|
|
|
dataSource,
|
|
|
|
}
|
|
|
|
date: aDate,
|
|
|
|
|
|
|
|
symbol: `${this.baseCurrency}${aToCurrency}`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the opposite direction
|
|
|
|
|
|
|
|
factor =
|
|
|
|
|
|
|
|
(1 / marketPriceBaseCurrencyFromCurrency) *
|
|
|
|
|
|
|
|
marketPriceBaseCurrencyToCurrency;
|
|
|
|
|
|
|
|
} catch {}
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (this.baseCurrency === aToCurrency) {
|
|
|
|
|
|
|
|
marketPriceBaseCurrencyToCurrency = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
marketPriceBaseCurrencyToCurrency = (
|
|
|
|
|
|
|
|
await this.marketDataService.get({
|
|
|
|
|
|
|
|
dataSource,
|
|
|
|
|
|
|
|
date: aDate,
|
|
|
|
|
|
|
|
symbol: `${this.baseCurrency}${aToCurrency}`
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
)?.marketPrice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the opposite direction
|
|
|
|
|
|
|
|
factor =
|
|
|
|
|
|
|
|
(1 / marketPriceBaseCurrencyFromCurrency) *
|
|
|
|
|
|
|
|
marketPriceBaseCurrencyToCurrency;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|