Refactor orders with activities (#3122)
This commit is contained in:
parent
d8bfb23f20
commit
6d2a897366
@ -348,7 +348,7 @@ export class PortfolioService {
|
|||||||
(user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
|
(user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
|
||||||
);
|
);
|
||||||
|
|
||||||
const { orders, portfolioOrders, transactionPoints } =
|
const { activities, portfolioOrders, transactionPoints } =
|
||||||
await this.getTransactionPoints({
|
await this.getTransactionPoints({
|
||||||
filters,
|
filters,
|
||||||
userId,
|
userId,
|
||||||
@ -582,8 +582,8 @@ export class PortfolioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { accounts, platforms } = await this.getValueOfAccountsAndPlatforms({
|
const { accounts, platforms } = await this.getValueOfAccountsAndPlatforms({
|
||||||
|
activities,
|
||||||
filters,
|
filters,
|
||||||
orders,
|
|
||||||
portfolioItemsNow,
|
portfolioItemsNow,
|
||||||
userCurrency,
|
userCurrency,
|
||||||
userId,
|
userId,
|
||||||
@ -1282,7 +1282,7 @@ export class PortfolioService {
|
|||||||
const user = await this.userService.user({ id: userId });
|
const user = await this.userService.user({ id: userId });
|
||||||
const userCurrency = this.getUserCurrency(user);
|
const userCurrency = this.getUserCurrency(user);
|
||||||
|
|
||||||
const { orders, portfolioOrders, transactionPoints } =
|
const { activities, portfolioOrders, transactionPoints } =
|
||||||
await this.getTransactionPoints({
|
await this.getTransactionPoints({
|
||||||
userId,
|
userId,
|
||||||
types: ['BUY', 'SELL']
|
types: ['BUY', 'SELL']
|
||||||
@ -1314,7 +1314,7 @@ export class PortfolioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { accounts } = await this.getValueOfAccountsAndPlatforms({
|
const { accounts } = await this.getValueOfAccountsAndPlatforms({
|
||||||
orders,
|
activities,
|
||||||
portfolioItemsNow,
|
portfolioItemsNow,
|
||||||
userCurrency,
|
userCurrency,
|
||||||
userId
|
userId
|
||||||
@ -1324,7 +1324,7 @@ export class PortfolioService {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
rules: {
|
rules: {
|
||||||
accountClusterRisk: isEmpty(orders)
|
accountClusterRisk: isEmpty(activities)
|
||||||
? undefined
|
? undefined
|
||||||
: await this.rulesService.evaluate(
|
: await this.rulesService.evaluate(
|
||||||
[
|
[
|
||||||
@ -1339,7 +1339,7 @@ export class PortfolioService {
|
|||||||
],
|
],
|
||||||
userSettings
|
userSettings
|
||||||
),
|
),
|
||||||
currencyClusterRisk: isEmpty(orders)
|
currencyClusterRisk: isEmpty(activities)
|
||||||
? undefined
|
? undefined
|
||||||
: await this.rulesService.evaluate(
|
: await this.rulesService.evaluate(
|
||||||
[
|
[
|
||||||
@ -1368,7 +1368,7 @@ export class PortfolioService {
|
|||||||
new FeeRatioInitialInvestment(
|
new FeeRatioInitialInvestment(
|
||||||
this.exchangeRateDataService,
|
this.exchangeRateDataService,
|
||||||
currentPositions.totalInvestment.toNumber(),
|
currentPositions.totalInvestment.toNumber(),
|
||||||
this.getFees({ userCurrency, activities: orders }).toNumber()
|
this.getFees({ activities, userCurrency }).toNumber()
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
userSettings
|
userSettings
|
||||||
@ -1953,8 +1953,8 @@ export class PortfolioService {
|
|||||||
userId: string;
|
userId: string;
|
||||||
withExcludedAccounts?: boolean;
|
withExcludedAccounts?: boolean;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
|
activities: Activity[];
|
||||||
transactionPoints: TransactionPoint[];
|
transactionPoints: TransactionPoint[];
|
||||||
orders: Activity[];
|
|
||||||
portfolioOrders: PortfolioOrder[];
|
portfolioOrders: PortfolioOrder[];
|
||||||
}> {
|
}> {
|
||||||
const userCurrency =
|
const userCurrency =
|
||||||
@ -1970,7 +1970,7 @@ export class PortfolioService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
return { transactionPoints: [], orders: [], portfolioOrders: [] };
|
return { activities: [], transactionPoints: [], portfolioOrders: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const portfolioOrders: PortfolioOrder[] = activities.map((order) => ({
|
const portfolioOrders: PortfolioOrder[] = activities.map((order) => ({
|
||||||
@ -1996,8 +1996,8 @@ export class PortfolioService {
|
|||||||
portfolioCalculator.computeTransactionPoints();
|
portfolioCalculator.computeTransactionPoints();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
activities,
|
||||||
portfolioOrders,
|
portfolioOrders,
|
||||||
orders: activities,
|
|
||||||
transactionPoints: portfolioCalculator.getTransactionPoints()
|
transactionPoints: portfolioCalculator.getTransactionPoints()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -2018,29 +2018,20 @@ export class PortfolioService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getValueOfAccountsAndPlatforms({
|
private async getValueOfAccountsAndPlatforms({
|
||||||
|
activities,
|
||||||
filters = [],
|
filters = [],
|
||||||
orders,
|
|
||||||
portfolioItemsNow,
|
portfolioItemsNow,
|
||||||
userCurrency,
|
userCurrency,
|
||||||
userId,
|
userId,
|
||||||
withExcludedAccounts = false
|
withExcludedAccounts = false
|
||||||
}: {
|
}: {
|
||||||
|
activities: Activity[];
|
||||||
filters?: Filter[];
|
filters?: Filter[];
|
||||||
orders: Activity[];
|
|
||||||
portfolioItemsNow: { [p: string]: TimelinePosition };
|
portfolioItemsNow: { [p: string]: TimelinePosition };
|
||||||
userCurrency: string;
|
userCurrency: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
withExcludedAccounts?: boolean;
|
withExcludedAccounts?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { activities: ordersOfTypeItemOrLiability } =
|
|
||||||
await this.orderService.getOrders({
|
|
||||||
filters,
|
|
||||||
userCurrency,
|
|
||||||
userId,
|
|
||||||
withExcludedAccounts,
|
|
||||||
types: ['LIABILITY']
|
|
||||||
});
|
|
||||||
|
|
||||||
const accounts: PortfolioDetails['accounts'] = {};
|
const accounts: PortfolioDetails['accounts'] = {};
|
||||||
const platforms: PortfolioDetails['platforms'] = {};
|
const platforms: PortfolioDetails['platforms'] = {};
|
||||||
|
|
||||||
@ -2058,7 +2049,7 @@ export class PortfolioService {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const accountIds = uniq(
|
const accountIds = uniq(
|
||||||
orders
|
activities
|
||||||
.filter(({ accountId }) => {
|
.filter(({ accountId }) => {
|
||||||
return accountId;
|
return accountId;
|
||||||
})
|
})
|
||||||
@ -2078,7 +2069,7 @@ export class PortfolioService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const account of currentAccounts) {
|
for (const account of currentAccounts) {
|
||||||
const ordersByAccount = orders.filter(({ accountId }) => {
|
const ordersByAccount = activities.filter(({ accountId }) => {
|
||||||
return accountId === account.id;
|
return accountId === account.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user