diff --git a/CHANGELOG.md b/CHANGELOG.md index f23e1af95..363c224c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed the cash balance computation for `SELL` activities to subtract the fee instead of adding it (the previous logic inflated the account's cash balance by twice the fee) + ## 3.3.0 - 2026-05-14 ### Added diff --git a/apps/api/src/app/activities/activities.service.ts b/apps/api/src/app/activities/activities.service.ts index 58b9c11a4..95e5aa05b 100644 --- a/apps/api/src/app/activities/activities.service.ts +++ b/apps/api/src/app/activities/activities.service.ts @@ -214,15 +214,15 @@ 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).toNumber(); if (['BUY', 'FEE'].includes(data.type)) { amount = new Big(amount).mul(-1).toNumber(); } + // Fees always reduce cash regardless of the activity direction + amount = new Big(amount).minus(data.fee).toNumber(); + await this.accountService.updateAccountBalance({ accountId, amount,