From 8571709014d93afafd85be0091ac2e5db68fbe6b Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Wed, 28 Jul 2021 15:57:48 +0200 Subject: [PATCH] Refactoring --- apps/api/src/app/core/portfolio-calculator.ts | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index f0cd0b5d2..e0cd2633d 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -103,14 +103,14 @@ export class PortfolioCalculator { } } - public setTransactionPoints(transactionPoints: TransactionPoint[]) { - this.transactionPoints = transactionPoints; - } - public getTransactionPoints(): TransactionPoint[] { return this.transactionPoints; } + public setTransactionPoints(transactionPoints: TransactionPoint[]) { + this.transactionPoints = transactionPoints; + } + public async getCurrentPositions(start: Date): Promise<{ hasErrors: boolean; positions: TimelinePosition[]; @@ -331,35 +331,6 @@ export class PortfolioCalculator { return flatten(timelinePeriods); } - private async getMarketValues( - transactionPoint: TransactionPoint, - dateRangeStart: Date, - dateRangeEnd: Date - ) { - const symbols: string[] = []; - const currencies: { [symbol: string]: Currency } = {}; - - for (const item of transactionPoint.items) { - symbols.push(item.symbol); - currencies[item.symbol] = item.currency; - } - const values = await this.currentRateService.getValues({ - dateQuery: { - gte: dateRangeStart, - lt: endOfDay(dateRangeEnd) - }, - symbols, - currencies, - userCurrency: this.currency - }); - - const marketValues: { [symbol: string]: GetValueObject } = {}; - for (const value of values) { - marketValues[value.symbol] = value; - } - return marketValues; - } - private async getTimePeriodForDate( j: number, startDate: Date, @@ -450,6 +421,7 @@ export class PortfolioCalculator { private getFactor(type: OrderType) { let factor: number; + switch (type) { case OrderType.Buy: factor = 1; @@ -461,6 +433,7 @@ export class PortfolioCalculator { factor = 0; break; } + return factor; }