Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/refactor portfolio holding response (#4649)
Thomas Kaul3646fb7f7769
diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.tsindex 4cb6d46c23..7afb2cd726 100644--- a/apps/api/src/app/import/import.service.ts+++ b/apps/api/src/app/import/import.service.ts@@ -49,7 +49,7 @@ export class ImportService {symbol}: AssetProfileIdentifier): Promise<Activity[]> {try {- const { firstBuyDate, historicalData, orders } =+ const { activities, firstBuyDate, historicalData } =await this.portfolioService.getHolding(dataSource, undefined, symbol);const [[assetProfile], dividends] = await Promise.all([@@ -68,7 +68,7 @@ export class ImportService {})]);- const accounts = orders+ const accounts = activities.filter(({ Account }) => {return !!Account;})@@ -88,7 +88,7 @@ export class ImportService {const value = new Big(quantity).mul(marketPrice).toNumber();const date = parseDate(dateString);- const isDuplicate = orders.some((activity) => {+ const isDuplicate = activities.some((activity) => {return (activity.accountId === Account?.id &&activity.SymbolProfile.currency === assetProfile.currency &&diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.tsindex 26265e8c8b..47c773e808 100644--- a/apps/api/src/app/portfolio/portfolio.service.ts+++ b/apps/api/src/app/portfolio/portfolio.service.ts@@ -648,6 +648,7 @@ export class PortfolioService {if (activities.length === 0) {return {+ activities: [],averagePrice: undefined,dataProviderInfo: undefined,dividendInBaseCurrency: undefined,@@ -662,13 +663,12 @@ export class PortfolioService {historicalData: [],investment: undefined,marketPrice: undefined,- maxPrice: undefined,- minPrice: undefined,+ marketPriceMax: undefined,+ marketPriceMin: undefined,netPerformance: undefined,netPerformancePercent: undefined,netPerformancePercentWithCurrencyEffect: undefined,netPerformanceWithCurrencyEffect: undefined,- orders: [],quantity: undefined,SymbolProfile: undefined,tags: [],@@ -714,7 +714,7 @@ export class PortfolioService {transactionCount} = position;- const activitiesOfPosition = activities.filter(({ SymbolProfile }) => {+ const activitiesOfHolding = activities.filter(({ SymbolProfile }) => {return (SymbolProfile.dataSource === dataSource &&SymbolProfile.symbol === symbol@@ -748,12 +748,12 @@ export class PortfolioService {);const historicalDataArray: HistoricalDataItem[] = [];- let maxPrice = Math.max(- activitiesOfPosition[0].unitPriceInAssetProfileCurrency,+ let marketPriceMax = Math.max(+ activitiesOfHolding[0].unitPriceInAssetProfileCurrency,marketPrice);- let minPrice = Math.min(- activitiesOfPosition[0].unitPriceInAssetProfileCurrency,+ let marketPriceMin = Math.min(+ activitiesOfHolding[0].unitPriceInAssetProfileCurrency,marketPrice);@@ -793,27 +793,31 @@ export class PortfolioService {quantity: currentQuantity});- maxPrice = Math.max(marketPrice ?? 0, maxPrice);- minPrice = Math.min(marketPrice ?? Number.MAX_SAFE_INTEGER, minPrice);+ marketPriceMax = Math.max(marketPrice ?? 0, marketPriceMax);+ marketPriceMin = Math.min(+ marketPrice ?? Number.MAX_SAFE_INTEGER,+ marketPriceMin+ );}} else {// Add historical entry for buy date, if no historical data availablehistoricalDataArray.push({- averagePrice: activitiesOfPosition[0].unitPriceInAssetProfileCurrency,+ averagePrice: activitiesOfHolding[0].unitPriceInAssetProfileCurrency,date: firstBuyDate,- marketPrice: activitiesOfPosition[0].unitPriceInAssetProfileCurrency,- quantity: activitiesOfPosition[0].quantity+ marketPrice: activitiesOfHolding[0].unitPriceInAssetProfileCurrency,+ quantity: activitiesOfHolding[0].quantity});}return {firstBuyDate,marketPrice,- maxPrice,- minPrice,+ marketPriceMax,+ marketPriceMin,SymbolProfile,tags,transactionCount,+ activities: activitiesOfHolding,averagePrice: averagePrice.toNumber(),dataProviderInfo: portfolioCalculator.getDataProviderInfos()?.[0],dividendInBaseCurrency: dividendInBaseCurrency.toNumber(),@@ -842,7 +846,6 @@ export class PortfolioService {]?.toNumber(),netPerformanceWithCurrencyEffect:position.netPerformanceWithCurrencyEffectMap?.['max']?.toNumber(),- orders: activitiesOfPosition,quantity: quantity.toNumber(),value: this.exchangeRateDataService.toCurrency(quantity.mul(marketPrice ?? 0).toNumber(),@@ -881,8 +884,8 @@ export class PortfolioService {}const historicalDataArray: HistoricalDataItem[] = [];- let maxPrice = marketPrice;- let minPrice = marketPrice;+ let marketPriceMax = marketPrice;+ let marketPriceMin = marketPrice;for (const [date, { marketPrice }] of Object.entries(historicalData[aSymbol]@@ -892,15 +895,19 @@ export class PortfolioService {value: marketPrice});- maxPrice = Math.max(marketPrice ?? 0, maxPrice);- minPrice = Math.min(marketPrice ?? Number.MAX_SAFE_INTEGER, minPrice);+ marketPriceMax = Math.max(marketPrice ?? 0, marketPriceMax);+ marketPriceMin = Math.min(+ marketPrice ?? Number.MAX_SAFE_INTEGER,+ marketPriceMin+ );}return {marketPrice,- maxPrice,- minPrice,+ marketPriceMax,+ marketPriceMin,SymbolProfile,+ activities: [],averagePrice: 0,dataProviderInfo: undefined,dividendInBaseCurrency: 0,@@ -918,7 +925,6 @@ export class PortfolioService {netPerformancePercent: undefined,netPerformancePercentWithCurrencyEffect: undefined,netPerformanceWithCurrencyEffect: undefined,- orders: [],quantity: 0,tags: [],transactionCount: undefined,diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.tsindex 25317e0c57..925a644298 100644--- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts+++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts@@ -105,8 +105,8 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {public investmentPrecision = 2;public marketDataItems: MarketData[] = [];public marketPrice: number;- public maxPrice: number;- public minPrice: number;+ public marketPriceMax: number;+ public marketPriceMin: number;public netPerformance: number;public netPerformancePrecision = 2;public netPerformancePercent: number;@@ -234,8 +234,8 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {historicalData,investment,marketPrice,- maxPrice,- minPrice,+ marketPriceMax,+ marketPriceMin,netPerformance,netPerformancePercent,netPerformancePercentWithCurrencyEffect,@@ -297,8 +297,8 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {}this.marketPrice = marketPrice;- this.maxPrice = maxPrice;- this.minPrice = minPrice;+ this.marketPriceMax = marketPriceMax;+ this.marketPriceMin = marketPriceMin;this.netPerformance = netPerformance;if (diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.htmlindex 9e8855d717..d18dc479b9 100644--- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html+++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html@@ -106,11 +106,11 @@[locale]="data.locale"[ngClass]="{'text-danger':- minPrice?.toFixed(2) === marketPrice?.toFixed(2) &&- maxPrice?.toFixed(2) !== minPrice?.toFixed(2)+ marketPriceMin?.toFixed(2) === marketPrice?.toFixed(2) &&+ marketPriceMax?.toFixed(2) !== marketPriceMin?.toFixed(2)}"[unit]="SymbolProfile?.currency"- [value]="minPrice"+ [value]="marketPriceMin">Minimum Price</gf-value></div>@@ -122,11 +122,11 @@[locale]="data.locale"[ngClass]="{'text-success':- maxPrice?.toFixed(2) === marketPrice?.toFixed(2) &&- maxPrice?.toFixed(2) !== minPrice?.toFixed(2)+ marketPriceMax?.toFixed(2) === marketPrice?.toFixed(2) &&+ marketPriceMax?.toFixed(2) !== marketPriceMin?.toFixed(2)}"[unit]="SymbolProfile?.currency"- [value]="maxPrice"+ [value]="marketPriceMax">Maximum Price</gf-value></div>diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.tsindex 41cde8c872..e3bd9f27b9 100644--- a/apps/client/src/app/services/data.service.ts+++ b/apps/client/src/app/services/data.service.ts@@ -411,8 +411,8 @@ export class DataService {).pipe(map((data) => {- if (data.orders) {- for (const order of data.orders) {+ if (data.activities) {+ for (const order of data.activities) {order.createdAt = parseISO(order.createdAt as unknown as string);order.date = parseISO(order.date as unknown as string);}diff --git a/libs/common/src/lib/interfaces/responses/portfolio-holding-response.interface.ts b/libs/common/src/lib/interfaces/responses/portfolio-holding-response.interface.tsindex cfdc1611d0..c460242af4 100644--- a/libs/common/src/lib/interfaces/responses/portfolio-holding-response.interface.ts+++ b/libs/common/src/lib/interfaces/responses/portfolio-holding-response.interface.ts@@ -8,6 +8,7 @@ import {import { Tag } from '@prisma/client';export interface PortfolioHoldingResponse {+ activities: Activity[];averagePrice: number;dataProviderInfo: DataProviderInfo;dividendInBaseCurrency: number;@@ -22,13 +23,12 @@ export interface PortfolioHoldingResponse {historicalData: HistoricalDataItem[];investment: number;marketPrice: number;- maxPrice: number;- minPrice: number;+ marketPriceMax: number;+ marketPriceMin: number;netPerformance: number;netPerformancePercent: number;netPerformancePercentWithCurrencyEffect: number;netPerformanceWithCurrencyEffect: number;- orders: Activity[];quantity: number;SymbolProfile: EnhancedSymbolProfile;tags: Tag[];