Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/set close state in market data gathering for specific date (#8062)

Thomas Kaul1f4f70e1b50e
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,