From c15c3d0fbd91ed40d0a21daaa3ccbc92464e7edf Mon Sep 17 00:00:00 2001 From: KenTandrian Date: Sun, 12 Oct 2025 15:51:09 +0700 Subject: [PATCH] fix(api): calculate from startDate to endDate --- apps/api/src/app/portfolio/portfolio.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index cc6d57954..b8f34b60a 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -682,7 +682,9 @@ export class PortfolioService { if (filters?.length === 0 || isFilteredByAccount || isFilteredByCash) { const cashPositions = this.getCashPositions({ cashDetails, + endDate, exchangeRatesByCurrency, + startDate, userCurrency, value: filteredValueInBaseCurrency }); @@ -708,7 +710,9 @@ export class PortfolioService { ) { const emergencyFundCashPositions = this.getCashPositions({ cashDetails, + endDate, exchangeRatesByCurrency, + startDate, userCurrency, value: filteredValueInBaseCurrency }); @@ -1644,12 +1648,16 @@ export class PortfolioService { private getCashPositions({ cashDetails, + endDate, exchangeRatesByCurrency, + startDate, userCurrency, value }: { cashDetails: CashDetails; + endDate: Date; exchangeRatesByCurrency: ExchangeRatesByCurrency; + startDate: Date; userCurrency: string; value: Big; }) { @@ -1676,10 +1684,10 @@ export class PortfolioService { // Calculate the performance of the cash position including currency effects const netPerformanceWithCurrencyEffect = new Big(account.balance) - .mul(exchangeRates?.[format(new Date(), DATE_FORMAT)] ?? 1) + .mul(exchangeRates?.[format(endDate, DATE_FORMAT)] ?? 1) .minus( new Big(account.balance).mul( - exchangeRates?.[format(account.createdAt, DATE_FORMAT)] ?? 1 + exchangeRates?.[format(startDate, DATE_FORMAT)] ?? 1 ) ) .toNumber();