From e0435e5cadecb5f910bf86e95af3153769241f2b Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 25 Jul 2021 12:23:18 +0200 Subject: [PATCH] Add name to position --- apps/api/src/app/core/portfolio-calculator.ts | 31 +++++++++++-------- .../src/app/portfolio/portfolio.service.ts | 7 +++-- .../interfaces/timeline-position.interface.ts | 1 + 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index a0d32f147..18d852152 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -56,25 +56,27 @@ export class PortfolioCalculator { const unitPrice = new Big(order.unitPrice); if (oldAccumulatedSymbol) { currentTransactionPointItem = { - quantity: order.quantity - .mul(factor) - .plus(oldAccumulatedSymbol.quantity), - symbol: order.symbol, + currency: order.currency, + firstBuyDate: oldAccumulatedSymbol.firstBuyDate, investment: unitPrice .mul(order.quantity) .mul(factor) .add(oldAccumulatedSymbol.investment), - currency: order.currency, - firstBuyDate: oldAccumulatedSymbol.firstBuyDate, + name: order.name, + quantity: order.quantity + .mul(factor) + .plus(oldAccumulatedSymbol.quantity), + symbol: order.symbol, transactionCount: oldAccumulatedSymbol.transactionCount + 1 }; } else { currentTransactionPointItem = { - quantity: order.quantity.mul(factor), - symbol: order.symbol, - investment: unitPrice.mul(order.quantity).mul(factor), currency: order.currency, firstBuyDate: order.date, + investment: unitPrice.mul(order.quantity).mul(factor), + name: order.name, + quantity: order.quantity.mul(factor), + symbol: order.symbol, transactionCount: 1 }; } @@ -147,6 +149,7 @@ export class PortfolioCalculator { : null, investment: item.investment, marketPrice: marketValue?.marketPrice, + name: item.name, quantity: item.quantity, symbol: item.symbol, transactionCount: item.transactionCount @@ -384,11 +387,12 @@ interface TransactionPoint { } interface TransactionPointSymbol { - quantity: Big; - symbol: string; - investment: Big; currency: Currency; firstBuyDate: string; + investment: Big; + name: string; + quantity: Big; + symbol: string; transactionCount: number; } @@ -407,10 +411,11 @@ export interface TimelinePeriod { } export interface PortfolioOrder { + currency: Currency; date: string; + name: string; quantity: Big; symbol: string; type: OrderType; unitPrice: Big; - currency: Currency; } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 1a8bfd5d7..6d39ce003 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -231,7 +231,7 @@ export class PortfolioService { position.grossPerformancePercentage ).toNumber(), investment: new Big(position.investment).toNumber(), - name: '', // TODO + name: position.name, quantity: new Big(position.quantity).toNumber(), type: Type.Unknown, // TODO url: '' // TODO @@ -267,12 +267,13 @@ export class PortfolioService { } const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ + currency: order.currency, date: format(order.date, 'yyyy-MM-dd'), + name: order.SymbolProfile?.name, quantity: new Big(order.quantity), symbol: order.symbol, type: order.type, - unitPrice: new Big(order.unitPrice), - currency: order.currency + unitPrice: new Big(order.unitPrice) })); const portfolioCalculator = new PortfolioCalculator( diff --git a/libs/common/src/lib/interfaces/timeline-position.interface.ts b/libs/common/src/lib/interfaces/timeline-position.interface.ts index 533c09a04..4fb306332 100644 --- a/libs/common/src/lib/interfaces/timeline-position.interface.ts +++ b/libs/common/src/lib/interfaces/timeline-position.interface.ts @@ -9,6 +9,7 @@ export interface TimelinePosition { grossPerformancePercentage: Big; investment: Big; marketPrice: number; + name: string; quantity: Big; symbol: string; transactionCount: number;