T-79: M1.3c — MarketDataStore contract types + pure 6-month Vault fence and DuckDB connection budget (no DuckDB dependency, no I/O)

This commit is contained in:
Studio 2026-11-28 00:20:37 -05:00
parent cfcc856817
commit be06a00ffe
6 changed files with 1240 additions and 2 deletions

View file

@ -0,0 +1,232 @@
import type {
BarBatch,
DataScope,
DuckDbConnectionBudget,
EventKind,
FencedTimeRange,
MarketDataStore,
Table,
UniverseRef,
VaultFenceContext,
VaultFenceQuery,
} from '@stock-bot/research';
import type {
DataScope as SubpathDataScope,
MarketDataStore as SubpathMarketDataStore,
} from '@stock-bot/research/market-data-store';
type AssertEqual<A, B> =
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
const _sameStore: AssertEqual<MarketDataStore, SubpathMarketDataStore> = true;
const _sameScope: AssertEqual<DataScope, SubpathDataScope> = true;
void _sameStore;
void _sameScope;
const emptyTable: Table = { columns: [], rows: [] };
const emptyBatch: BarBatch = { rows: [] };
const stubStore: MarketDataStore = {
bars(_q: {
listingIds: number[];
timeframe: '1m' | '5m' | '1h' | '1d';
from: string;
to: string;
adjustment: 'raw' | 'split' | 'total';
asOf?: string;
scope?: DataScope;
}): AsyncIterable<BarBatch> {
return {
async *[Symbol.asyncIterator]() {
yield emptyBatch;
},
};
},
async crossSection(_q: {
features: string[];
date: string;
universe: UniverseRef;
asOf?: string;
}): Promise<Table> {
return emptyTable;
},
async fundamentalsAsOf(_q: {
listingIds: number[];
fields: string[];
asOf: string;
allowEstimatedLag?: boolean;
}): Promise<Table> {
return emptyTable;
},
async events(_q: {
kinds: EventKind[];
listingIds?: number[];
from: string;
to: string;
asOf?: string;
}): Promise<Table> {
return emptyTable;
},
async shortsAsOf(_q: {
listingIds: number[];
from: string;
to: string;
asOf?: string;
}): Promise<Table> {
return emptyTable;
},
async macroAsOf(_q: {
countries: string[];
indicators: string[];
from: string;
to: string;
asOf?: string;
}): Promise<Table> {
return emptyTable;
},
async fx(_q: {
pair: 'USD.CAD';
timeframe: '1m' | '1d';
from: string;
to: string;
}): Promise<Table> {
return emptyTable;
},
async universe(_q: { ref: UniverseRef; date: string }): Promise<number[]> {
return [101, 202];
},
};
function verifyAllMethods(store: MarketDataStore): void {
const _bars: AsyncIterable<BarBatch> = store.bars({
listingIds: [1, 2],
timeframe: '1d',
from: '2024-01-01',
to: '2025-12-31',
adjustment: 'raw',
});
const _barsWithOpts: AsyncIterable<BarBatch> = store.bars({
listingIds: [1],
timeframe: '1m',
from: '2025-01-01T00:00:00Z',
to: '2025-06-01T00:00:00Z',
adjustment: 'total',
asOf: '2025-06-01T00:00:00Z',
scope: 'vault_fenced',
});
const _cross: Promise<Table> = store.crossSection({
features: ['rsi_14@v1'],
date: '2025-05-01',
universe: 'us_liquid_top3000',
asOf: '2025-05-01',
});
const _fundamentals: Promise<Table> = store.fundamentalsAsOf({
listingIds: [1],
fields: ['revenue_ttm'],
asOf: '2025-05-01',
allowEstimatedLag: false,
});
const _events: Promise<Table> = store.events({
kinds: ['filing', 'earnings', 'ceo_post', 'corporate_action'],
from: '2025-01-01',
to: '2025-05-01',
});
const _shorts: Promise<Table> = store.shortsAsOf({
listingIds: [1],
from: '2025-01-01',
to: '2025-05-01',
});
const _macro: Promise<Table> = store.macroAsOf({
countries: ['US', 'CA'],
indicators: ['CPI'],
from: '2025-01-01',
to: '2025-05-01',
});
const _fx: Promise<Table> = store.fx({
pair: 'USD.CAD',
timeframe: '1d',
from: '2025-01-01',
to: '2025-05-01',
});
const _universe: Promise<number[]> = store.universe({
ref: 'us_liquid_top3000',
date: '2025-05-01',
});
void _bars;
void _barsWithOpts;
void _cross;
void _fundamentals;
void _events;
void _shorts;
void _macro;
void _fx;
void _universe;
// Negative checks: unknown DataScope, non-numeric listingIds, missing required fields.
// @ts-expect-error Only 'vault_fenced' and 'vault_evaluation_only' are valid DataScope values.
const _badScope: DataScope = 'unrestricted';
void _badScope;
store.bars({
// @ts-expect-error listingIds must be INT32 number[], not string[].
listingIds: ['AAPL'],
timeframe: '1d',
from: '2025-01-01',
to: '2025-05-01',
adjustment: 'raw',
});
// @ts-expect-error adjustment is required on bars().
store.bars({
listingIds: [1],
timeframe: '1d',
from: '2025-01-01',
to: '2025-05-01',
});
// @ts-expect-error asOf is required on fundamentalsAsOf().
store.fundamentalsAsOf({
listingIds: [1],
fields: ['revenue_ttm'],
});
store.fx({
// @ts-expect-error pair is locked to 'USD.CAD' in §4.
pair: 'EUR.USD',
timeframe: '1d',
from: '2025-01-01',
to: '2025-05-01',
});
}
verifyAllMethods(stubStore);
// Ensure auxiliary exported contract types remain structurally usable.
const _query: VaultFenceQuery = { from: '2025-01-01', to: '2025-05-01' };
const _ctx: VaultFenceContext = { vaultCutoffTs: Date.UTC(2026, 4, 28) };
const _range: FencedTimeRange = {
fromMs: 0,
toMs: 1,
asOfMs: 1,
scope: 'vault_fenced',
clampedTo: false,
clampedAsOf: false,
};
const _budget: DuckDbConnectionBudget = {
memoryLimit: '6GB',
threads: 4,
tempDirectory: '/mnt/data/stockbot/tmp/duckdb',
statements: [],
};
void _query;
void _ctx;
void _range;
void _budget;