|  | @ -1,4 +1,6 @@ | 
			
		
	
		
		
			
				
					
					|  |  | import { UNKNOWN_KEY } from '@ghostfolio/common/config'; |  |  | import { AccountService } from '@ghostfolio/api/app/account/account.service'; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface'; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import { UNKNOWN_KEY, ghostfolioCashSymbol } from '@ghostfolio/common/config'; | 
			
		
	
		
		
			
				
					|  |  | import { getToday, getYesterday, resetHours } from '@ghostfolio/common/helper'; |  |  | import { getToday, getYesterday, resetHours } from '@ghostfolio/common/helper'; | 
			
		
	
		
		
			
				
					|  |  | import { |  |  | import { | 
			
		
	
		
		
			
				
					|  |  |   PortfolioItem, |  |  |   PortfolioItem, | 
			
		
	
	
		
		
			
				
					|  | @ -11,7 +13,7 @@ import { | 
			
		
	
		
		
			
				
					|  |  | import { Country } from '@ghostfolio/common/interfaces/country.interface'; |  |  | import { Country } from '@ghostfolio/common/interfaces/country.interface'; | 
			
		
	
		
		
			
				
					|  |  | import { Sector } from '@ghostfolio/common/interfaces/sector.interface'; |  |  | import { Sector } from '@ghostfolio/common/interfaces/sector.interface'; | 
			
		
	
		
		
			
				
					|  |  | import { DateRange, OrderWithAccount } from '@ghostfolio/common/types'; |  |  | import { DateRange, OrderWithAccount } from '@ghostfolio/common/types'; | 
			
		
	
		
		
			
				
					
					|  |  | import { Prisma } from '@prisma/client'; |  |  | import { Currency, Prisma } from '@prisma/client'; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | import { continents, countries } from 'countries-list'; |  |  | import { continents, countries } from 'countries-list'; | 
			
		
	
		
		
			
				
					|  |  | import { |  |  | import { | 
			
		
	
		
		
			
				
					|  |  |   add, |  |  |   add, | 
			
		
	
	
		
		
			
				
					|  | @ -34,7 +36,7 @@ import * as roundTo from 'round-to'; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | import { DataProviderService } from '../services/data-provider.service'; |  |  | import { DataProviderService } from '../services/data-provider.service'; | 
			
		
	
		
		
			
				
					|  |  | import { ExchangeRateDataService } from '../services/exchange-rate-data.service'; |  |  | import { ExchangeRateDataService } from '../services/exchange-rate-data.service'; | 
			
		
	
		
		
			
				
					
					|  |  | import { IOrder } from '../services/interfaces/interfaces'; |  |  | import { IOrder, MarketState, Type } from '../services/interfaces/interfaces'; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | import { RulesService } from '../services/rules.service'; |  |  | import { RulesService } from '../services/rules.service'; | 
			
		
	
		
		
			
				
					|  |  | import { PortfolioInterface } from './interfaces/portfolio.interface'; |  |  | import { PortfolioInterface } from './interfaces/portfolio.interface'; | 
			
		
	
		
		
			
				
					|  |  | import { Order } from './order'; |  |  | import { Order } from './order'; | 
			
		
	
	
		
		
			
				
					|  | @ -54,6 +56,7 @@ export class Portfolio implements PortfolioInterface { | 
			
		
	
		
		
			
				
					|  |  |   private user: UserWithSettings; |  |  |   private user: UserWithSettings; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |   public constructor( |  |  |   public constructor( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private accountService: AccountService, | 
			
		
	
		
		
			
				
					|  |  |     private dataProviderService: DataProviderService, |  |  |     private dataProviderService: DataProviderService, | 
			
		
	
		
		
			
				
					|  |  |     private exchangeRateDataService: ExchangeRateDataService, |  |  |     private exchangeRateDataService: ExchangeRateDataService, | 
			
		
	
		
		
			
				
					|  |  |     private rulesService: RulesService |  |  |     private rulesService: RulesService | 
			
		
	
	
		
		
			
				
					|  | @ -232,10 +235,14 @@ export class Portfolio implements PortfolioInterface { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const [portfolioItemsNow] = await this.get(new Date()); |  |  |     const [portfolioItemsNow] = await this.get(new Date()); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     const investment = this.getInvestment(new Date()); |  |  |     const cashDetails = await this.accountService.getCashDetails( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |       this.user.id, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       this.user.Settings.currency | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     ); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     const investment = this.getInvestment(new Date()) + cashDetails.balance; | 
			
		
	
		
		
			
				
					|  |  |     const portfolioItems = this.get(new Date()); |  |  |     const portfolioItems = this.get(new Date()); | 
			
		
	
		
		
			
				
					|  |  |     const symbols = this.getSymbols(new Date()); |  |  |     const symbols = this.getSymbols(new Date()); | 
			
		
	
		
		
			
				
					
					|  |  |     const value = this.getValue(); |  |  |     const value = this.getValue() + cashDetails.balance; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     const details: { [symbol: string]: PortfolioPosition } = {}; |  |  |     const details: { [symbol: string]: PortfolioPosition } = {}; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -372,6 +379,12 @@ export class Portfolio implements PortfolioInterface { | 
			
		
	
		
		
			
				
					|  |  |       }; |  |  |       }; | 
			
		
	
		
		
			
				
					|  |  |     }); |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     details[ghostfolioCashSymbol] = await this.getCashPosition({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       cashDetails, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       investment, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       value | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     return details; |  |  |     return details; | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |   } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -644,6 +657,46 @@ export class Portfolio implements PortfolioInterface { | 
			
		
	
		
		
			
				
					|  |  |     return this; |  |  |     return this; | 
			
		
	
		
		
			
				
					|  |  |   } |  |  |   } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   private async getCashPosition({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     cashDetails, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     investment, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     value | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }: { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     cashDetails: CashDetails; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     investment: number; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     value: number; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   }) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     const accounts = {}; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     const cashValue = cashDetails.balance; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     cashDetails.accounts.forEach((account) => { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       accounts[account.name] = { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         current: account.balance, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         original: account.balance | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       }; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     return { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       accounts, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       allocationCurrent: cashValue / value, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       allocationInvestment: cashValue / investment, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       countries: [], | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       currency: Currency.CHF, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       grossPerformance: 0, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       grossPerformancePercent: 0, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       investment: cashValue, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       marketPrice: 0, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       marketState: MarketState.open, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       name: Type.Cash, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       quantity: 0, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       sectors: [], | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       symbol: ghostfolioCashSymbol, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       type: Type.Cash, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       transactionCount: 0, | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       value: cashValue | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     }; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |   /** |  |  |   /** | 
			
		
	
		
		
			
				
					|  |  |    * TODO: Refactor |  |  |    * TODO: Refactor | 
			
		
	
		
		
			
				
					|  |  |    */ |  |  |    */ | 
			
		
	
	
		
		
			
				
					|  | 
 |