From 7baa6ed497a3c5fd4fc897e5fe9dcb37b4c57693 Mon Sep 17 00:00:00 2001 From: lorenzozanee Date: Wed, 16 Sep 2026 02:07:27 +0800 Subject: [PATCH] Fix portfolio current value responses --- .../src/app/portfolio/portfolio.controller.ts | 4 +--- .../src/app/portfolio/portfolio.service.ts | 19 +++++++++++++------ .../portfolio-holdings-response.interface.ts | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index a65186100a..7f0120de4b 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -400,13 +400,11 @@ export class PortfolioController { filterByTags: tags }); - const holdings = await this.portfolioService.getHoldings({ + return this.portfolioService.getHoldings({ filters, userId, dateRange: range }); - - return { holdings }; } @Get('investments') diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index fd941286c2..1ce506acd2 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -57,6 +57,7 @@ import { InvestmentItem, PortfolioDetails, PortfolioHoldingResponse, + PortfolioHoldingsResponse, PortfolioInvestmentsResponse, PortfolioPerformanceResponse, PortfolioPosition, @@ -506,7 +507,14 @@ export class PortfolioService { }); } - return holdings; + return { + holdings, + totalValueInBaseCurrency: getSum( + holdings.map(({ valueInBaseCurrency }) => { + return new Big(valueInBaseCurrency ?? 0); + }) + ).toNumber() + }; } public async getInvestments({ @@ -1225,7 +1233,7 @@ export class PortfolioService { subscriptionType: user.subscription?.type }); - const { errors, hasErrors, historicalData } = + const { currentValueInBaseCurrency, errors, hasErrors, historicalData } = await portfolioCalculator.getSnapshot(); const { endDate, startDate } = getIntervalFromDateRange({ dateRange }); @@ -1242,8 +1250,7 @@ export class PortfolioService { netPerformanceWithCurrencyEffect, netWorth, totalInvestment, - totalInvestmentValueWithCurrencyEffect, - valueWithCurrencyEffect + totalInvestmentValueWithCurrencyEffect } = chart?.at(-1) ?? { netPerformance: 0, netPerformanceInPercentage: 0, @@ -1251,7 +1258,7 @@ export class PortfolioService { netPerformanceWithCurrencyEffect: 0, netWorth: 0, totalInvestment: 0, - valueWithCurrencyEffect: 0 + totalInvestmentValueWithCurrencyEffect: 0 }; return { @@ -1265,7 +1272,7 @@ export class PortfolioService { totalInvestment, totalInvestmentValueWithCurrencyEffect, currentNetWorth: netWorth, - currentValueInBaseCurrency: valueWithCurrencyEffect, + currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(), netPerformancePercentage: netPerformanceInPercentage, netPerformancePercentageWithCurrencyEffect: netPerformanceInPercentageWithCurrencyEffect diff --git a/libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts b/libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts index d2cf38f553..c15f36d934 100644 --- a/libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts +++ b/libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts @@ -2,4 +2,5 @@ import { PortfolioPosition } from '@ghostfolio/common/interfaces'; export interface PortfolioHoldingsResponse { holdings: PortfolioPosition[]; + totalValueInBaseCurrency: number; }