|
|
@ -119,7 +119,7 @@ export class PortfolioService {
|
|
|
|
userId: string;
|
|
|
|
userId: string;
|
|
|
|
withExcludedAccounts?: boolean;
|
|
|
|
withExcludedAccounts?: boolean;
|
|
|
|
}): Promise<AccountWithValue[]> {
|
|
|
|
}): Promise<AccountWithValue[]> {
|
|
|
|
const where: Prisma.AccountWhereInput = { userId: userId };
|
|
|
|
const where: Prisma.AccountWhereInput = { userId };
|
|
|
|
|
|
|
|
|
|
|
|
const accountFilter = filters?.find(({ type }) => {
|
|
|
|
const accountFilter = filters?.find(({ type }) => {
|
|
|
|
return type === 'ACCOUNT';
|
|
|
|
return type === 'ACCOUNT';
|
|
|
@ -227,18 +227,24 @@ export class PortfolioService {
|
|
|
|
impersonationId: string;
|
|
|
|
impersonationId: string;
|
|
|
|
}): Promise<InvestmentItem[]> {
|
|
|
|
}): Promise<InvestmentItem[]> {
|
|
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id);
|
|
|
|
const userId = await this.getUserId(impersonationId, this.request.user.id);
|
|
|
|
|
|
|
|
const user = await this.userService.user({ id: userId });
|
|
|
|
|
|
|
|
const userCurrency = this.getUserCurrency(user);
|
|
|
|
|
|
|
|
|
|
|
|
const { activities } = await this.orderService.getOrders({
|
|
|
|
const { activities } = await this.orderService.getOrders({
|
|
|
|
filters,
|
|
|
|
filters,
|
|
|
|
|
|
|
|
userCurrency,
|
|
|
|
userId,
|
|
|
|
userId,
|
|
|
|
types: ['DIVIDEND'],
|
|
|
|
types: ['DIVIDEND']
|
|
|
|
userCurrency: this.request.user.Settings.settings.baseCurrency
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let dividends = activities.map((dividend) => {
|
|
|
|
let dividends = activities.map(({ date, SymbolProfile, value }) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
date: format(dividend.date, DATE_FORMAT),
|
|
|
|
date: format(date, DATE_FORMAT),
|
|
|
|
investment: dividend.valueInBaseCurrency
|
|
|
|
investment: this.exchangeRateDataService.toCurrency(
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
SymbolProfile.currency,
|
|
|
|
|
|
|
|
userCurrency
|
|
|
|
|
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -762,8 +768,14 @@ export class PortfolioService {
|
|
|
|
.filter(({ type }) => {
|
|
|
|
.filter(({ type }) => {
|
|
|
|
return type === 'DIVIDEND';
|
|
|
|
return type === 'DIVIDEND';
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.map(({ valueInBaseCurrency }) => {
|
|
|
|
.map(({ SymbolProfile, value }) => {
|
|
|
|
return new Big(valueInBaseCurrency);
|
|
|
|
return new Big(
|
|
|
|
|
|
|
|
this.exchangeRateDataService.toCurrency(
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
SymbolProfile.currency,
|
|
|
|
|
|
|
|
userCurrency
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -1992,7 +2004,7 @@ export class PortfolioService {
|
|
|
|
withExcludedAccounts = false
|
|
|
|
withExcludedAccounts = false
|
|
|
|
}: {
|
|
|
|
}: {
|
|
|
|
filters?: Filter[];
|
|
|
|
filters?: Filter[];
|
|
|
|
orders: OrderWithAccount[];
|
|
|
|
orders: Activity[];
|
|
|
|
portfolioItemsNow: { [p: string]: TimelinePosition };
|
|
|
|
portfolioItemsNow: { [p: string]: TimelinePosition };
|
|
|
|
userCurrency: string;
|
|
|
|
userCurrency: string;
|
|
|
|
userId: string;
|
|
|
|
userId: string;
|
|
|
@ -2088,41 +2100,50 @@ export class PortfolioService {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const order of ordersByAccount) {
|
|
|
|
for (const {
|
|
|
|
|
|
|
|
Account,
|
|
|
|
|
|
|
|
quantity,
|
|
|
|
|
|
|
|
SymbolProfile,
|
|
|
|
|
|
|
|
type,
|
|
|
|
|
|
|
|
unitPrice
|
|
|
|
|
|
|
|
} of ordersByAccount) {
|
|
|
|
|
|
|
|
const unitPriceInBaseCurrency =
|
|
|
|
|
|
|
|
portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ??
|
|
|
|
|
|
|
|
this.exchangeRateDataService.toCurrency(
|
|
|
|
|
|
|
|
unitPrice,
|
|
|
|
|
|
|
|
SymbolProfile.currency,
|
|
|
|
|
|
|
|
userCurrency
|
|
|
|
|
|
|
|
) ??
|
|
|
|
|
|
|
|
0;
|
|
|
|
|
|
|
|
|
|
|
|
let currentValueOfSymbolInBaseCurrency =
|
|
|
|
let currentValueOfSymbolInBaseCurrency =
|
|
|
|
order.quantity *
|
|
|
|
quantity * unitPriceInBaseCurrency;
|
|
|
|
(portfolioItemsNow[order.SymbolProfile.symbol]
|
|
|
|
|
|
|
|
?.marketPriceInBaseCurrency ??
|
|
|
|
|
|
|
|
order.unitPrice ??
|
|
|
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (order.type === 'LIABILITY' || order.type === 'SELL') {
|
|
|
|
if (type === 'LIABILITY' || type === 'SELL') {
|
|
|
|
currentValueOfSymbolInBaseCurrency *= -1;
|
|
|
|
currentValueOfSymbolInBaseCurrency *= -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (accounts[order.Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
|
|
|
|
if (accounts[Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
|
|
|
|
accounts[order.Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
|
|
|
|
accounts[Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
|
|
|
|
currentValueOfSymbolInBaseCurrency;
|
|
|
|
currentValueOfSymbolInBaseCurrency;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
accounts[order.Account?.id || UNKNOWN_KEY] = {
|
|
|
|
accounts[Account?.id || UNKNOWN_KEY] = {
|
|
|
|
balance: 0,
|
|
|
|
balance: 0,
|
|
|
|
currency: order.Account?.currency,
|
|
|
|
currency: Account?.currency,
|
|
|
|
name: account.name,
|
|
|
|
name: account.name,
|
|
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
|
|
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
platforms[order.Account?.Platform?.id || UNKNOWN_KEY]
|
|
|
|
platforms[Account?.Platform?.id || UNKNOWN_KEY]?.valueInBaseCurrency
|
|
|
|
?.valueInBaseCurrency
|
|
|
|
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
platforms[
|
|
|
|
platforms[Account?.Platform?.id || UNKNOWN_KEY].valueInBaseCurrency +=
|
|
|
|
order.Account?.Platform?.id || UNKNOWN_KEY
|
|
|
|
currentValueOfSymbolInBaseCurrency;
|
|
|
|
].valueInBaseCurrency += currentValueOfSymbolInBaseCurrency;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
platforms[order.Account?.Platform?.id || UNKNOWN_KEY] = {
|
|
|
|
platforms[Account?.Platform?.id || UNKNOWN_KEY] = {
|
|
|
|
balance: 0,
|
|
|
|
balance: 0,
|
|
|
|
currency: order.Account?.currency,
|
|
|
|
currency: Account?.currency,
|
|
|
|
name: account.Platform?.name,
|
|
|
|
name: account.Platform?.name,
|
|
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
|
|
|
|
valueInBaseCurrency: currentValueOfSymbolInBaseCurrency
|
|
|
|
};
|
|
|
|
};
|
|
|
|