Browse Source

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
pull/8289/head
Thomas Kaul 5 days ago
committed by GitHub
parent
commit
1f4f70e1b5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 24
      apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts
  3. 15
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

4
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 - 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 - 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 ## 3.91.0 - 2026-10-23
### Added ### Added

24
apps/api/src/services/queues/data-gathering/data-gathering.service.spec.ts

@ -263,7 +263,29 @@ describe('DataGatheringService', () => {
expect(prismaService.marketData.upsert).toHaveBeenCalledWith( expect(prismaService.marketData.upsert).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
create: expect.objectContaining({ isCarriedForward: false }), 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' })
}) })
); );
}); });

15
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 { Inject, Injectable, Logger } from '@nestjs/common';
import { Prisma } from '@prisma/client'; import { Prisma } from '@prisma/client';
import { Job, JobOptions, Queue } from 'bull'; 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'; import ms, { StringValue } from 'ms';
@Injectable() @Injectable()
@ -342,6 +349,10 @@ export class DataGatheringService {
]?.marketPrice; ]?.marketPrice;
if (marketPrice) { if (marketPrice) {
const state = isBefore(startOfUtcDate, getStartOfUtcDate(new Date()))
? 'CLOSE'
: 'INTRADAY';
return await this.prismaService.marketData.upsert({ return await this.prismaService.marketData.upsert({
create: { create: {
dataSource, dataSource,
@ -350,7 +361,7 @@ export class DataGatheringService {
date: startOfUtcDate, date: startOfUtcDate,
isCarriedForward: false isCarriedForward: false
}, },
update: { marketPrice, isCarriedForward: false }, update: { marketPrice, state, isCarriedForward: false },
where: { where: {
dataSource_symbol_date: { dataSource_symbol_date: {
dataSource, dataSource,

Loading…
Cancel
Save