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 90de5ddc38..377d2b4fb4 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -59,6 +59,7 @@ import { InvestmentItem, PortfolioDetails, PortfolioHoldingResponse, + PortfolioHoldingsResponse, PortfolioInvestmentsResponse, PortfolioPerformanceResponse, PortfolioPosition, @@ -508,7 +509,14 @@ export class PortfolioService { }); } - return holdings; + return { + holdings, + totalValueInBaseCurrency: getSum( + holdings.map(({ valueInBaseCurrency }) => { + return new Big(valueInBaseCurrency ?? 0); + }) + ).toNumber() + }; } public async getInvestments({ @@ -1241,7 +1249,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 }); @@ -1258,8 +1266,7 @@ export class PortfolioService { netPerformanceWithCurrencyEffect, netWorth, totalInvestment, - totalInvestmentValueWithCurrencyEffect, - valueWithCurrencyEffect + totalInvestmentValueWithCurrencyEffect } = chart?.at(-1) ?? { netPerformance: 0, netPerformanceInPercentage: 0, @@ -1267,7 +1274,7 @@ export class PortfolioService { netPerformanceWithCurrencyEffect: 0, netWorth: 0, totalInvestment: 0, - valueWithCurrencyEffect: 0 + totalInvestmentValueWithCurrencyEffect: 0 }; return { @@ -1281,7 +1288,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; }