Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Bugfix/fix cash position in user currency (#1433)
Thomas Kaul33fd1282e51f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 839d41c389..2ab5c03055 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Merged the _FIRE_ calculator and the _X-ray_ section to a single page- Tightened the validation rule of the base currency environment variable (`BASE_CURRENCY`)+### Fixed++- Fixed an issue in the cash positions calculation+## 1.209.0 - 05.11.2022### Addeddiff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.tsindex 06722cefde..f7efd66512 100644--- a/apps/api/src/app/portfolio/portfolio.service.ts+++ b/apps/api/src/app/portfolio/portfolio.service.ts@@ -31,6 +31,7 @@ import {HistoricalDataItem,PortfolioDetails,PortfolioPerformanceResponse,+ PortfolioPosition,PortfolioReport,PortfolioSummary,Position,@@ -1109,7 +1110,12 @@ export class PortfolioService {value: Big;userCurrency: string;}) {- const cashPositions: PortfolioDetails['holdings'] = {};+ const cashPositions: PortfolioDetails['holdings'] = {+ [userCurrency]: this.getInitialCashPosition({+ balance: 0,+ currency: userCurrency+ })+ };for (const account of cashDetails.accounts) {const convertedBalance = this.exchangeRateDataService.toCurrency(@@ -1126,28 +1132,10 @@ export class PortfolioService {cashPositions[account.currency].investment += convertedBalance;cashPositions[account.currency].value += convertedBalance;} else {- cashPositions[account.currency] = {- allocationCurrent: 0,- allocationInvestment: 0,- assetClass: AssetClass.CASH,- assetSubClass: AssetClass.CASH,- countries: [],- currency: account.currency,- dataSource: undefined,- grossPerformance: 0,- grossPerformancePercent: 0,- investment: convertedBalance,- marketPrice: 0,- marketState: 'open',- name: account.currency,- netPerformance: 0,- netPerformancePercent: 0,- quantity: 0,- sectors: [],- symbol: account.currency,- transactionCount: 0,- value: convertedBalance- };+ cashPositions[account.currency] = this.getInitialCashPosition({+ balance: convertedBalance,+ currency: account.currency+ });}}@@ -1247,6 +1235,37 @@ export class PortfolioService {);}+ private getInitialCashPosition({+ balance,+ currency+ }: {+ balance: number;+ currency: string;+ }): PortfolioPosition {+ return {+ currency,+ allocationCurrent: 0,+ allocationInvestment: 0,+ assetClass: AssetClass.CASH,+ assetSubClass: AssetClass.CASH,+ countries: [],+ dataSource: undefined,+ grossPerformance: 0,+ grossPerformancePercent: 0,+ investment: balance,+ marketPrice: 0,+ marketState: 'open',+ name: currency,+ netPerformance: 0,+ netPerformancePercent: 0,+ quantity: 0,+ sectors: [],+ symbol: currency,+ transactionCount: 0,+ value: balance+ };+ }+private getItems(orders: OrderWithAccount[], date = new Date(0)) {return orders.filter((order) => {