From 218efbb5bd27fa155d2fb6fe5345313aac8672bc Mon Sep 17 00:00:00 2001 From: Valentin Zickner <3200232+vzickner@users.noreply.github.com> Date: Sat, 7 Aug 2021 07:03:35 +0200 Subject: [PATCH] fix position diagram for sold items (#261) * fix position diagram for sold items * Add missing data to position from the past * Update changelog Co-authored-by: Valentin Zickner Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com> --- CHANGELOG.md | 1 + .../src/app/portfolio/portfolio.service.ts | 20 ++++++++++++------- .../position-detail-dialog.html | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e3e21ee..b774d54f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed an issue with the currency conversion of the market price in the position detail dialog +- Fixed the chart and missing data of positions from the past in the position detail dialog ## 1.33.0 - 05.08.2021 diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 5bb2a711..71a08d1a 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -391,6 +391,7 @@ export class PortfolioService { }; } else { const currentData = await this.dataProviderService.get([aSymbol]); + const marketPrice = currentData[aSymbol]?.marketPrice; let historicalData = await this.dataProviderService.getHistorical( [aSymbol], @@ -408,28 +409,33 @@ export class PortfolioService { } const historicalDataArray: HistoricalDataItem[] = []; + let maxPrice = marketPrice; + let minPrice = marketPrice; for (const [date, { marketPrice }] of Object.entries( historicalData[aSymbol] - ).reverse()) { + )) { historicalDataArray.push({ date, value: marketPrice }); + + maxPrice = Math.max(marketPrice ?? 0, maxPrice); + minPrice = Math.min(marketPrice ?? Number.MAX_SAFE_INTEGER, minPrice); } return { - averagePrice: undefined, + marketPrice, + maxPrice, + minPrice, + averagePrice: 0, currency: currentData[aSymbol]?.currency, firstBuyDate: undefined, grossPerformance: undefined, grossPerformancePercent: undefined, historicalData: historicalDataArray, - investment: undefined, - marketPrice: currentData[aSymbol]?.marketPrice, - maxPrice: undefined, - minPrice: undefined, - quantity: undefined, + investment: 0, + quantity: 0, symbol: aSymbol, transactionCount: undefined }; diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html index fbd54e14..870ec1fb 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html @@ -1,7 +1,7 @@