Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Refactor value to valueInBaseCurrency (#2160)
Thomas Kaul455a2d2e92c3
diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.tsindex 06f841e129..0d9afea51a 100644--- a/apps/api/src/app/portfolio/portfolio.controller.ts+++ b/apps/api/src/app/portfolio/portfolio.controller.ts@@ -134,7 +134,7 @@ export class PortfolioController {portfolioPosition.netPerformance = null;portfolioPosition.quantity = null;portfolioPosition.valueInPercentage =- portfolioPosition.value / totalValue;+ portfolioPosition.valueInBaseCurrency / totalValue;}for (const [name, { valueInBaseCurrency }] of Object.entries(accounts)) {@@ -445,7 +445,8 @@ export class PortfolioController {for (const [symbol, portfolioPosition] of Object.entries(holdings)) {portfolioPublicDetails.holdings[symbol] = {- allocationInPercentage: portfolioPosition.value / totalValue,+ allocationInPercentage:+ portfolioPosition.valueInBaseCurrency / totalValue,countries: hasDetails ? portfolioPosition.countries : [],currency: hasDetails ? portfolioPosition.currency : undefined,dataSource: portfolioPosition.dataSource,@@ -456,7 +457,7 @@ export class PortfolioController {sectors: hasDetails ? portfolioPosition.sectors : [],symbol: portfolioPosition.symbol,url: portfolioPosition.url,- valueInPercentage: portfolioPosition.value / totalValue+ valueInPercentage: portfolioPosition.valueInBaseCurrency / totalValue};}diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.tsindex 7d13728d2d..4bc1c7b158 100644--- a/apps/api/src/app/portfolio/portfolio.service.ts+++ b/apps/api/src/app/portfolio/portfolio.service.ts@@ -585,7 +585,7 @@ export class PortfolioService {symbol: item.symbol,transactionCount: item.transactionCount,url: symbolProfile.url,- value: value.toNumber()+ valueInBaseCurrency: value.toNumber()};}@@ -645,7 +645,7 @@ export class PortfolioService {holdings[userCurrency] = {...emergencyFundCashPositions[userCurrency],investment: emergencyFundInCash,- value: emergencyFundInCash+ valueInBaseCurrency: emergencyFundInCash};}@@ -1278,7 +1278,7 @@ export class PortfolioService {if (cashPositions[account.currency]) {cashPositions[account.currency].investment += convertedBalance;- cashPositions[account.currency].value += convertedBalance;+ cashPositions[account.currency].valueInBaseCurrency += convertedBalance;} else {cashPositions[account.currency] = this.getInitialCashPosition({balance: convertedBalance,@@ -1290,7 +1290,9 @@ export class PortfolioService {for (const symbol of Object.keys(cashPositions)) {// Calculate allocations for each currencycashPositions[symbol].allocationInPercentage = value.gt(0)- ? new Big(cashPositions[symbol].value).div(value).toNumber()+ ? new Big(cashPositions[symbol].valueInBaseCurrency)+ .div(value)+ .toNumber(): 0;}@@ -1475,7 +1477,7 @@ export class PortfolioService {sectors: [],symbol: currency,transactionCount: 0,- value: balance+ valueInBaseCurrency: balance};}diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.tsindex 43f33b70ec..6d2ada8b0d 100644--- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts+++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts@@ -70,7 +70,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {| 'currency'| 'exchange'| 'name'- | 'value'+ | 'valueInBaseCurrency'> & { etfProvider: string };};public sectors: {@@ -292,11 +292,11 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {if (this.hasImpersonationId) {value = position.allocationInPercentage;} else {- value = position.value;+ value = position.valueInBaseCurrency;}this.positions[symbol] = {- value,+ valueInBaseCurrency: value,assetClass: position.assetClass,assetSubClass: position.assetSubClass,currency: position.currency,@@ -323,39 +323,45 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {}this.markets.developedMarkets.value +=- position.markets.developedMarkets * position.value;+ position.markets.developedMarkets * position.valueInBaseCurrency;this.markets.emergingMarkets.value +=- position.markets.emergingMarkets * position.value;+ position.markets.emergingMarkets * position.valueInBaseCurrency;this.markets.otherMarkets.value +=- position.markets.otherMarkets * position.value;+ position.markets.otherMarkets * position.valueInBaseCurrency;for (const country of position.countries) {const { code, continent, name, weight } = country;if (this.continents[continent]?.value) {- this.continents[continent].value += weight * position.value;+ this.continents[continent].value +=+ weight * position.valueInBaseCurrency;} else {this.continents[continent] = {name: continent,- value: weight * this.portfolioDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency};}if (this.countries[code]?.value) {- this.countries[code].value += weight * position.value;+ this.countries[code].value +=+ weight * position.valueInBaseCurrency;} else {this.countries[code] = {name,- value: weight * this.portfolioDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency};}}} else {this.continents[UNKNOWN_KEY].value +=- this.portfolioDetails.holdings[symbol].value;+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency;this.countries[UNKNOWN_KEY].value +=- this.portfolioDetails.holdings[symbol].value;+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency;}if (position.sectors.length > 0) {@@ -363,17 +369,19 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {const { name, weight } = sector;if (this.sectors[name]?.value) {- this.sectors[name].value += weight * position.value;+ this.sectors[name].value += weight * position.valueInBaseCurrency;} else {this.sectors[name] = {name,- value: weight * this.portfolioDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency};}}} else {this.sectors[UNKNOWN_KEY].value +=- this.portfolioDetails.holdings[symbol].value;+ this.portfolioDetails.holdings[symbol].valueInBaseCurrency;}}@@ -381,8 +389,8 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {dataSource: position.dataSource,name: position.name,symbol: prettifySymbol(symbol),- value: isNumber(position.value)- ? position.value+ value: isNumber(position.valueInBaseCurrency)+ ? position.valueInBaseCurrency: position.valueInPercentage};}diff --git a/apps/client/src/app/pages/public/public-page.component.ts b/apps/client/src/app/pages/public/public-page.component.tsindex f25c69dae8..54ff0cf157 100644--- a/apps/client/src/app/pages/public/public-page.component.ts+++ b/apps/client/src/app/pages/public/public-page.component.ts@@ -33,11 +33,18 @@ export class PublicPageComponent implements OnInit {};public portfolioPublicDetails: PortfolioPublicDetails;public positions: {- [symbol: string]: Pick<PortfolioPosition, 'currency' | 'name' | 'value'>;+ [symbol: string]: Pick<+ PortfolioPosition,+ 'currency' | 'name' | 'valueInBaseCurrency'+ >;};public positionsArray: Pick<PortfolioPosition,- 'currency' | 'name' | 'netPerformancePercent' | 'symbol' | 'value'+ | 'currency'+ | 'name'+ | 'netPerformancePercent'+ | 'symbol'+ | 'valueInBaseCurrency'>[];public sectors: {[name: string]: { name: string; value: number };@@ -135,7 +142,7 @@ export class PublicPageComponent implements OnInit {const value = position.allocationInPercentage;this.positions[symbol] = {- value,+ valueInBaseCurrency: value,currency: position.currency,name: position.name};@@ -143,39 +150,44 @@ export class PublicPageComponent implements OnInit {if (position.countries.length > 0) {this.markets.developedMarkets.value +=- position.markets.developedMarkets * position.value;+ position.markets.developedMarkets * position.valueInBaseCurrency;this.markets.emergingMarkets.value +=- position.markets.emergingMarkets * position.value;+ position.markets.emergingMarkets * position.valueInBaseCurrency;this.markets.otherMarkets.value +=- position.markets.otherMarkets * position.value;+ position.markets.otherMarkets * position.valueInBaseCurrency;for (const country of position.countries) {const { code, continent, name, weight } = country;if (this.continents[continent]?.value) {- this.continents[continent].value += weight * position.value;+ this.continents[continent].value +=+ weight * position.valueInBaseCurrency;} else {this.continents[continent] = {name: continent,- value: weight * this.portfolioPublicDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency};}if (this.countries[code]?.value) {- this.countries[code].value += weight * position.value;+ this.countries[code].value += weight * position.valueInBaseCurrency;} else {this.countries[code] = {name,- value: weight * this.portfolioPublicDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency};}}} else {this.continents[UNKNOWN_KEY].value +=- this.portfolioPublicDetails.holdings[symbol].value;+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;this.countries[UNKNOWN_KEY].value +=- this.portfolioPublicDetails.holdings[symbol].value;+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;}if (position.sectors.length > 0) {@@ -183,24 +195,26 @@ export class PublicPageComponent implements OnInit {const { name, weight } = sector;if (this.sectors[name]?.value) {- this.sectors[name].value += weight * position.value;+ this.sectors[name].value += weight * position.valueInBaseCurrency;} else {this.sectors[name] = {name,- value: weight * this.portfolioPublicDetails.holdings[symbol].value+ value:+ weight *+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency};}}} else {this.sectors[UNKNOWN_KEY].value +=- this.portfolioPublicDetails.holdings[symbol].value;+ this.portfolioPublicDetails.holdings[symbol].valueInBaseCurrency;}this.symbols[prettifySymbol(symbol)] = {name: position.name,symbol: prettifySymbol(symbol),- value: isNumber(position.value)- ? position.value+ value: isNumber(position.valueInBaseCurrency)+ ? position.valueInBaseCurrency: position.valueInPercentage};}diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.tsindex 99416ae57f..c29529590d 100644--- a/apps/client/src/app/services/data.service.ts+++ b/apps/client/src/app/services/data.service.ts@@ -415,10 +415,10 @@ export class DataService {map((response) => {if (response.holdings) {for (const symbol of Object.keys(response.holdings)) {- response.holdings[symbol].value = isNumber(- response.holdings[symbol].value+ response.holdings[symbol].valueInBaseCurrency = isNumber(+ response.holdings[symbol].valueInBaseCurrency)- ? response.holdings[symbol].value+ ? response.holdings[symbol].valueInBaseCurrency: response.holdings[symbol].valueInPercentage;}}diff --git a/libs/common/src/lib/interfaces/portfolio-position.interface.ts b/libs/common/src/lib/interfaces/portfolio-position.interface.tsindex 2b7c6c4864..81ac0b7ad8 100644--- a/libs/common/src/lib/interfaces/portfolio-position.interface.ts+++ b/libs/common/src/lib/interfaces/portfolio-position.interface.ts@@ -30,6 +30,6 @@ export interface PortfolioPosition {symbol: string;type?: string;url?: string;- value?: number;+ valueInBaseCurrency?: number;valueInPercentage?: number;}diff --git a/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts b/libs/common/src/lib/interfaces/portfolio-public-details.interface.tsindex 7abc7f78fd..fb56ed94d8 100644--- a/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts+++ b/libs/common/src/lib/interfaces/portfolio-public-details.interface.ts@@ -17,7 +17,7 @@ export interface PortfolioPublicDetails {| 'sectors'| 'symbol'| 'url'- | 'value'+ | 'valueInBaseCurrency'| 'valueInPercentage'>;};