|
@ -4,18 +4,20 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- |
|
|
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; |
|
|
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service'; |
|
|
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service'; |
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
|
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; |
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; |
|
|
import { |
|
|
import { |
|
|
DATA_GATHERING_QUEUE, |
|
|
DATA_GATHERING_QUEUE, |
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS, |
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS, |
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS |
|
|
GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS, |
|
|
|
|
|
PROPERTY_BENCHMARKS |
|
|
} from '@ghostfolio/common/config'; |
|
|
} from '@ghostfolio/common/config'; |
|
|
import { |
|
|
import { |
|
|
DATE_FORMAT, |
|
|
DATE_FORMAT, |
|
|
getAssetProfileIdentifier, |
|
|
getAssetProfileIdentifier, |
|
|
resetHours |
|
|
resetHours |
|
|
} from '@ghostfolio/common/helper'; |
|
|
} from '@ghostfolio/common/helper'; |
|
|
import { UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { InjectQueue } from '@nestjs/bull'; |
|
|
import { InjectQueue } from '@nestjs/bull'; |
|
|
import { Inject, Injectable, Logger } from '@nestjs/common'; |
|
|
import { Inject, Injectable, Logger } from '@nestjs/common'; |
|
|
import { DataSource } from '@prisma/client'; |
|
|
import { DataSource } from '@prisma/client'; |
|
@ -34,6 +36,7 @@ export class DataGatheringService { |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly marketDataService: MarketDataService, |
|
|
private readonly marketDataService: MarketDataService, |
|
|
private readonly prismaService: PrismaService, |
|
|
private readonly prismaService: PrismaService, |
|
|
|
|
|
private readonly propertyService: PropertyService, |
|
|
private readonly symbolProfileService: SymbolProfileService |
|
|
private readonly symbolProfileService: SymbolProfileService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
@ -255,6 +258,10 @@ export class DataGatheringService { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getEarliestDate(aStartDate: Date) { |
|
|
|
|
|
return min([aStartDate, subYears(new Date(), 10)]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async getSymbols7D(): Promise<IDataGatheringItem[]> { |
|
|
private async getSymbols7D(): Promise<IDataGatheringItem[]> { |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
const startDate = subDays(resetHours(new Date()), 7); |
|
|
|
|
|
|
|
@ -321,6 +328,14 @@ export class DataGatheringService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async getSymbolsMax(): Promise<IDataGatheringItem[]> { |
|
|
private async getSymbolsMax(): Promise<IDataGatheringItem[]> { |
|
|
|
|
|
const benchmarkAssetProfileIdMap: { [key: string]: boolean } = {}; |
|
|
|
|
|
( |
|
|
|
|
|
((await this.propertyService.getByKey( |
|
|
|
|
|
PROPERTY_BENCHMARKS |
|
|
|
|
|
)) as BenchmarkProperty[]) ?? [] |
|
|
|
|
|
).forEach(({ symbolProfileId }) => { |
|
|
|
|
|
benchmarkAssetProfileIdMap[symbolProfileId] = true; |
|
|
|
|
|
}); |
|
|
const startDate = |
|
|
const startDate = |
|
|
( |
|
|
( |
|
|
await this.prismaService.order.findFirst({ |
|
|
await this.prismaService.order.findFirst({ |
|
@ -334,7 +349,7 @@ export class DataGatheringService { |
|
|
return { |
|
|
return { |
|
|
dataSource, |
|
|
dataSource, |
|
|
symbol, |
|
|
symbol, |
|
|
date: min([startDate, subYears(new Date(), 10)]) |
|
|
date: this.getEarliestDate(startDate) |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -343,6 +358,7 @@ export class DataGatheringService { |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
orderBy: [{ symbol: 'asc' }], |
|
|
select: { |
|
|
select: { |
|
|
dataSource: true, |
|
|
dataSource: true, |
|
|
|
|
|
id: true, |
|
|
Order: { |
|
|
Order: { |
|
|
orderBy: [{ date: 'asc' }], |
|
|
orderBy: [{ date: 'asc' }], |
|
|
select: { date: true }, |
|
|
select: { date: true }, |
|
@ -364,9 +380,15 @@ export class DataGatheringService { |
|
|
); |
|
|
); |
|
|
}) |
|
|
}) |
|
|
.map((symbolProfile) => { |
|
|
.map((symbolProfile) => { |
|
|
|
|
|
let date = symbolProfile.Order?.[0]?.date ?? startDate; |
|
|
|
|
|
|
|
|
|
|
|
if (benchmarkAssetProfileIdMap[symbolProfile.id]) { |
|
|
|
|
|
date = this.getEarliestDate(startDate); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
...symbolProfile, |
|
|
...symbolProfile, |
|
|
date: symbolProfile.Order?.[0]?.date ?? startDate |
|
|
date |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|