Browse Source

Bugfix/restore incorrect fee currency conversion (#4645)

* Restore incorrect fee currency conversion

* Update changelog
pull/4659/head
Marcin Szymański 2 months ago
committed by GitHub
parent
commit
28d2fd3877
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 4
      apps/api/src/app/import/import.service.ts
  3. 2
      apps/api/src/app/order/interfaces/activities.interface.ts
  4. 35
      apps/api/src/app/order/order.service.ts
  5. 1
      apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts

4
CHANGELOG.md

@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed `Account` to `accounts` in the `Platform` database schema - Renamed `Account` to `accounts` in the `Platform` database schema
- Upgraded `prisma` from version `6.6.0` to `6.7.0` - Upgraded `prisma` from version `6.6.0` to `6.7.0`
### Fixed
- Fixed an issue with the fee calculations related to activities in a custom currency
## 2.159.0 - 2025-05-02 ## 2.159.0 - 2025-05-02
### Added ### Added

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

@ -118,6 +118,7 @@ export class ImportService {
createdAt: undefined, createdAt: undefined,
fee: 0, fee: 0,
feeInAssetProfileCurrency: 0, feeInAssetProfileCurrency: 0,
feeInBaseCurrency: 0,
id: assetProfile.id, id: assetProfile.id,
isDraft: false, isDraft: false,
SymbolProfile: assetProfile, SymbolProfile: assetProfile,
@ -126,7 +127,8 @@ export class ImportService {
unitPrice: marketPrice, unitPrice: marketPrice,
unitPriceInAssetProfileCurrency: marketPrice, unitPriceInAssetProfileCurrency: marketPrice,
updatedAt: undefined, updatedAt: undefined,
userId: Account?.userId userId: Account?.userId,
valueInBaseCurrency: value
}; };
}) })
); );

2
apps/api/src/app/order/interfaces/activities.interface.ts

@ -12,11 +12,13 @@ export interface Activity extends Order {
Account?: AccountWithPlatform; Account?: AccountWithPlatform;
error?: ActivityError; error?: ActivityError;
feeInAssetProfileCurrency: number; feeInAssetProfileCurrency: number;
feeInBaseCurrency: number;
SymbolProfile?: EnhancedSymbolProfile; SymbolProfile?: EnhancedSymbolProfile;
tags?: Tag[]; tags?: Tag[];
unitPriceInAssetProfileCurrency: number; unitPriceInAssetProfileCurrency: number;
updateAccountBalance?: boolean; updateAccountBalance?: boolean;
value: number; value: number;
valueInBaseCurrency: number;
} }
export interface ActivityError { export interface ActivityError {

35
apps/api/src/app/order/order.service.ts

@ -531,31 +531,46 @@ export class OrderService {
const value = new Big(order.quantity).mul(order.unitPrice).toNumber(); const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
return { const [
...order, feeInAssetProfileCurrency,
value, feeInBaseCurrency,
feeInAssetProfileCurrency: unitPriceInAssetProfileCurrency,
await this.exchangeRateDataService.toCurrencyAtDate( valueInBaseCurrency
] = await Promise.all([
this.exchangeRateDataService.toCurrencyAtDate(
order.fee, order.fee,
order.currency ?? order.SymbolProfile.currency, order.currency ?? order.SymbolProfile.currency,
order.SymbolProfile.currency, order.SymbolProfile.currency,
order.date order.date
), ),
SymbolProfile: assetProfile, this.exchangeRateDataService.toCurrencyAtDate(
unitPriceInAssetProfileCurrency: order.fee,
await this.exchangeRateDataService.toCurrencyAtDate( order.currency ?? order.SymbolProfile.currency,
userCurrency,
order.date
),
this.exchangeRateDataService.toCurrencyAtDate(
order.unitPrice, order.unitPrice,
order.currency ?? order.SymbolProfile.currency, order.currency ?? order.SymbolProfile.currency,
order.SymbolProfile.currency, order.SymbolProfile.currency,
order.date order.date
), ),
valueInBaseCurrency: this.exchangeRateDataService.toCurrencyAtDate(
await this.exchangeRateDataService.toCurrencyAtDate(
value, value,
order.currency ?? order.SymbolProfile.currency, order.currency ?? order.SymbolProfile.currency,
userCurrency, userCurrency,
order.date order.date
) )
]);
return {
...order,
feeInAssetProfileCurrency,
feeInBaseCurrency,
unitPriceInAssetProfileCurrency,
value,
valueInBaseCurrency,
SymbolProfile: assetProfile
}; };
}) })
); );

1
apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts

@ -8,6 +8,7 @@ export const activityDummyData = {
currency: undefined, currency: undefined,
fee: undefined, fee: undefined,
feeInAssetProfileCurrency: undefined, feeInAssetProfileCurrency: undefined,
feeInBaseCurrency: undefined,
id: undefined, id: undefined,
isDraft: false, isDraft: false,
symbolProfileId: undefined, symbolProfileId: undefined,

Loading…
Cancel
Save