Browse Source

Merge 42d2c78763 into ad9a1d526b

pull/7771/merge
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
});
const holdings = await this.portfolioService.getHoldings({
return this.portfolioService.getHoldings({
filters,
userId,
dateRange: range
});
return { holdings };
}
@Get('investments')

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

@ -57,6 +57,7 @@ import {
InvestmentItem,
PortfolioDetails,
PortfolioHoldingResponse,
PortfolioHoldingsResponse,
PortfolioInvestmentsResponse,
PortfolioPerformanceResponse,
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({
@ -1185,7 +1193,7 @@ export class PortfolioService {
currency: userCurrency
});
const { errors, hasErrors, historicalData } =
const { currentValueInBaseCurrency, errors, hasErrors, historicalData } =
await portfolioCalculator.getSnapshot();
const { endDate, startDate } = getIntervalFromDateRange({ dateRange });
@ -1202,8 +1210,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect,
netWorth,
totalInvestment,
totalInvestmentValueWithCurrencyEffect,
valueWithCurrencyEffect
totalInvestmentValueWithCurrencyEffect
} = chart?.at(-1) ?? {
netPerformance: 0,
netPerformanceInPercentage: 0,
@ -1211,7 +1218,7 @@ export class PortfolioService {
netPerformanceWithCurrencyEffect: 0,
netWorth: 0,
totalInvestment: 0,
valueWithCurrencyEffect: 0
totalInvestmentValueWithCurrencyEffect: 0
};
return {
@ -1225,7 +1232,7 @@ export class PortfolioService {
totalInvestment,
totalInvestmentValueWithCurrencyEffect,
currentNetWorth: netWorth,
currentValueInBaseCurrency: valueWithCurrencyEffect,
currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(),
netPerformancePercentage: netPerformanceInPercentage,
netPerformancePercentageWithCurrencyEffect:
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 {
holdings: PortfolioPosition[];
totalValueInBaseCurrency: number;
}

Loading…
Cancel
Save