T-86: M1.1k — Read-only Mongo source-symbol readers: eodSymbols / ibSymbols / qmSymbols / ceoSymbols / eodSymbolChange → Stage A + Stage B input records (no new dependencies)

This commit is contained in:
Studio 2026-11-28 04:13:30 -05:00
parent fa55ff16fa
commit 32677c50da
4 changed files with 2729 additions and 0 deletions

View file

@ -80,3 +80,18 @@ bun --env-file=/home/boki/.studio/test-env/stock-bot.env test test/postgres/secu
- Workload: `20,000` instruments, `20,000` listings, `60,000` provider mappings (`100,000` core rows; `140,000` total rows including `20,000` `instrument_identifier_history` and `20,000` `listing_symbol_history` rows).
- Observed end-to-end test wall time: `2.20s` (`2200.02ms`, reported by `bun test`; includes isolated schema migration, synthetic fixture construction, `persistSecurityMaster`, and `COUNT(*)` verification because `test/setup.ts` suppresses `console.info`).
- Throughput (conservative lower bound over full test wall time): `45,454` core rows/s (`100,000 / 2.20002s`), `63,636` total rows/s (`140,000 / 2.20002s`).
## Read-Only Source-Symbol Readers (`source-symbol-readers.ts`)
`apps/stock/data-pipeline/src/security-master/source-symbol-readers.ts` adapts raw `eodSymbols`, `ibSymbols`, `qmSymbols`, `ceoSymbols`, and `eodSymbolChange` documents into deterministic Stage A (`StageASourceRecord`) and Stage B (`StageBEodListingInput`, `StageBIbContractInput`, `StageBTickerSourceInput`, `StageBSymbolChangeInput`) inputs via `readSecurityMasterSources`:
- **Read-only contract:** Exposes only `isReadOnly()` and `find()` on `ReadOnlySourceSymbolReader` (compile-time verified against `MongoDBClient`) with explicit `_id: 0` projections (omitting `qmSymbols.profile`/`symbolInfo`) and pushed-down country/venue filters (default `['US', 'CA']`).
- **Provider rules enforced:** Excludes `eodSymbols` `Exchange="NMFQS"` mutual funds, preserves `delisted: true` and duplicate QM `(symbol, exchange)` pairs (`VOY:CNX` + `VOY:CC`), sets Stage A country strictly to issuer country (never listing country), never uses IB ATS `exchangeId` venues (`AEQLIT`, `OTCLNKECN`, etc.) as listing MIC or `primaryExchange`, strips CEO `.TO`/`.V` suffixes with Stage B double-strip protection, nulls invalid ISIN/CUSIP check digits without throwing, and reconciles `docsRead === emitted + sum(skips)` per collection.
- **Local synthetic benchmark:** Run the unit suite and fixed-seed 368,000-doc synthetic benchmark (`300,000` `eodSymbols` + `50,000` `qmSymbols` + `18,000` `ibSymbols`, zero DB connections) with:
```bash
bun test test/unit/security-master-source-symbol-readers.test.ts
```
- **Recorded baseline (`2026-11-28`, local sandbox, in-memory streaming fake reader):**
- Workload: `368,000` synthetic docs (`300,000` `eodSymbols`, `50,000` `qmSymbols`, `18,000` `ibSymbols`) including NMFQS exclusion, country normalization, ISIN/CUSIP check-digit validation, ticker parsing, and deterministic ASCII sorting.
- Observed throughput: `940,646 docs/s` (`391.2 ms` wall time, floor `>= 25,000 docs/s`).

View file

@ -189,3 +189,55 @@ export {
type SampleCloseRecord,
type SelectSampleDatesOptions,
} from './price-cross-check';
export {
adaptCeoSymbolDoc,
adaptEodSymbolChangeDoc,
adaptEodSymbolDoc,
adaptIbSymbolDoc,
adaptQmSymbolDoc,
CEO_SYMBOLS_PROJECTION,
createExchangeSourceLookup,
DEFAULT_SOURCE_COUNTRIES,
EOD_SYMBOL_CHANGE_PROJECTION,
EOD_SYMBOLS_PROJECTION,
IB_SYMBOLS_PROJECTION,
normalizeCountryIso2,
QM_SYMBOLS_PROJECTION,
readCeoSymbols,
readEodSymbolChanges,
readEodSymbols,
readIbSymbols,
readQmSymbols,
readSecurityMasterSources,
SOURCE_SYMBOL_COLLECTIONS,
type AdaptCeoSymbolContext,
type AdaptEodSymbolChangeContext,
type AdaptEodSymbolChangeResult,
type AdaptEodSymbolContext,
type AdaptEodSymbolResult,
type AdaptIbSymbolContext,
type AdaptIbSymbolResult,
type AdaptQmSymbolContext,
type AdaptTickerSourceResult,
type CreateExchangeSourceLookupOptions,
type ExchangeSourceLookup,
type ExchangeSourceLookupEntry,
type MongoDBClientSourceSymbolReaderCheck,
type ReadEodSymbolChangesResult,
type ReadEodSymbolsResult,
type ReadIbSymbolsResult,
type ReadOnlySourceSymbolReader,
type ReadSecurityMasterSourcesOptions,
type ReadSourceCollectionOptions,
type ReadTickerSourcesResult,
type SecurityMasterSourcesResult,
type SecurityMasterSourcesStats,
type SecurityMasterStageBSourceInput,
type SourceCollectionReadStats,
type SourceSymbolCollectionKey,
type SourceSymbolCollectionName,
type SourceSymbolFindOptions,
type SourceSymbolSkipCounts,
type SourceSymbolSkipReason,
} from './source-symbol-readers';

File diff suppressed because it is too large Load diff