T-148: M2.3h — Route MarketDataStore.bars (timeframe: '1m') to the QuestDB bars_1m reader: pure createRoutedMarketDataStore composing the DuckDB daily store + injected intraday reader in libs/research/src/market-data-store-routed.ts (no new deps, no live QuestDB)

This commit is contained in:
Studio 2026-12-01 23:02:17 -05:00
parent c6ee4d0336
commit 8f9e9ac196
5 changed files with 1323 additions and 0 deletions

View file

@ -124,6 +124,37 @@ Fixed-seed (`20261129`) local benchmark planning `120,000` mixed queries across
- **Mixed planners (`120,000` queries):** `elapsedMs = 225.79 ms`, `queriesPerSec = 531,470 queries/s` (`758,061` bound params, pinned checksum `8606c98c`)
- **`universe` plan + adapter mapping (`200` calls × `15,000` listings):** `elapsedMs = 23.44 ms`, `callsPerSec = 8,534 calls/s`, `rowsPerSec = 128,011,137 rows/s` (`3,000,000` mapped IDs, pinned checksum `ef5f1136`)
## Routed `MarketDataStore` (DuckDB Daily + QuestDB `1m` Intraday)
Exported from `@stock-bot/research` and `@stock-bot/research/market-data-store-routed` (`libs/research/src/market-data-store-routed.ts`). The QuestDB intraday reader is also exported from `@stock-bot/research/market-data-store-questdb`. Both modules are pure, dependency-free, and browser-safe.
- **`createRoutedMarketDataStore({ daily, intraday })`** — Composes a full daily `MarketDataStore` (e.g. `createDuckDbMarketDataStore`) with an intraday `bars` reader (`Pick<MarketDataStore, 'bars'>`, e.g. `createQuestDbIntradayBarsReader`).
- `bars(q)` with `timeframe: '1m'` delegates directly to `intraday.bars(q)` (preserving lazy iteration, receiver, query identity, and error propagation). Note that `createQuestDbIntradayBarsReader` supports split-unadjusted raw (`adjustment: 'raw'`) `1m` bars.
- `bars(q)` with any other timeframe (`'1d'`, `'5m'`, `'1h'`, or malformed inputs) and all other `MarketDataStore` methods (`crossSection`, `fundamentalsAsOf`, `events`, `shortsAsOf`, `macroAsOf`, `fx`, `universe`) delegate directly to `daily`.
- **Shared Vault fence requirement:** The router adds no Vault logic of its own; each delegate enforces its own fence. Always construct `daily`, `intraday`, and any MCP tool (`createQueryDataTool` / `createResearchCopilotMcpServer`) with the exact same `vaultCutoffTs` and `vaultOperatorAuthorized`:
```ts
const vaultCutoffTs = Date.UTC(2025, 6, 1, 0, 0, 0, 0);
const vaultOperatorAuthorized = false;
const daily = createDuckDbMarketDataStore({
executor: duckDbExecutor,
curatedRoot: '/mnt/data/stockbot/curated',
vaultCutoffTs,
vaultOperatorAuthorized,
});
const intraday = createQuestDbIntradayBarsReader({
executor: questDbExecutor,
vaultCutoffTs,
vaultOperatorAuthorized,
});
const store = createRoutedMarketDataStore({ daily, intraday });
const queryDataTool = createQueryDataTool({
store,
vaultContext: { vaultCutoffTs, vaultOperatorAuthorized },
});
```
## Signal Panel Builder
Exported from both `@stock-bot/research` and `@stock-bot/research/signal-panel` (`libs/research/src/signal-panel.ts`). The module is pure, synchronous (except `collectBars`), dependency-free, and browser-safe (zero `node:*` imports, zero bare `process` access, no database drivers).