|
|
@ -323,8 +323,6 @@ export class PortfolioService { |
|
|
|
withMarkets?: boolean; |
|
|
|
withSummary?: boolean; |
|
|
|
}): Promise<PortfolioDetails & { hasErrors: boolean }> { |
|
|
|
console.time('-- PortfolioService.getDetails - 1'); |
|
|
|
|
|
|
|
userId = await this.getUserId(impersonationId, userId); |
|
|
|
const user = await this.userService.user({ id: userId }); |
|
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
@ -351,16 +349,9 @@ export class PortfolioService { |
|
|
|
this.request.user?.Settings.settings.isExperimentalFeatures |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 1'); |
|
|
|
|
|
|
|
console.time('-- PortfolioService.getDetails - 2'); |
|
|
|
|
|
|
|
const { currentValueInBaseCurrency, hasErrors, positions } = |
|
|
|
await portfolioCalculator.getSnapshot(); |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 2'); |
|
|
|
console.time('-- PortfolioService.getDetails - 3'); |
|
|
|
|
|
|
|
const cashDetails = await this.accountService.getCashDetails({ |
|
|
|
filters, |
|
|
|
userId, |
|
|
@ -409,9 +400,6 @@ export class PortfolioService { |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 3'); |
|
|
|
console.time('-- PortfolioService.getDetails - 4'); |
|
|
|
|
|
|
|
const symbolProfiles = |
|
|
|
await this.symbolProfileService.getSymbolProfiles(dataGatheringItems); |
|
|
|
|
|
|
@ -425,9 +413,6 @@ export class PortfolioService { |
|
|
|
portfolioItemsNow[position.symbol] = position; |
|
|
|
} |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 4'); |
|
|
|
console.time('-- PortfolioService.getDetails - 5'); |
|
|
|
|
|
|
|
for (const { |
|
|
|
currency, |
|
|
|
dividend, |
|
|
@ -581,10 +566,6 @@ export class PortfolioService { |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 5'); |
|
|
|
|
|
|
|
console.time('-- PortfolioService.getDetails - 6'); |
|
|
|
|
|
|
|
let summary: PortfolioSummary; |
|
|
|
|
|
|
|
if (withSummary) { |
|
|
@ -603,8 +584,6 @@ export class PortfolioService { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
console.timeEnd('-- PortfolioService.getDetails - 6'); |
|
|
|
|
|
|
|
return { |
|
|
|
accounts, |
|
|
|
hasErrors, |
|
|
@ -1078,9 +1057,6 @@ export class PortfolioService { |
|
|
|
userId: string; |
|
|
|
withExcludedAccounts?: boolean; |
|
|
|
}): Promise<PortfolioPerformanceResponse> { |
|
|
|
// OPTIMIZE (1.34s)
|
|
|
|
console.time('------ PortfolioService.getPerformance'); |
|
|
|
|
|
|
|
userId = await this.getUserId(impersonationId, userId); |
|
|
|
const user = await this.userService.user({ id: userId }); |
|
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
@ -1117,8 +1093,6 @@ export class PortfolioService { |
|
|
|
|
|
|
|
const { endDate, startDate } = getIntervalFromDateRange(dateRange); |
|
|
|
|
|
|
|
console.time('------- PortfolioService.getPerformance - 2'); |
|
|
|
|
|
|
|
const { activities } = await this.orderService.getOrders({ |
|
|
|
endDate, |
|
|
|
filters, |
|
|
@ -1127,9 +1101,6 @@ export class PortfolioService { |
|
|
|
withExcludedAccounts |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd('------- PortfolioService.getPerformance - 2'); |
|
|
|
console.time('------- PortfolioService.getPerformance - 3'); |
|
|
|
|
|
|
|
if (accountBalanceItems?.length <= 0 && activities?.length <= 0) { |
|
|
|
return { |
|
|
|
chart: [], |
|
|
@ -1168,16 +1139,6 @@ export class PortfolioService { |
|
|
|
const { errors, hasErrors, historicalData } = |
|
|
|
await portfolioCalculator.getSnapshot(); |
|
|
|
|
|
|
|
console.timeEnd('------- PortfolioService.getPerformance - 3'); |
|
|
|
console.time('------- PortfolioService.getPerformance - 4'); |
|
|
|
|
|
|
|
console.timeEnd('------- PortfolioService.getPerformance - 4'); |
|
|
|
console.time('------- PortfolioService.getPerformance - 5'); |
|
|
|
|
|
|
|
console.timeEnd('------- PortfolioService.getPerformance - 5'); |
|
|
|
|
|
|
|
console.timeEnd('------ PortfolioService.getPerformance'); |
|
|
|
|
|
|
|
const { chart } = await portfolioCalculator.getPerformance({ |
|
|
|
end: endDate, |
|
|
|
start: startDate |
|
|
@ -1624,23 +1585,15 @@ export class PortfolioService { |
|
|
|
userCurrency: string; |
|
|
|
userId: string; |
|
|
|
}): Promise<PortfolioSummary> { |
|
|
|
// OPTIMIZE (1.1 s)
|
|
|
|
console.time('---- PortfolioService.getSummary'); |
|
|
|
|
|
|
|
userId = await this.getUserId(impersonationId, userId); |
|
|
|
const user = await this.userService.user({ id: userId }); |
|
|
|
|
|
|
|
console.time('----- PortfolioService.getSummary - 1'); |
|
|
|
|
|
|
|
const { activities } = await this.orderService.getOrders({ |
|
|
|
userCurrency, |
|
|
|
userId, |
|
|
|
withExcludedAccounts: true |
|
|
|
}); |
|
|
|
|
|
|
|
console.timeEnd('----- PortfolioService.getSummary - 1'); |
|
|
|
console.time('----- PortfolioService.getSummary - 2'); |
|
|
|
|
|
|
|
const excludedActivities: Activity[] = []; |
|
|
|
const nonExcludedActivities: Activity[] = []; |
|
|
|
|
|
|
@ -1681,9 +1634,6 @@ export class PortfolioService { |
|
|
|
|
|
|
|
const interest = await portfolioCalculator.getInterestInBaseCurrency(); |
|
|
|
|
|
|
|
console.timeEnd('----- PortfolioService.getSummary - 2'); |
|
|
|
console.time('----- PortfolioService.getSummary - 3'); |
|
|
|
|
|
|
|
const liabilities = |
|
|
|
await portfolioCalculator.getLiabilitiesInBaseCurrency(); |
|
|
|
|
|
|
@ -1720,9 +1670,6 @@ export class PortfolioService { |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
console.timeEnd('----- PortfolioService.getSummary - 3'); |
|
|
|
console.time('----- PortfolioService.getSummary - 4'); |
|
|
|
|
|
|
|
const cashDetailsWithExcludedAccounts = |
|
|
|
await this.accountService.getCashDetails({ |
|
|
|
userId, |
|
|
@ -1760,10 +1707,6 @@ export class PortfolioService { |
|
|
|
) |
|
|
|
})?.toNumber(); |
|
|
|
|
|
|
|
console.timeEnd('----- PortfolioService.getSummary - 4'); |
|
|
|
|
|
|
|
console.timeEnd('---- PortfolioService.getSummary'); |
|
|
|
|
|
|
|
return { |
|
|
|
annualizedPerformancePercent, |
|
|
|
annualizedPerformancePercentWithCurrencyEffect, |
|
|
|