|
|
@ -1,3 +1,8 @@ |
|
|
|
import { OrderService } from '@ghostfolio/api/app/order/order.service'; |
|
|
|
import { |
|
|
|
PerformanceCalculationType, |
|
|
|
PortfolioCalculatorFactory |
|
|
|
} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator.factory'; |
|
|
|
import { PortfolioSnapshotValue } from '@ghostfolio/api/app/portfolio/interfaces/snapshot-value.interface'; |
|
|
|
import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; |
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
@ -6,11 +11,9 @@ import { |
|
|
|
PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME, |
|
|
|
PORTFOLIO_SNAPSHOT_QUEUE |
|
|
|
} from '@ghostfolio/common/config'; |
|
|
|
import { PortfolioSnapshot } from '@ghostfolio/common/models'; |
|
|
|
|
|
|
|
import { Process, Processor } from '@nestjs/bull'; |
|
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
|
import * as Big from 'big.js'; |
|
|
|
import { Job } from 'bull'; |
|
|
|
import { addMilliseconds } from 'date-fns'; |
|
|
|
|
|
|
@ -20,7 +23,9 @@ import { IPortfolioSnapshotQueueJob } from './interfaces/portfolio-snapshot-queu |
|
|
|
@Processor(PORTFOLIO_SNAPSHOT_QUEUE) |
|
|
|
export class PortfolioSnapshotProcessor { |
|
|
|
public constructor( |
|
|
|
private readonly calculatorFactory: PortfolioCalculatorFactory, |
|
|
|
private readonly configurationService: ConfigurationService, |
|
|
|
private readonly orderService: OrderService, |
|
|
|
private readonly redisCacheService: RedisCacheService |
|
|
|
) {} |
|
|
|
|
|
|
@ -34,7 +39,22 @@ export class PortfolioSnapshotProcessor { |
|
|
|
`PortfolioSnapshotProcessor (${PORTFOLIO_SNAPSHOT_PROCESS_JOB_NAME})` |
|
|
|
); |
|
|
|
|
|
|
|
const snapshot = await this.computeSnapshot(); |
|
|
|
const { activities } = |
|
|
|
await this.orderService.getOrdersForPortfolioCalculator({ |
|
|
|
filters: job.data.filters, |
|
|
|
userCurrency: job.data.userCurrency, |
|
|
|
userId: job.data.userId |
|
|
|
}); |
|
|
|
|
|
|
|
const portfolioCalculator = this.calculatorFactory.createCalculator({ |
|
|
|
activities, |
|
|
|
calculationType: PerformanceCalculationType.TWR, |
|
|
|
currency: job.data.userCurrency, |
|
|
|
filters: job.data.filters, |
|
|
|
userId: job.data.userId |
|
|
|
}); |
|
|
|
|
|
|
|
const snapshot = await portfolioCalculator.computeSnapshot(); |
|
|
|
|
|
|
|
Logger.log( |
|
|
|
`Portfolio snapshot calculation of user ${job.data.userId} has been completed`, |
|
|
@ -68,20 +88,4 @@ export class PortfolioSnapshotProcessor { |
|
|
|
throw new Error(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO
|
|
|
|
public async computeSnapshot(): Promise<PortfolioSnapshot> { |
|
|
|
return { |
|
|
|
currentValueInBaseCurrency: new Big(0), |
|
|
|
hasErrors: false, |
|
|
|
historicalData: [], |
|
|
|
positions: [], |
|
|
|
totalFeesWithCurrencyEffect: new Big(0), |
|
|
|
totalInterestWithCurrencyEffect: new Big(0), |
|
|
|
totalInvestment: new Big(0), |
|
|
|
totalInvestmentWithCurrencyEffect: new Big(0), |
|
|
|
totalLiabilitiesWithCurrencyEffect: new Big(0), |
|
|
|
totalValuablesWithCurrencyEffect: new Big(0) |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|