From 1f4f70e1b50ef1d6b171c1b7a1d8fd97cd8f4037 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 24 Oct 2026 09:54:35 +0200 Subject: [PATCH] Bugfix/set close state in market data gathering for specific date (#8062) * Fix state of market data in historical market data gathering for specific date * Update changelog --- CHANGELOG.md | 4 ++++ .../data-gathering.service.spec.ts | 24 ++++++++++++++++++- .../data-gathering/data-gathering.service.ts | 15 ++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 574c1e07ff..ce6ee7919b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the performance of the historical market data table of the admin control panel by querying subscription usage in a single database query - Hardened the `POST api/v1/import` endpoint by hiding internal error messages +### Fixed + +- Fixed the state of the market data in the historical market data gathering endpoint for a specific date + ## 3.91.0 - 2026-10-23 ### Added diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts index 95ca49efcc..9b63037ce2 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts @@ -263,7 +263,29 @@ describe('DataGatheringService', () => { expect(prismaService.marketData.upsert).toHaveBeenCalledWith( expect.objectContaining({ create: expect.objectContaining({ isCarriedForward: false }), - update: { marketPrice: 100, isCarriedForward: false } + update: { isCarriedForward: false, marketPrice: 100, state: 'CLOSE' } + }) + ); + }); + + it('sets the state to INTRADAY for today', async () => { + jest.useFakeTimers().setSystemTime(new Date('2026-08-22T14:00:00.000Z')); + + dataProviderService.getHistoricalRaw.mockResolvedValue({ + 'YAHOO-AAPL': { + '2026-08-22': { marketPrice: 100 } + } + }); + + await dataGatheringService.gatherSymbolForDate({ + dataSource: 'YAHOO', + date: parseDate('2026-08-22'), + symbol: 'AAPL' + }); + + expect(prismaService.marketData.upsert).toHaveBeenCalledWith( + expect.objectContaining({ + update: expect.objectContaining({ state: 'INTRADAY' }) }) ); }); diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts index 5547d4cca6..83d722888f 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts @@ -33,7 +33,14 @@ import { InjectQueue } from '@nestjs/bull'; import { Inject, Injectable, Logger } from '@nestjs/common'; import { Prisma } from '@prisma/client'; import { Job, JobOptions, Queue } from 'bull'; -import { format, min, subDays, subMilliseconds, subYears } from 'date-fns'; +import { + format, + isBefore, + min, + subDays, + subMilliseconds, + subYears +} from 'date-fns'; import ms, { StringValue } from 'ms'; @Injectable() @@ -342,6 +349,10 @@ export class DataGatheringService { ]?.marketPrice; if (marketPrice) { + const state = isBefore(startOfUtcDate, getStartOfUtcDate(new Date())) + ? 'CLOSE' + : 'INTRADAY'; + return await this.prismaService.marketData.upsert({ create: { dataSource, @@ -350,7 +361,7 @@ export class DataGatheringService { date: startOfUtcDate, isCarriedForward: false }, - update: { marketPrice, isCarriedForward: false }, + update: { marketPrice, state, isCarriedForward: false }, where: { dataSource_symbol_date: { dataSource,