T-146: M2.3f — QuestDB bars_1m intraday reader for MarketDataStore.bars (timeframe: '1m'): Vault-fenced, parameterized planBars1mQuery + batch iterator over an injected PGWire query port in libs/research/src/market-data-store-questdb.ts (pure, no new deps, no live QuestDB)
This commit is contained in:
parent
cfbcb51bd3
commit
9f2b184cd2
2 changed files with 86 additions and 7 deletions
|
|
@ -415,12 +415,12 @@ describe('Input validation and injection rejection', () => {
|
|||
})
|
||||
).toThrow(MarketDataStoreValidationError);
|
||||
|
||||
for (const badBatchSize of [0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY]) {
|
||||
for (const badBatchSize of [0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY, null]) {
|
||||
expect(() =>
|
||||
createQuestDbIntradayBarsReader({
|
||||
executor,
|
||||
vaultCutoffTs: VAULT_CUTOFF_TS,
|
||||
batchSize: badBatchSize,
|
||||
batchSize: badBatchSize as unknown as number,
|
||||
})
|
||||
).toThrow(MarketDataStoreValidationError);
|
||||
}
|
||||
|
|
@ -700,4 +700,69 @@ describe('Malformed and out-of-fence row defence-in-depth', () => {
|
|||
expect(caught).toBeInstanceOf(MarketDataStoreValidationError);
|
||||
expect(yielded).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('rounds sub-millisecond known_at up so wider-window replay never exposes a bar before arrival', async () => {
|
||||
// Matches the QuestDB storage fixture:
|
||||
// ts = 2024-01-02T14:30:00.000000Z (1704205800000000 us)
|
||||
// known_at = 2024-01-02T14:31:00.000700Z (1704205860000700 us)
|
||||
const executor = new RecordingQuestDbExecutor();
|
||||
executor.setRows([
|
||||
{
|
||||
listing_id: '1042',
|
||||
ts_us: '1704205800000000',
|
||||
open: 185.1,
|
||||
high: 185.5,
|
||||
low: 184.9,
|
||||
close: 185.4,
|
||||
volume: 12500,
|
||||
vwap: 185.28,
|
||||
known_at_us: '1704205860000700',
|
||||
},
|
||||
{
|
||||
listing_id: '1042',
|
||||
ts_us: '1704205860000000',
|
||||
open: 185.4,
|
||||
high: 185.6,
|
||||
low: 185.3,
|
||||
close: 185.55,
|
||||
volume: 8200,
|
||||
vwap: null,
|
||||
known_at_us: '1704205920000000', // exact millisecond: 2024-01-02T14:32:00.000000Z
|
||||
},
|
||||
]);
|
||||
|
||||
const reader = createQuestDbIntradayBarsReader({
|
||||
executor,
|
||||
vaultCutoffTs: VAULT_CUTOFF_TS,
|
||||
});
|
||||
|
||||
const query: QuestDbBars1mQuery = {
|
||||
listingIds: [1042],
|
||||
timeframe: '1m',
|
||||
from: '2024-01-02T14:30:00.000Z',
|
||||
to: '2024-01-02T21:00:00.000Z',
|
||||
asOf: '2024-01-02T21:00:00.000Z',
|
||||
adjustment: 'raw',
|
||||
};
|
||||
|
||||
const run1 = (await collectBatches(reader.bars(query))).flatMap(b => b.rows);
|
||||
const run2 = (await collectBatches(reader.bars(query))).flatMap(b => b.rows);
|
||||
expect(run1).toEqual(run2);
|
||||
expect(run1).toHaveLength(2);
|
||||
|
||||
const decisionAt143100000 = Date.UTC(2024, 0, 2, 14, 31, 0, 0);
|
||||
const decisionAt143100001 = Date.UTC(2024, 0, 2, 14, 31, 0, 1);
|
||||
const exactKnownAt143200000 = Date.UTC(2024, 0, 2, 14, 32, 0, 0);
|
||||
|
||||
const subMsBar = run1[0]!;
|
||||
expect(subMsBar.knownAt).toBe(decisionAt143100001);
|
||||
// Ineligible at 14:31:00.000 UTC, eligible at 14:31:00.001 UTC.
|
||||
expect(subMsBar.knownAt <= decisionAt143100000).toBe(false);
|
||||
expect(subMsBar.knownAt <= decisionAt143100001).toBe(true);
|
||||
|
||||
// Exact whole-millisecond known_at is not pushed forward.
|
||||
const exactMsBar = run1[1]!;
|
||||
expect(exactMsBar.knownAt).toBe(exactKnownAt143200000);
|
||||
expect(exactMsBar.knownAt <= exactKnownAt143200000).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue