lorenzozane 2 days ago
committed by GitHub
parent
commit
ffbadd5e50
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 19
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 1
      libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts

4
apps/api/src/app/portfolio/portfolio.controller.ts

@ -399,13 +399,11 @@ export class PortfolioController {
filterByTags: tags filterByTags: tags
}); });
const holdings = await this.portfolioService.getHoldings({ return this.portfolioService.getHoldings({
filters, filters,
userId, userId,
dateRange: range dateRange: range
}); });
return { holdings };
} }
@Get('investments') @Get('investments')

19
apps/api/src/app/portfolio/portfolio.service.ts

@ -57,6 +57,7 @@ import {
InvestmentItem, InvestmentItem,
PortfolioDetails, PortfolioDetails,
PortfolioHoldingResponse, PortfolioHoldingResponse,
PortfolioHoldingsResponse,
PortfolioInvestmentsResponse, PortfolioInvestmentsResponse,
PortfolioPerformanceResponse, PortfolioPerformanceResponse,
PortfolioPosition, PortfolioPosition,
@ -505,7 +506,14 @@ export class PortfolioService {
}); });
} }
return holdings; return {
holdings,
totalValueInBaseCurrency: getSum(
holdings.map(({ valueInBaseCurrency }) => {
return new Big(valueInBaseCurrency ?? 0);
})
).toNumber()
};
} }
public async getInvestments({ public async getInvestments({
@ -1185,7 +1193,7 @@ export class PortfolioService {
currency: userCurrency currency: userCurrency
}); });
const { errors, hasErrors, historicalData } = const { currentValueInBaseCurrency, errors, hasErrors, historicalData } =
await portfolioCalculator.getSnapshot(); await portfolioCalculator.getSnapshot();
const { endDate, startDate } = getIntervalFromDateRange({ dateRange }); const { endDate, startDate } = getIntervalFromDateRange({ dateRange });
@ -1202,8 +1210,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect, netPerformanceWithCurrencyEffect,
netWorth, netWorth,
totalInvestment, totalInvestment,
totalInvestmentValueWithCurrencyEffect, totalInvestmentValueWithCurrencyEffect
valueWithCurrencyEffect
} = chart?.at(-1) ?? { } = chart?.at(-1) ?? {
netPerformance: 0, netPerformance: 0,
netPerformanceInPercentage: 0, netPerformanceInPercentage: 0,
@ -1211,7 +1218,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect: 0, netPerformanceWithCurrencyEffect: 0,
netWorth: 0, netWorth: 0,
totalInvestment: 0, totalInvestment: 0,
valueWithCurrencyEffect: 0 totalInvestmentValueWithCurrencyEffect: 0
}; };
return { return {
@ -1225,7 +1232,7 @@ export class PortfolioService {
totalInvestment, totalInvestment,
totalInvestmentValueWithCurrencyEffect, totalInvestmentValueWithCurrencyEffect,
currentNetWorth: netWorth, currentNetWorth: netWorth,
currentValueInBaseCurrency: valueWithCurrencyEffect, currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(),
netPerformancePercentage: netPerformanceInPercentage, netPerformancePercentage: netPerformanceInPercentage,
netPerformancePercentageWithCurrencyEffect: netPerformancePercentageWithCurrencyEffect:
netPerformanceInPercentageWithCurrencyEffect netPerformanceInPercentageWithCurrencyEffect

1
libs/common/src/lib/interfaces/responses/portfolio-holdings-response.interface.ts

@ -2,4 +2,5 @@ import { PortfolioPosition } from '@ghostfolio/common/interfaces';
export interface PortfolioHoldingsResponse { export interface PortfolioHoldingsResponse {
holdings: PortfolioPosition[]; holdings: PortfolioPosition[];
totalValueInBaseCurrency: number;
} }

Loading…
Cancel
Save