From 68b1085b4df811c7d9280b34f318d5e108ec6857 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 Sep 2021 09:23:32 +0200 Subject: [PATCH] Clean up after code review --- .../interfaces/portfolio-order.interface.ts | 2 +- .../transaction-point-symbol.interface.ts | 2 +- .../src/app/portfolio/portfolio-calculator.ts | 14 +++++++------- .../api/src/app/portfolio/portfolio.service.ts | 18 +++++++++--------- .../interfaces/timeline-position.interface.ts | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts index de258539a..2b443236e 100644 --- a/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts @@ -5,10 +5,10 @@ import Big from 'big.js'; export interface PortfolioOrder { currency: Currency; date: string; + fee: Big; name: string; quantity: Big; symbol: string; type: OrderType; unitPrice: Big; - fee: Big; } diff --git a/apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts b/apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts index 593bbac4b..91dcdd63b 100644 --- a/apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts @@ -3,10 +3,10 @@ import Big from 'big.js'; export interface TransactionPointSymbol { currency: Currency; + fee: Big; firstBuyDate: string; investment: Big; quantity: Big; symbol: string; transactionCount: number; - fee: Big; } diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 82f328b05..60facc686 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -58,6 +58,7 @@ export class PortfolioCalculator { .plus(oldAccumulatedSymbol.quantity); currentTransactionPointItem = { currency: order.currency, + fee: order.fee, firstBuyDate: oldAccumulatedSymbol.firstBuyDate, investment: newQuantity.eq(0) ? new Big(0) @@ -67,17 +68,16 @@ export class PortfolioCalculator { .add(oldAccumulatedSymbol.investment), quantity: newQuantity, symbol: order.symbol, - fee: order.fee, transactionCount: oldAccumulatedSymbol.transactionCount + 1 }; } else { currentTransactionPointItem = { currency: order.currency, + fee: order.fee, firstBuyDate: order.date, investment: unitPrice.mul(order.quantity).mul(factor), quantity: order.quantity.mul(factor), symbol: order.symbol, - fee: order.fee, transactionCount: 1 }; } @@ -119,13 +119,13 @@ export class PortfolioCalculator { public async getCurrentPositions(start: Date): Promise { if (!this.transactionPoints?.length) { return { + currentValue: new Big(0), hasErrors: false, - positions: [], grossPerformance: new Big(0), grossPerformancePercentage: new Big(0), netPerformance: new Big(0), netPerformancePercentage: new Big(0), - currentValue: new Big(0), + positions: [], totalInvestment: new Big(0) }; } @@ -300,13 +300,13 @@ export class PortfolioCalculator { isValid && holdingPeriodReturns[item.symbol] ? holdingPeriodReturns[item.symbol].minus(1) : null, + investment: item.investment, + marketPrice: marketValue?.toNumber() ?? null, netPerformance: isValid ? netPerformance[item.symbol] ?? null : null, netPerformancePercentage: isValid && netHoldingPeriodReturns[item.symbol] ? netHoldingPeriodReturns[item.symbol].minus(1) : null, - investment: item.investment, - marketPrice: marketValue?.toNumber() ?? null, quantity: item.quantity, symbol: item.symbol, transactionCount: item.transactionCount @@ -461,9 +461,9 @@ export class PortfolioCalculator { currentValue, grossPerformance, grossPerformancePercentage, + hasErrors, netPerformance, netPerformancePercentage, - hasErrors, totalInvestment }; } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 392e8d3cc..bbdd9302a 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -291,12 +291,12 @@ export class PortfolioService { const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ currency: order.currency, date: format(order.date, DATE_FORMAT), + fee: new Big(order.fee), name: order.SymbolProfile?.name, quantity: new Big(order.quantity), symbol: order.symbol, type: order.type, - unitPrice: new Big(order.unitPrice), - fee: new Big(order.fee) + unitPrice: new Big(order.unitPrice) })); const portfolioCalculator = new PortfolioCalculator( @@ -779,6 +779,13 @@ export class PortfolioService { const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ currency: order.currency, date: format(order.date, DATE_FORMAT), + fee: new Big( + this.exchangeRateDataService.toCurrency( + order.fee, + order.currency, + userCurrency + ) + ), name: order.SymbolProfile?.name, quantity: new Big(order.quantity), symbol: order.symbol, @@ -789,13 +796,6 @@ export class PortfolioService { order.currency, userCurrency ) - ), - fee: new Big( - this.exchangeRateDataService.toCurrency( - order.fee, - order.currency, - userCurrency - ) ) })); diff --git a/libs/common/src/lib/interfaces/timeline-position.interface.ts b/libs/common/src/lib/interfaces/timeline-position.interface.ts index 420833869..76604955a 100644 --- a/libs/common/src/lib/interfaces/timeline-position.interface.ts +++ b/libs/common/src/lib/interfaces/timeline-position.interface.ts @@ -7,10 +7,10 @@ export interface TimelinePosition { firstBuyDate: string; grossPerformance: Big; grossPerformancePercentage: Big; - netPerformance: Big; - netPerformancePercentage: Big; investment: Big; marketPrice: number; + netPerformance: Big; + netPerformancePercentage: Big; quantity: Big; symbol: string; transactionCount: number;