diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 1c022ba17..18346c4b3 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -346,10 +346,19 @@ export class PortfolioController { this.userService.isRestrictedView(this.request.user) ) { performanceInformation.chart = performanceInformation.chart.map( - ({ date, netPerformanceInPercentage, totalInvestment, value }) => { + ({ + date, + netPerformanceInPercentage, + totalInvestment, + value, + totalAccountBalance, + netWorth + }) => { return { date, netPerformanceInPercentage, + netWorth, + totalAccountBalance, totalInvestment: new Big(totalInvestment) .div(performanceInformation.performance.totalInvestment) .toNumber(), diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index b2538fb6a..d563db42f 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1,3 +1,4 @@ +import { AccountBalanceService } from '@ghostfolio/api/services/account-balance/account-balance.service'; import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; @@ -91,6 +92,7 @@ const europeMarkets = require('../../assets/countries/europe-markets.json'); @Injectable() export class PortfolioService { public constructor( + private readonly accountBalanceService: AccountBalanceService, private readonly accountService: AccountService, private readonly currentRateService: CurrentRateService, private readonly dataProviderService: DataProviderService, @@ -1195,6 +1197,16 @@ export class PortfolioService { ).div(100); } + const balancesValue = await this.accountBalanceService.getAccountBalances({ + userId: userId + }); + + let totalBalance = 0; + + balancesValue.balances.map((item) => { + totalBalance += item.value; + }); + return { errors, hasErrors, @@ -1211,7 +1223,9 @@ export class PortfolioService { netPerformanceInPercentage, value, netPerformance: netPerformanceOfItem, - totalInvestment: totalInvestmentOfItem + totalInvestment: totalInvestmentOfItem, + totalAccountBalance: totalBalance, + netWorth: value + totalBalance }; } ), diff --git a/apps/api/src/services/account-balance/account-balance.service.ts b/apps/api/src/services/account-balance/account-balance.service.ts index 9995bbc3e..60d39fc83 100644 --- a/apps/api/src/services/account-balance/account-balance.service.ts +++ b/apps/api/src/services/account-balance/account-balance.service.ts @@ -19,7 +19,7 @@ export class AccountBalanceService { accountId, userId }: { - accountId: string; + accountId?: string; userId: string; }): Promise { const balances = await this.prismaService.accountBalance.findMany({ diff --git a/libs/common/src/lib/interfaces/historical-data-item.interface.ts b/libs/common/src/lib/interfaces/historical-data-item.interface.ts index b8306ff86..3408f554d 100644 --- a/libs/common/src/lib/interfaces/historical-data-item.interface.ts +++ b/libs/common/src/lib/interfaces/historical-data-item.interface.ts @@ -5,7 +5,9 @@ export interface HistoricalDataItem { marketPrice?: number; netPerformance?: number; netPerformanceInPercentage?: number; + netWorth?: number; quantity?: number; + totalAccountBalance?: number; totalInvestment?: number; value?: number; valueInPercentage?: number;