From 7f09a8fd825e13ba67662447c15e3e859634d7bc Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Wed, 11 Aug 2021 21:39:46 +0200 Subject: [PATCH] Fix position chart for missing historical data --- CHANGELOG.md | 1 + apps/api/src/app/portfolio/portfolio.service.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c12af951..d9c587c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed hidden cryptocurrency holdings +- Fixed the position detail chart if there are missing historical data around the first buy date ## 1.35.0 - 08.08.2021 diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index d95331ca7..63d781f05 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -362,8 +362,17 @@ export class PortfolioService { ); const historicalDataArray: HistoricalDataItem[] = []; - let maxPrice = marketPrice; - let minPrice = marketPrice; + let maxPrice = orders[0].unitPrice; + let minPrice = orders[0].unitPrice; + + if (!historicalData[aSymbol][firstBuyDate]) { + // Add historical entry for buy date, if no historical data available + historicalDataArray.push({ + averagePrice: orders[0].unitPrice, + date: firstBuyDate, + value: orders[0].unitPrice + }); + } if (historicalData[aSymbol]) { let j = -1;