Browse Source

Improve exchange rate robustness

pull/7119/head
Thomas Kaul 3 weeks ago
parent
commit
1d5990df07
  1. 8
      apps/api/src/app/activities/activities.service.ts
  2. 15
      apps/api/src/app/import/import.service.ts
  3. 8
      apps/api/src/app/portfolio/portfolio.service.ts

8
apps/api/src/app/activities/activities.service.ts

@ -746,10 +746,10 @@ export class ActivitiesService {
const value = new Big(order.quantity).mul(order.unitPrice).toNumber(); const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
const [ const [
feeInAssetProfileCurrency, feeInAssetProfileCurrency = 0,
feeInBaseCurrency, feeInBaseCurrency = 0,
unitPriceInAssetProfileCurrency, unitPriceInAssetProfileCurrency = 0,
valueInBaseCurrency valueInBaseCurrency = 0
] = await Promise.all([ ] = await Promise.all([
this.exchangeRateDataService.toCurrencyAtDate( this.exchangeRateDataService.toCurrencyAtDate(
order.fee, order.fee,

15
apps/api/src/app/import/import.service.ts

@ -592,18 +592,19 @@ export class ImportService {
const value = new Big(quantity).mul(unitPrice).toNumber(); const value = new Big(quantity).mul(unitPrice).toNumber();
const valueInBaseCurrency = this.exchangeRateDataService.toCurrencyAtDate( const valueInBaseCurrency =
value, (await this.exchangeRateDataService.toCurrencyAtDate(
currency ?? assetProfile.currency, value,
userCurrency, currency ?? assetProfile.currency,
date userCurrency,
); date
)) ?? 0;
activities.push({ activities.push({
...order, ...order,
error, error,
value, value,
valueInBaseCurrency: await valueInBaseCurrency, valueInBaseCurrency,
// @ts-ignore // @ts-ignore
SymbolProfile: assetProfile SymbolProfile: assetProfile
}); });

8
apps/api/src/app/portfolio/portfolio.service.ts

@ -205,21 +205,21 @@ export class PortfolioService {
switch (type) { switch (type) {
case ActivityType.DIVIDEND: case ActivityType.DIVIDEND:
dividendInBaseCurrency += dividendInBaseCurrency +=
await this.exchangeRateDataService.toCurrencyAtDate( (await this.exchangeRateDataService.toCurrencyAtDate(
new Big(quantity).mul(unitPrice).toNumber(), new Big(quantity).mul(unitPrice).toNumber(),
currency ?? SymbolProfile.currency, currency ?? SymbolProfile.currency,
userCurrency, userCurrency,
date date
); )) ?? 0;
break; break;
case ActivityType.INTEREST: case ActivityType.INTEREST:
interestInBaseCurrency += interestInBaseCurrency +=
await this.exchangeRateDataService.toCurrencyAtDate( (await this.exchangeRateDataService.toCurrencyAtDate(
unitPrice, unitPrice,
currency ?? SymbolProfile.currency, currency ?? SymbolProfile.currency,
userCurrency, userCurrency,
date date
); )) ?? 0;
break; break;
} }

Loading…
Cancel
Save