|
@ -50,13 +50,14 @@ import { |
|
|
UserSettings |
|
|
UserSettings |
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
import { TimelinePosition } from '@ghostfolio/common/models'; |
|
|
import { TimelinePosition } from '@ghostfolio/common/models'; |
|
|
import type { |
|
|
import { |
|
|
AccountWithValue, |
|
|
AccountWithValue, |
|
|
DateRange, |
|
|
DateRange, |
|
|
GroupBy, |
|
|
GroupBy, |
|
|
RequestWithUser, |
|
|
RequestWithUser, |
|
|
UserWithSettings |
|
|
UserWithSettings |
|
|
} from '@ghostfolio/common/types'; |
|
|
} from '@ghostfolio/common/types'; |
|
|
|
|
|
import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; |
|
|
|
|
|
|
|
|
import { Inject, Injectable } from '@nestjs/common'; |
|
|
import { Inject, Injectable } from '@nestjs/common'; |
|
|
import { REQUEST } from '@nestjs/core'; |
|
|
import { REQUEST } from '@nestjs/core'; |
|
@ -85,10 +86,7 @@ import { |
|
|
import { isEmpty } from 'lodash'; |
|
|
import { isEmpty } from 'lodash'; |
|
|
|
|
|
|
|
|
import { PortfolioCalculator } from './calculator/portfolio-calculator'; |
|
|
import { PortfolioCalculator } from './calculator/portfolio-calculator'; |
|
|
import { |
|
|
import { PortfolioCalculatorFactory } from './calculator/portfolio-calculator.factory'; |
|
|
PerformanceCalculationType, |
|
|
|
|
|
PortfolioCalculatorFactory |
|
|
|
|
|
} from './calculator/portfolio-calculator.factory'; |
|
|
|
|
|
import { PortfolioHoldingDetail } from './interfaces/portfolio-holding-detail.interface'; |
|
|
import { PortfolioHoldingDetail } from './interfaces/portfolio-holding-detail.interface'; |
|
|
import { RulesService } from './rules.service'; |
|
|
import { RulesService } from './rules.service'; |
|
|
|
|
|
|
|
@ -278,14 +276,16 @@ export class PortfolioService { |
|
|
savingsRate: number; |
|
|
savingsRate: number; |
|
|
}): Promise<PortfolioInvestments> { |
|
|
}): Promise<PortfolioInvestments> { |
|
|
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 { endDate, startDate } = getIntervalFromDateRange(dateRange); |
|
|
const { endDate, startDate } = getIntervalFromDateRange(dateRange); |
|
|
|
|
|
|
|
|
const { activities } = |
|
|
const { activities } = |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userCurrency, |
|
|
userCurrency: this.getUserCurrency() |
|
|
userId |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (activities.length === 0) { |
|
|
if (activities.length === 0) { |
|
@ -299,8 +299,8 @@ export class PortfolioService { |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: PerformanceCalculationType.ROAI, |
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
currency: this.request.user.Settings.settings.baseCurrency |
|
|
currency: userCurrency |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const { historicalData } = await portfolioCalculator.getSnapshot(); |
|
|
const { historicalData } = await portfolioCalculator.getSnapshot(); |
|
@ -376,7 +376,7 @@ export class PortfolioService { |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: PerformanceCalculationType.ROAI, |
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
currency: userCurrency |
|
|
currency: userCurrency |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -684,7 +684,7 @@ export class PortfolioService { |
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
activities, |
|
|
activities, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: PerformanceCalculationType.ROAI, |
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
currency: userCurrency |
|
|
currency: userCurrency |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -935,12 +935,13 @@ export class PortfolioService { |
|
|
})?.id; |
|
|
})?.id; |
|
|
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 user = await this.userService.user({ id: userId }); |
|
|
|
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
|
|
|
|
|
|
const { activities } = |
|
|
const { activities } = |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userCurrency, |
|
|
userCurrency: this.getUserCurrency() |
|
|
userId |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (activities.length === 0) { |
|
|
if (activities.length === 0) { |
|
@ -954,8 +955,8 @@ export class PortfolioService { |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: PerformanceCalculationType.ROAI, |
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
currency: this.request.user.Settings.settings.baseCurrency |
|
|
currency: userCurrency |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const portfolioSnapshot = await portfolioCalculator.getSnapshot(); |
|
|
const portfolioSnapshot = await portfolioCalculator.getSnapshot(); |
|
@ -1120,7 +1121,7 @@ export class PortfolioService { |
|
|
activities, |
|
|
activities, |
|
|
filters, |
|
|
filters, |
|
|
userId, |
|
|
userId, |
|
|
calculationType: PerformanceCalculationType.ROAI, |
|
|
calculationType: this.getUserPerformanceCalculationType(user), |
|
|
currency: userCurrency |
|
|
currency: userCurrency |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -2021,6 +2022,12 @@ export class PortfolioService { |
|
|
return impersonationUserId || aUserId; |
|
|
return impersonationUserId || aUserId; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getUserPerformanceCalculationType( |
|
|
|
|
|
aUser: UserWithSettings |
|
|
|
|
|
): PerformanceCalculationType { |
|
|
|
|
|
return aUser?.Settings?.settings.performanceCalculationType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async getValueOfAccountsAndPlatforms({ |
|
|
private async getValueOfAccountsAndPlatforms({ |
|
|
activities, |
|
|
activities, |
|
|
filters = [], |
|
|
filters = [], |
|
|