From 29e9336baf5fcec963e90e3fe981b3a8e2ede713 Mon Sep 17 00:00:00 2001 From: Chris Ian Fiel Date: Fri, 15 May 2026 20:21:25 +0800 Subject: [PATCH] Bugfix/account cash balance calculation for SELL activities with fees (#6862) * Fix account cash balance calculation for SELL activities with fees * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/activities/activities.service.ts | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) 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 });