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