diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e690376a..1a87462d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed the editing of the emergency fund +- Fixed the historical data gathering interval for asset profiles used as benchmarks having activities ## 1.298.0 - 2023-08-06 diff --git a/apps/api/src/services/data-gathering/data-gathering.module.ts b/apps/api/src/services/data-gathering/data-gathering.module.ts index 50131bbe8..673364f09 100644 --- a/apps/api/src/services/data-gathering/data-gathering.module.ts +++ b/apps/api/src/services/data-gathering/data-gathering.module.ts @@ -5,6 +5,7 @@ import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data- import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.module'; import { MarketDataModule } from '@ghostfolio/api/services/market-data/market-data.module'; import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; +import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile/symbol-profile.module'; import { DATA_GATHERING_QUEUE } from '@ghostfolio/common/config'; import { BullModule } from '@nestjs/bull'; @@ -28,6 +29,7 @@ import { DataGatheringProcessor } from './data-gathering.processor'; ExchangeRateDataModule, MarketDataModule, PrismaModule, + PropertyModule, SymbolProfileModule ], providers: [DataGatheringProcessor, DataGatheringService], diff --git a/apps/api/src/services/data-gathering/data-gathering.service.ts b/apps/api/src/services/data-gathering/data-gathering.service.ts index 20da098ff..7718ef394 100644 --- a/apps/api/src/services/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering/data-gathering.service.ts @@ -4,18 +4,20 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.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 { DATA_GATHERING_QUEUE, GATHER_HISTORICAL_MARKET_DATA_PROCESS, - GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS + GATHER_HISTORICAL_MARKET_DATA_PROCESS_OPTIONS, + PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; import { DATE_FORMAT, getAssetProfileIdentifier, resetHours } from '@ghostfolio/common/helper'; -import { UniqueAsset } from '@ghostfolio/common/interfaces'; +import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; import { InjectQueue } from '@nestjs/bull'; import { Inject, Injectable, Logger } from '@nestjs/common'; import { DataSource } from '@prisma/client'; @@ -34,6 +36,7 @@ export class DataGatheringService { private readonly exchangeRateDataService: ExchangeRateDataService, private readonly marketDataService: MarketDataService, private readonly prismaService: PrismaService, + private readonly propertyService: PropertyService, 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 { const startDate = subDays(resetHours(new Date()), 7); @@ -321,6 +328,14 @@ export class DataGatheringService { } private async getSymbolsMax(): Promise { + const benchmarkAssetProfileIdMap: { [key: string]: boolean } = {}; + ( + ((await this.propertyService.getByKey( + PROPERTY_BENCHMARKS + )) as BenchmarkProperty[]) ?? [] + ).forEach(({ symbolProfileId }) => { + benchmarkAssetProfileIdMap[symbolProfileId] = true; + }); const startDate = ( await this.prismaService.order.findFirst({ @@ -334,7 +349,7 @@ export class DataGatheringService { return { dataSource, symbol, - date: min([startDate, subYears(new Date(), 10)]) + date: this.getEarliestDate(startDate) }; }); @@ -343,6 +358,7 @@ export class DataGatheringService { orderBy: [{ symbol: 'asc' }], select: { dataSource: true, + id: true, Order: { orderBy: [{ date: 'asc' }], select: { date: true }, @@ -364,9 +380,15 @@ export class DataGatheringService { ); }) .map((symbolProfile) => { + let date = symbolProfile.Order?.[0]?.date ?? startDate; + + if (benchmarkAssetProfileIdMap[symbolProfile.id]) { + date = this.getEarliestDate(startDate); + } + return { ...symbolProfile, - date: symbolProfile.Order?.[0]?.date ?? startDate + date }; });