Browse Source

Bugfix/account cash balance calculation for SELL activities with fees (#6862)

* Fix account cash balance calculation for SELL activities with fees

* Update changelog
pull/1685/merge
Chris Ian Fiel 1 week ago
committed by GitHub
parent
commit
29e9336baf
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 11
      apps/api/src/app/activities/activities.service.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Resolved an issue with the cash balance calculation of an account for `SELL` activities to ensure fees are correctly subtracted
- Resolved an exception in the portfolio details endpoint when an asset profile is unmatched
## 3.3.0 - 2026-05-14

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

@ -214,19 +214,18 @@ export class ActivitiesService {
});
if (updateAccountBalance === true) {
let amount = new Big(data.unitPrice)
.mul(data.quantity)
.plus(data.fee)
.toNumber();
let amount = new Big(data.unitPrice).mul(data.quantity);
if (['BUY', 'FEE'].includes(data.type)) {
amount = new Big(amount).mul(-1).toNumber();
amount = amount.mul(-1);
}
amount = amount.minus(data.fee);
await this.accountService.updateAccountBalance({
accountId,
amount,
userId,
amount: amount.toNumber(),
currency: data.SymbolProfile.connectOrCreate.create.currency,
date: data.date as Date
});

Loading…
Cancel
Save