diff --git a/CHANGELOG.md b/CHANGELOG.md index be6630ae1..d7676efee 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/apps/api/src/app/activities/activities.service.ts b/apps/api/src/app/activities/activities.service.ts index 58b9c11a4..821185e11 100644 --- a/apps/api/src/app/activities/activities.service.ts +++ b/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 });