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
|
|
@ -265,10 +265,22 @@ function parseTimestampMicros(
|
|||
);
|
||||
}
|
||||
|
||||
function microsToEpochMs(us: bigint, field: 'ts' | 'known_at', rowIndex: number): number {
|
||||
function microsToEpochMs(
|
||||
us: bigint,
|
||||
field: 'ts' | 'known_at',
|
||||
rowIndex: number,
|
||||
rounding: 'floor' | 'ceil'
|
||||
): number {
|
||||
const quotient = us / 1000n;
|
||||
const remainder = us % 1000n;
|
||||
const msBigInt = remainder < 0n ? quotient - 1n : quotient;
|
||||
const msBigInt =
|
||||
rounding === 'ceil'
|
||||
? remainder > 0n
|
||||
? quotient + 1n
|
||||
: quotient
|
||||
: remainder < 0n
|
||||
? quotient - 1n
|
||||
: quotient;
|
||||
const ms = Number(msBigInt);
|
||||
if (!Number.isSafeInteger(ms) || Math.abs(ms) > MAX_ECMASCRIPT_EPOCH_MS) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
|
|
@ -350,14 +362,15 @@ function mapBars1mRows(
|
|||
|
||||
out[i] = {
|
||||
listingId,
|
||||
ts: microsToEpochMs(tsUs, 'ts', i),
|
||||
ts: microsToEpochMs(tsUs, 'ts', i, 'floor'),
|
||||
open: readRequiredFiniteNumber(raw, 'open', i),
|
||||
high: readRequiredFiniteNumber(raw, 'high', i),
|
||||
low: readRequiredFiniteNumber(raw, 'low', i),
|
||||
close: readRequiredFiniteNumber(raw, 'close', i),
|
||||
volume: readRequiredFiniteNumber(raw, 'volume', i),
|
||||
vwap: readNullableFiniteNumber(raw, 'vwap', i),
|
||||
knownAt: microsToEpochMs(knownAtUs, 'known_at', i),
|
||||
// Round sub-millisecond availability up so replay never treats a bar as known before arrival.
|
||||
knownAt: microsToEpochMs(knownAtUs, 'known_at', i, 'ceil'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -404,7 +417,8 @@ export function createQuestDbIntradayBarsReader(
|
|||
);
|
||||
}
|
||||
|
||||
const batchSize = options.batchSize ?? DEFAULT_QUESTDB_BARS_BATCH_SIZE;
|
||||
const batchSize =
|
||||
options.batchSize === undefined ? DEFAULT_QUESTDB_BARS_BATCH_SIZE : options.batchSize;
|
||||
if (typeof batchSize !== 'number' || !Number.isSafeInteger(batchSize) || batchSize < 1) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid batchSize "${String(options.batchSize)}". Expected a positive safe integer.`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue