|
@ -26,6 +26,7 @@ import { |
|
|
Accounts, |
|
|
Accounts, |
|
|
PortfolioDetails, |
|
|
PortfolioDetails, |
|
|
PortfolioPerformanceResponse, |
|
|
PortfolioPerformanceResponse, |
|
|
|
|
|
PortfolioPosition, |
|
|
PortfolioReport, |
|
|
PortfolioReport, |
|
|
PortfolioSummary, |
|
|
PortfolioSummary, |
|
|
Position, |
|
|
Position, |
|
@ -297,6 +298,10 @@ export class PortfolioServiceNew { |
|
|
): Promise<PortfolioDetails & { hasErrors: boolean }> { |
|
|
): Promise<PortfolioDetails & { hasErrors: boolean }> { |
|
|
const userId = await this.getUserId(aImpersonationId, aUserId); |
|
|
const userId = await this.getUserId(aImpersonationId, aUserId); |
|
|
|
|
|
|
|
|
|
|
|
const emergencyFund = new Big( |
|
|
|
|
|
(this.request.user?.Settings?.settings as UserSettings)?.emergencyFund ?? |
|
|
|
|
|
0 |
|
|
|
|
|
); |
|
|
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency; |
|
|
const userCurrency = this.request.user?.Settings?.currency ?? baseCurrency; |
|
|
|
|
|
|
|
|
const { orders, portfolioOrders, transactionPoints } = |
|
|
const { orders, portfolioOrders, transactionPoints } = |
|
@ -394,6 +399,7 @@ export class PortfolioServiceNew { |
|
|
|
|
|
|
|
|
const cashPositions = await this.getCashPositions({ |
|
|
const cashPositions = await this.getCashPositions({ |
|
|
cashDetails, |
|
|
cashDetails, |
|
|
|
|
|
emergencyFund, |
|
|
userCurrency, |
|
|
userCurrency, |
|
|
investment: totalInvestment, |
|
|
investment: totalInvestment, |
|
|
value: totalValue |
|
|
value: totalValue |
|
@ -897,7 +903,7 @@ export class PortfolioServiceNew { |
|
|
}); |
|
|
}); |
|
|
const dividend = this.getDividend(orders).toNumber(); |
|
|
const dividend = this.getDividend(orders).toNumber(); |
|
|
const emergencyFund = |
|
|
const emergencyFund = |
|
|
(this.request.user?.Settings?.settings as UserSettings).emergencyFund ?? |
|
|
(this.request.user?.Settings?.settings as UserSettings)?.emergencyFund ?? |
|
|
0; |
|
|
0; |
|
|
const fees = this.getFees(orders).toNumber(); |
|
|
const fees = this.getFees(orders).toNumber(); |
|
|
const firstOrderDate = orders[0]?.date; |
|
|
const firstOrderDate = orders[0]?.date; |
|
@ -950,16 +956,20 @@ export class PortfolioServiceNew { |
|
|
|
|
|
|
|
|
private async getCashPositions({ |
|
|
private async getCashPositions({ |
|
|
cashDetails, |
|
|
cashDetails, |
|
|
|
|
|
emergencyFund, |
|
|
investment, |
|
|
investment, |
|
|
userCurrency, |
|
|
userCurrency, |
|
|
value |
|
|
value |
|
|
}: { |
|
|
}: { |
|
|
cashDetails: CashDetails; |
|
|
cashDetails: CashDetails; |
|
|
|
|
|
emergencyFund: Big; |
|
|
investment: Big; |
|
|
investment: Big; |
|
|
value: Big; |
|
|
value: Big; |
|
|
userCurrency: string; |
|
|
userCurrency: string; |
|
|
}) { |
|
|
}) { |
|
|
const cashPositions = {}; |
|
|
const cashPositions: { |
|
|
|
|
|
[symbol: string]: Partial<PortfolioPosition>; |
|
|
|
|
|
} = {}; |
|
|
|
|
|
|
|
|
for (const account of cashDetails.accounts) { |
|
|
for (const account of cashDetails.accounts) { |
|
|
const convertedBalance = this.exchangeRateDataService.toCurrency( |
|
|
const convertedBalance = this.exchangeRateDataService.toCurrency( |
|
@ -1000,6 +1010,25 @@ export class PortfolioServiceNew { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cashPositions['EMERGENCY_FUND'] = { |
|
|
|
|
|
...cashPositions[userCurrency], |
|
|
|
|
|
assetSubClass: 'EMERGENCY_FUND', |
|
|
|
|
|
investment: emergencyFund.toNumber(), |
|
|
|
|
|
name: 'EMERGENCY_FUND', |
|
|
|
|
|
symbol: 'EMERGENCY_FUND', |
|
|
|
|
|
value: emergencyFund.toNumber() |
|
|
|
|
|
}; |
|
|
|
|
|
cashPositions[userCurrency].investment = new Big( |
|
|
|
|
|
cashPositions[userCurrency].investment |
|
|
|
|
|
) |
|
|
|
|
|
.minus(emergencyFund) |
|
|
|
|
|
.toNumber(); |
|
|
|
|
|
cashPositions[userCurrency].value = new Big( |
|
|
|
|
|
cashPositions[userCurrency].value |
|
|
|
|
|
) |
|
|
|
|
|
.minus(emergencyFund) |
|
|
|
|
|
.toNumber(); |
|
|
|
|
|
|
|
|
for (const symbol of Object.keys(cashPositions)) { |
|
|
for (const symbol of Object.keys(cashPositions)) { |
|
|
// Calculate allocations for each currency
|
|
|
// Calculate allocations for each currency
|
|
|
cashPositions[symbol].allocationCurrent = new Big( |
|
|
cashPositions[symbol].allocationCurrent = new Big( |
|
|