Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/improve market price of first buy date in chart of position detail dialog (#1956)

Thomas Kaulef4a75d1f0c0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e4f7a72c7..be0e0135ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Changed
+
+- Improved the market price on the first buy date in the chart of the position detail dialog
+
## 1.268.0 - 2023-05-08
### Added
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index 830a4bbe9d..7755146f1a 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -794,16 +794,6 @@ export class PortfolioService {
let maxPrice = Math.max(orders[0].unitPrice, marketPrice);
let minPrice = Math.min(orders[0].unitPrice, marketPrice);
- if (!historicalData?.[aSymbol]?.[firstBuyDate]) {
- // Add historical entry for buy date, if no historical data available
- historicalDataArray.push({
- averagePrice: orders[0].unitPrice,
- date: firstBuyDate,
- marketPrice: orders[0].unitPrice,
- quantity: orders[0].quantity
- });
- }
-
if (historicalData[aSymbol]) {
let j = -1;
for (const [date, { marketPrice }] of Object.entries(
@@ -815,11 +805,16 @@ export class PortfolioService {
) {
j++;
}
+
let currentAveragePrice = 0;
let currentQuantity = 0;
+
const currentSymbol = transactionPoints[j].items.find(
- (item) => item.symbol === aSymbol
+ ({ symbol }) => {
+ return symbol === aSymbol;
+ }
);
+
if (currentSymbol) {
currentAveragePrice = currentSymbol.quantity.eq(0)
? 0
@@ -829,14 +824,25 @@ export class PortfolioService {
historicalDataArray.push({
date,
- marketPrice,
averagePrice: currentAveragePrice,
+ marketPrice:
+ historicalDataArray.length > 0
+ ? marketPrice
+ : currentAveragePrice,
quantity: currentQuantity
});
maxPrice = Math.max(marketPrice ?? 0, maxPrice);
minPrice = Math.min(marketPrice ?? Number.MAX_SAFE_INTEGER, minPrice);
}
+ } else {
+ // Add historical entry for buy date, if no historical data available
+ historicalDataArray.push({
+ averagePrice: orders[0].unitPrice,
+ date: firstBuyDate,
+ marketPrice: orders[0].unitPrice,
+ quantity: orders[0].quantity
+ });
}
return {