Browse Source

Refactor portfolio service

pull/5063/head
Thomas Kaul 2 days ago
parent
commit
f494da78dc
  1. 27
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -709,26 +709,24 @@ export class PortfolioService {
const { positions } = await portfolioCalculator.getSnapshot(); const { positions } = await portfolioCalculator.getSnapshot();
const position = positions.find((position) => { const holding = positions.find((position) => {
return position.dataSource === dataSource && position.symbol === symbol; return position.dataSource === dataSource && position.symbol === symbol;
}); });
if (position) { if (holding) {
const { const {
averagePrice, averagePrice,
currency, currency,
dataSource,
dividendInBaseCurrency, dividendInBaseCurrency,
fee, fee,
firstBuyDate, firstBuyDate,
marketPrice, marketPrice,
quantity, quantity,
symbol,
tags, tags,
timeWeightedInvestment, timeWeightedInvestment,
timeWeightedInvestmentWithCurrencyEffect, timeWeightedInvestmentWithCurrencyEffect,
transactionCount transactionCount
} = position; } = holding;
const activitiesOfHolding = activities.filter(({ SymbolProfile }) => { const activitiesOfHolding = activities.filter(({ SymbolProfile }) => {
return ( return (
@ -858,24 +856,23 @@ export class PortfolioService {
SymbolProfile.currency, SymbolProfile.currency,
userCurrency userCurrency
), ),
grossPerformance: position.grossPerformance?.toNumber(), grossPerformance: holding.grossPerformance?.toNumber(),
grossPerformancePercent: grossPerformancePercent: holding.grossPerformancePercentage?.toNumber(),
position.grossPerformancePercentage?.toNumber(),
grossPerformancePercentWithCurrencyEffect: grossPerformancePercentWithCurrencyEffect:
position.grossPerformancePercentageWithCurrencyEffect?.toNumber(), holding.grossPerformancePercentageWithCurrencyEffect?.toNumber(),
grossPerformanceWithCurrencyEffect: grossPerformanceWithCurrencyEffect:
position.grossPerformanceWithCurrencyEffect?.toNumber(), holding.grossPerformanceWithCurrencyEffect?.toNumber(),
historicalData: historicalDataArray, historicalData: historicalDataArray,
investmentInBaseCurrencyWithCurrencyEffect: investmentInBaseCurrencyWithCurrencyEffect:
position.investmentWithCurrencyEffect?.toNumber(), holding.investmentWithCurrencyEffect?.toNumber(),
netPerformance: position.netPerformance?.toNumber(), netPerformance: holding.netPerformance?.toNumber(),
netPerformancePercent: position.netPerformancePercentage?.toNumber(), netPerformancePercent: holding.netPerformancePercentage?.toNumber(),
netPerformancePercentWithCurrencyEffect: netPerformancePercentWithCurrencyEffect:
position.netPerformancePercentageWithCurrencyEffectMap?.[ holding.netPerformancePercentageWithCurrencyEffectMap?.[
'max' 'max'
]?.toNumber(), ]?.toNumber(),
netPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffect:
position.netPerformanceWithCurrencyEffectMap?.['max']?.toNumber(), holding.netPerformanceWithCurrencyEffectMap?.['max']?.toNumber(),
performances: { performances: {
allTimeHigh: { allTimeHigh: {
performancePercent, performancePercent,

Loading…
Cancel
Save