From f494da78dc3d7a4606a9b6e800dacffc6851ca7d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 29 Jun 2025 21:20:35 +0200 Subject: [PATCH] Refactor portfolio service --- .../src/app/portfolio/portfolio.service.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index c4c38a646..38a355cab 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -709,26 +709,24 @@ export class PortfolioService { const { positions } = await portfolioCalculator.getSnapshot(); - const position = positions.find((position) => { + const holding = positions.find((position) => { return position.dataSource === dataSource && position.symbol === symbol; }); - if (position) { + if (holding) { const { averagePrice, currency, - dataSource, dividendInBaseCurrency, fee, firstBuyDate, marketPrice, quantity, - symbol, tags, timeWeightedInvestment, timeWeightedInvestmentWithCurrencyEffect, transactionCount - } = position; + } = holding; const activitiesOfHolding = activities.filter(({ SymbolProfile }) => { return ( @@ -858,24 +856,23 @@ export class PortfolioService { SymbolProfile.currency, userCurrency ), - grossPerformance: position.grossPerformance?.toNumber(), - grossPerformancePercent: - position.grossPerformancePercentage?.toNumber(), + grossPerformance: holding.grossPerformance?.toNumber(), + grossPerformancePercent: holding.grossPerformancePercentage?.toNumber(), grossPerformancePercentWithCurrencyEffect: - position.grossPerformancePercentageWithCurrencyEffect?.toNumber(), + holding.grossPerformancePercentageWithCurrencyEffect?.toNumber(), grossPerformanceWithCurrencyEffect: - position.grossPerformanceWithCurrencyEffect?.toNumber(), + holding.grossPerformanceWithCurrencyEffect?.toNumber(), historicalData: historicalDataArray, investmentInBaseCurrencyWithCurrencyEffect: - position.investmentWithCurrencyEffect?.toNumber(), - netPerformance: position.netPerformance?.toNumber(), - netPerformancePercent: position.netPerformancePercentage?.toNumber(), + holding.investmentWithCurrencyEffect?.toNumber(), + netPerformance: holding.netPerformance?.toNumber(), + netPerformancePercent: holding.netPerformancePercentage?.toNumber(), netPerformancePercentWithCurrencyEffect: - position.netPerformancePercentageWithCurrencyEffectMap?.[ + holding.netPerformancePercentageWithCurrencyEffectMap?.[ 'max' ]?.toNumber(), netPerformanceWithCurrencyEffect: - position.netPerformanceWithCurrencyEffectMap?.['max']?.toNumber(), + holding.netPerformanceWithCurrencyEffectMap?.['max']?.toNumber(), performances: { allTimeHigh: { performancePercent,