From f9d5a5fd55b407f918a2d5ea147c01427679a029 Mon Sep 17 00:00:00 2001 From: Joarley Santos Date: Sun, 19 Oct 2025 06:24:20 +0000 Subject: [PATCH] Feature: Calculate Bitcoin value based on activities in PortfolioService --- .../src/app/portfolio/portfolio.service.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index b74b779f6..e7adb4b86 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -222,6 +222,17 @@ export class PortfolioService { const valueInBaseCurrency = details.accounts[account.id]?.valueInBaseCurrency ?? 0; + const value = account.currency === 'BTC' || account.currency === 'bitcoin' ? + account.activities.reduce((acc, activity) => { + return activity.type === ActivityType.SELL ? acc.minus(activity.quantity) : acc.plus(activity.quantity); + }, new Big(0)).toNumber() + : + this.exchangeRateDataService.toCurrency( + valueInBaseCurrency, + userCurrency, + account.currency + ); + const result = { ...account, dividendInBaseCurrency, @@ -234,11 +245,12 @@ export class PortfolioService { account.currency, userCurrency ), - value: this.exchangeRateDataService.toCurrency( - valueInBaseCurrency, - userCurrency, - account.currency - ) + // value: this.exchangeRateDataService.toCurrency( + // valueInBaseCurrency, + // userCurrency, + // account.currency + // ) + value }; delete result.activities;