|  |  | @ -99,15 +99,22 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |       const value = details.accounts[account.id]?.current ?? 0; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |       const result = { | 
			
		
	
		
			
				
					|  |  |  |         ...account, | 
			
		
	
		
			
				
					|  |  |  |         transactionCount, | 
			
		
	
		
			
				
					|  |  |  |         convertedBalance: this.exchangeRateDataService.toCurrency( | 
			
		
	
		
			
				
					|  |  |  |         value, | 
			
		
	
		
			
				
					|  |  |  |         balanceInBaseCurrency: this.exchangeRateDataService.toCurrency( | 
			
		
	
		
			
				
					|  |  |  |           account.balance, | 
			
		
	
		
			
				
					|  |  |  |           account.currency, | 
			
		
	
		
			
				
					|  |  |  |           userCurrency | 
			
		
	
		
			
				
					|  |  |  |         ), | 
			
		
	
		
			
				
					|  |  |  |         value: details.accounts[account.id]?.current ?? 0 | 
			
		
	
		
			
				
					|  |  |  |         valueInBaseCurrency: this.exchangeRateDataService.toCurrency( | 
			
		
	
		
			
				
					|  |  |  |           value, | 
			
		
	
		
			
				
					|  |  |  |           account.currency, | 
			
		
	
		
			
				
					|  |  |  |           userCurrency | 
			
		
	
		
			
				
					|  |  |  |         ) | 
			
		
	
		
			
				
					|  |  |  |       }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |       delete result.Order; | 
			
		
	
	
		
			
				
					|  |  | @ -118,17 +125,26 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   public async getAccountsWithAggregations(aUserId: string): Promise<Accounts> { | 
			
		
	
		
			
				
					|  |  |  |     const accounts = await this.getAccounts(aUserId); | 
			
		
	
		
			
				
					|  |  |  |     let totalBalance = 0; | 
			
		
	
		
			
				
					|  |  |  |     let totalValue = 0; | 
			
		
	
		
			
				
					|  |  |  |     let totalBalanceInBaseCurrency = new Big(0); | 
			
		
	
		
			
				
					|  |  |  |     let totalValueInBaseCurrency = new Big(0); | 
			
		
	
		
			
				
					|  |  |  |     let transactionCount = 0; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     for (const account of accounts) { | 
			
		
	
		
			
				
					|  |  |  |       totalBalance += account.convertedBalance; | 
			
		
	
		
			
				
					|  |  |  |       totalValue += account.value; | 
			
		
	
		
			
				
					|  |  |  |       totalBalanceInBaseCurrency = totalBalanceInBaseCurrency.plus( | 
			
		
	
		
			
				
					|  |  |  |         account.balanceInBaseCurrency | 
			
		
	
		
			
				
					|  |  |  |       ); | 
			
		
	
		
			
				
					|  |  |  |       totalValueInBaseCurrency = totalValueInBaseCurrency.plus( | 
			
		
	
		
			
				
					|  |  |  |         account.valueInBaseCurrency | 
			
		
	
		
			
				
					|  |  |  |       ); | 
			
		
	
		
			
				
					|  |  |  |       transactionCount += account.transactionCount; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     return { accounts, totalBalance, totalValue, transactionCount }; | 
			
		
	
		
			
				
					|  |  |  |     return { | 
			
		
	
		
			
				
					|  |  |  |       accounts, | 
			
		
	
		
			
				
					|  |  |  |       transactionCount, | 
			
		
	
		
			
				
					|  |  |  |       totalBalanceInBaseCurrency: totalBalanceInBaseCurrency.toNumber(), | 
			
		
	
		
			
				
					|  |  |  |       totalValueInBaseCurrency: totalValueInBaseCurrency.toNumber() | 
			
		
	
		
			
				
					|  |  |  |     }; | 
			
		
	
		
			
				
					|  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   public async getInvestments( | 
			
		
	
	
		
			
				
					|  |  | @ -281,13 +297,11 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  |       userId | 
			
		
	
		
			
				
					|  |  |  |     }); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     if (transactionPoints?.length <= 0) { | 
			
		
	
		
			
				
					|  |  |  |       return { accounts: {}, holdings: {}, hasErrors: false }; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     portfolioCalculator.setTransactionPoints(transactionPoints); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const portfolioStart = parseDate(transactionPoints[0].date); | 
			
		
	
		
			
				
					|  |  |  |     const portfolioStart = parseDate( | 
			
		
	
		
			
				
					|  |  |  |       transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT) | 
			
		
	
		
			
				
					|  |  |  |     ); | 
			
		
	
		
			
				
					|  |  |  |     const startDate = this.getStartDate(aDateRange, portfolioStart); | 
			
		
	
		
			
				
					|  |  |  |     const currentPositions = await portfolioCalculator.getCurrentPositions( | 
			
		
	
		
			
				
					|  |  |  |       startDate | 
			
		
	
	
		
			
				
					|  |  | @ -300,9 +314,11 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const holdings: PortfolioDetails['holdings'] = {}; | 
			
		
	
		
			
				
					|  |  |  |     const totalInvestment = currentPositions.totalInvestment.plus( | 
			
		
	
		
			
				
					|  |  |  |       cashDetails.balance | 
			
		
	
		
			
				
					|  |  |  |       cashDetails.balanceInBaseCurrency | 
			
		
	
		
			
				
					|  |  |  |     ); | 
			
		
	
		
			
				
					|  |  |  |     const totalValue = currentPositions.currentValue.plus( | 
			
		
	
		
			
				
					|  |  |  |       cashDetails.balanceInBaseCurrency | 
			
		
	
		
			
				
					|  |  |  |     ); | 
			
		
	
		
			
				
					|  |  |  |     const totalValue = currentPositions.currentValue.plus(cashDetails.balance); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const dataGatheringItems = currentPositions.positions.map((position) => { | 
			
		
	
		
			
				
					|  |  |  |       return { | 
			
		
	
	
		
			
				
					|  |  | @ -848,7 +864,7 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const performanceInformation = await this.getPerformance(aImpersonationId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const { balance } = await this.accountService.getCashDetails( | 
			
		
	
		
			
				
					|  |  |  |     const { balanceInBaseCurrency } = await this.accountService.getCashDetails( | 
			
		
	
		
			
				
					|  |  |  |       userId, | 
			
		
	
		
			
				
					|  |  |  |       userCurrency | 
			
		
	
		
			
				
					|  |  |  |     ); | 
			
		
	
	
		
			
				
					|  |  | @ -866,7 +882,7 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const committedFunds = new Big(totalBuy).minus(totalSell); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const netWorth = new Big(balance) | 
			
		
	
		
			
				
					|  |  |  |     const netWorth = new Big(balanceInBaseCurrency) | 
			
		
	
		
			
				
					|  |  |  |       .plus(performanceInformation.performance.currentValue) | 
			
		
	
		
			
				
					|  |  |  |       .plus(items) | 
			
		
	
		
			
				
					|  |  |  |       .toNumber(); | 
			
		
	
	
		
			
				
					|  |  | @ -882,7 +898,7 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  |       totalSell, | 
			
		
	
		
			
				
					|  |  |  |       annualizedPerformancePercent: | 
			
		
	
		
			
				
					|  |  |  |         performanceInformation.performance.annualizedPerformancePercent, | 
			
		
	
		
			
				
					|  |  |  |       cash: balance, | 
			
		
	
		
			
				
					|  |  |  |       cash: balanceInBaseCurrency, | 
			
		
	
		
			
				
					|  |  |  |       committedFunds: committedFunds.toNumber(), | 
			
		
	
		
			
				
					|  |  |  |       ordersCount: orders.filter((order) => { | 
			
		
	
		
			
				
					|  |  |  |         return order.type === 'BUY' || order.type === 'SELL'; | 
			
		
	
	
		
			
				
					|  |  | @ -1113,17 +1129,12 @@ export class PortfolioService { | 
			
		
	
		
			
				
					|  |  |  |         return accountId === account.id; | 
			
		
	
		
			
				
					|  |  |  |       }); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |       const convertedBalance = this.exchangeRateDataService.toCurrency( | 
			
		
	
		
			
				
					|  |  |  |         account.balance, | 
			
		
	
		
			
				
					|  |  |  |         account.currency, | 
			
		
	
		
			
				
					|  |  |  |         userCurrency | 
			
		
	
		
			
				
					|  |  |  |       ); | 
			
		
	
		
			
				
					|  |  |  |       accounts[account.id] = { | 
			
		
	
		
			
				
					|  |  |  |         balance: convertedBalance, | 
			
		
	
		
			
				
					|  |  |  |         balance: account.balance, | 
			
		
	
		
			
				
					|  |  |  |         currency: account.currency, | 
			
		
	
		
			
				
					|  |  |  |         current: convertedBalance, | 
			
		
	
		
			
				
					|  |  |  |         current: account.balance, | 
			
		
	
		
			
				
					|  |  |  |         name: account.name, | 
			
		
	
		
			
				
					|  |  |  |         original: convertedBalance | 
			
		
	
		
			
				
					|  |  |  |         original: account.balance | 
			
		
	
		
			
				
					|  |  |  |       }; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |       for (const order of ordersByAccount) { | 
			
		
	
	
		
			
				
					|  |  | 
 |