|
|
@ -37,6 +37,7 @@ import {
|
|
|
|
} from '@ghostfolio/common/interfaces';
|
|
|
|
} from '@ghostfolio/common/interfaces';
|
|
|
|
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface';
|
|
|
|
import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface';
|
|
|
|
import type {
|
|
|
|
import type {
|
|
|
|
|
|
|
|
AccountWithValue,
|
|
|
|
DateRange,
|
|
|
|
DateRange,
|
|
|
|
OrderWithAccount,
|
|
|
|
OrderWithAccount,
|
|
|
|
RequestWithUser
|
|
|
|
RequestWithUser
|
|
|
@ -79,6 +80,36 @@ export class PortfolioService {
|
|
|
|
private readonly symbolProfileService: SymbolProfileService
|
|
|
|
private readonly symbolProfileService: SymbolProfileService
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async getAccounts(aUserId: string): Promise<AccountWithValue[]> {
|
|
|
|
|
|
|
|
const [accounts, details] = await Promise.all([
|
|
|
|
|
|
|
|
this.accountService.accounts({
|
|
|
|
|
|
|
|
include: { Order: true, Platform: true },
|
|
|
|
|
|
|
|
orderBy: { name: 'asc' },
|
|
|
|
|
|
|
|
where: { userId: aUserId }
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
this.getDetails(aUserId, aUserId)
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const userCurrency = this.request.user.Settings.currency;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return accounts.map((account) => {
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
|
|
|
|
...account,
|
|
|
|
|
|
|
|
convertedBalance: this.exchangeRateDataService.toCurrency(
|
|
|
|
|
|
|
|
account.balance,
|
|
|
|
|
|
|
|
account.currency,
|
|
|
|
|
|
|
|
userCurrency
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
transactionCount: account.Order.length,
|
|
|
|
|
|
|
|
value: details.accounts[account.name].current
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete result.Order;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async getInvestments(
|
|
|
|
public async getInvestments(
|
|
|
|
aImpersonationId: string
|
|
|
|
aImpersonationId: string
|
|
|
|
): Promise<InvestmentItem[]> {
|
|
|
|
): Promise<InvestmentItem[]> {
|
|
|
@ -256,7 +287,7 @@ export class PortfolioService {
|
|
|
|
value: totalValue
|
|
|
|
value: totalValue
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const accounts = await this.getAccounts(
|
|
|
|
const accounts = await this.getValueOfAccounts(
|
|
|
|
orders,
|
|
|
|
orders,
|
|
|
|
portfolioItemsNow,
|
|
|
|
portfolioItemsNow,
|
|
|
|
userCurrency,
|
|
|
|
userCurrency,
|
|
|
@ -617,7 +648,7 @@ export class PortfolioService {
|
|
|
|
currentGrossPerformancePercent,
|
|
|
|
currentGrossPerformancePercent,
|
|
|
|
currentNetPerformance,
|
|
|
|
currentNetPerformance,
|
|
|
|
currentNetPerformancePercent,
|
|
|
|
currentNetPerformancePercent,
|
|
|
|
currentValue: currentValue
|
|
|
|
currentValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -667,7 +698,7 @@ export class PortfolioService {
|
|
|
|
for (const position of currentPositions.positions) {
|
|
|
|
for (const position of currentPositions.positions) {
|
|
|
|
portfolioItemsNow[position.symbol] = position;
|
|
|
|
portfolioItemsNow[position.symbol] = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const accounts = await this.getAccounts(
|
|
|
|
const accounts = await this.getValueOfAccounts(
|
|
|
|
orders,
|
|
|
|
orders,
|
|
|
|
portfolioItemsNow,
|
|
|
|
portfolioItemsNow,
|
|
|
|
currency,
|
|
|
|
currency,
|
|
|
@ -867,7 +898,7 @@ export class PortfolioService {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async getAccounts(
|
|
|
|
private async getValueOfAccounts(
|
|
|
|
orders: OrderWithAccount[],
|
|
|
|
orders: OrderWithAccount[],
|
|
|
|
portfolioItemsNow: { [p: string]: TimelinePosition },
|
|
|
|
portfolioItemsNow: { [p: string]: TimelinePosition },
|
|
|
|
userCurrency: string,
|
|
|
|
userCurrency: string,
|
|
|
@ -882,20 +913,15 @@ export class PortfolioService {
|
|
|
|
return accountId === account.id;
|
|
|
|
return accountId === account.id;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (ordersByAccount.length <= 0) {
|
|
|
|
const convertedBalance = this.exchangeRateDataService.toCurrency(
|
|
|
|
// Add account without orders
|
|
|
|
account.balance,
|
|
|
|
const balance = this.exchangeRateDataService.toCurrency(
|
|
|
|
account.currency,
|
|
|
|
account.balance,
|
|
|
|
userCurrency
|
|
|
|
account.currency,
|
|
|
|
);
|
|
|
|
userCurrency
|
|
|
|
accounts[account.name] = {
|
|
|
|
);
|
|
|
|
current: convertedBalance,
|
|
|
|
accounts[account.name] = {
|
|
|
|
original: convertedBalance
|
|
|
|
current: balance,
|
|
|
|
};
|
|
|
|
original: balance
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const order of ordersByAccount) {
|
|
|
|
for (const order of ordersByAccount) {
|
|
|
|
let currentValueOfSymbol = this.exchangeRateDataService.toCurrency(
|
|
|
|
let currentValueOfSymbol = this.exchangeRateDataService.toCurrency(
|
|
|
|