refactor: pre-M0 cleanup, core library hardening, and isolated dev/QA Docker stack
- Remove ~44k LOC of dead code, legacy v1 TS simulator/strategy stack, event-bus, analytics FastAPI prototype, legacy calculation archives, and unused deps (data-ingestion provider API handlers untouched) - Extract @stock-bot/di/http-security and isolate @stock-bot/browser to data-ingestion via ServiceContainerBuilder.withRegistrations() - Harden @stock-bot/mongodb read-only proxies, flatten @stock-bot/postgres with unified master+research migrations, and fix @stock-bot/config EnvLoader, ServiceApplication worker lifecycle, NamespacedCache.clear(), and BatchProcessor error propagation - Flatten workspace root (remove apps/stock/package.json) and collapse orchestrator re-export shims - Pin all Docker image versions, add shm_size/nofile/RAM caps and docker-compose.quant.yml, fix 05-add-visible-column.sql view recreation, and decouple dev/QA Compose project names for side-by-side execution - Update PLATFORM-PLAN, DATA-CONTRACTS (bars_1m PARTITION BY MONTH, Rust bulk ETL, DuckDB limits), MILESTONES, and servers docs
This commit is contained in:
parent
ce9e2df67c
commit
4cd6038063
432 changed files with 1247 additions and 44469 deletions
|
|
@ -150,7 +150,7 @@ APP (web-app): Lab (+ marimo) · Agents · Strategies · Data · Trading · Mark
|
|||
| Layer | Owns | Language |
|
||||
| --- | --- | --- |
|
||||
| `data-ingestion` | Provider crawlers → raw MongoDB (scheduled jobs disabled outside dedicated ingester) | TypeScript |
|
||||
| `data-pipeline` | Entity resolution, split/volume un-adjustment, PIT curation, batch features → Postgres + Parquet + QuestDB | TypeScript + Python/DuckDB batch |
|
||||
| `data-pipeline` + `curate-etl` | Entity resolution & orchestration (TS), zero-copy BSON bulk bar ETL (`tools/curate-etl` in Rust), PIT/feature batch jobs → Postgres + Parquet + QuestDB | TypeScript + Rust (`RawDocumentBuf`/Arrow/ILP) + Python/DuckDB |
|
||||
| Research kernel | Single API + MCP server enforcing vault cutoff, budgets, trial ledger, and canonical metrics | TypeScript (`web-api` / `orchestrator` / `@stock-bot/calculations`) |
|
||||
| Engine | Authoritative accounting, multi-currency margin ledger, corporate actions, fills, risk, replay | Rust (`apps/stock/engine/src/financial`) |
|
||||
| Python SDK + marimo | Exploration, Signal Analyzer, Event Study, Tier 1 columnar screener, feature batch definitions | Python (`polars`, `duckdb`, `marimo`) |
|
||||
|
|
@ -176,9 +176,10 @@ Full schemas and SQL contracts live in **[DATA-CONTRACTS.md](DATA-CONTRACTS.md)*
|
|||
### Access rules & performance targets
|
||||
|
||||
1. **One access contract (`MarketDataStore` in TS, `stockbot.data` in Python).** Every non-vault call enforces `ts < VAULT_CUTOFF_TS` and `known_at <= asOf` inside the adapter. No raw-SQL escape hatch is exposed to agents; human localhost sessions may query read-only pre-vault DuckDB views.
|
||||
2. **Storage hygiene.**
|
||||
2. **Storage & memory hygiene.**
|
||||
- `MarketDataStore` and Parquet expose `listing_id` as `INT32`; inside QuestDB `10.2.0`, `listing_id` is stored as `SYMBOL CAPACITY 65536 NOCACHE` so `LATEST ON` backward partition scans and `ASOF JOIN` fast paths work without JVM heap bloat.
|
||||
- Sealed `>90d` QuestDB `bars_1m` partitions may be compressed in-place (`ALTER TABLE bars_1m CONVERT PARTITION TO PARQUET`) if NVMe capacity requires it; recent partitions remain native mmap.
|
||||
- QuestDB `bars_1m` uses **`PARTITION BY MONTH`** (`270` partitions across 22.5y instead of `~5,670` daily partitions) with host `vm.max_map_count >= 1048576`, `ulimits.nofile = 1048576`, and `QDB_RAM_USAGE_LIMIT_BYTES` capped (`20 GiB` on `quant`). Sealed `>90d` monthly partitions may be compressed in-place (`ALTER TABLE bars_1m CONVERT PARTITION TO PARQUET`) if NVMe capacity requires it; recent partitions remain native mmap.
|
||||
- Every DuckDB connection explicitly sets `memory_limit = '6GB'`, `threads = 4`, and `temp_directory` on `quant` (instead of DuckDB's `80%` host-RAM default), leaving `~24 GiB` of `quant`'s `125 GiB` unallocated for Linux NVMe page cache.
|
||||
3. **Measured storage targets on `quant` (`12900K`, SN850X NVMe):**
|
||||
- **W1:** 20y US+CA daily universe (~15k active+delisted listings, ~45M bars) + 1 signal IC/quantile scan: **`< 3 s` warm / `< 8 s` cold**.
|
||||
- **W2:** 1 listing, 1y of `1m` bars (~100k–200k rows) from QuestDB: **`< 250 ms` warm / `< 1 s` cold**.
|
||||
|
|
@ -264,7 +265,7 @@ Extends the existing 8-decimal Rust kernel (retiring legacy `f64` `BacktestEngin
|
|||
|
||||
- **Atomic timestamp-slice marking (`F06` fix):** Apply all instrument marks at timestamp `t` before evaluating `RiskAccount` portfolio drawdown/daily-loss latches so hedged long/short moves never trigger false intermediate halts.
|
||||
- **Simultaneous target rebalancing:** Credit haircut-adjusted pending `Sell` proceeds against same-barrier `Buy` reservations in `MatchingAccount::submit` so fully invested cross-sectional rotations execute cleanly in one barrier.
|
||||
- **Feature side-channel & Arrow loading:** Load market bars + precomputed `features` directly from Parquet/Arrow into Rust (eliminating PostgreSQL's 1 GB `JSONB` snapshot ceiling and removing double `serde_json::Value` parsing in `api/canonical.rs`), triggering JS/sandbox callbacks **only on declared rebalance barriers**.
|
||||
- **Zero-JSON market-data path & Feature side-channel:** Eliminate the 8× JSON/Zod/IPC/N-API bar path (`backtest_datasets.payload` `255 MB` `JSONB` ceiling, `structuredClone`, `fork({ serialization: 'json' })`, and `api/canonical.rs` triple `serde_json::Value` parse). Retain only `(hash, manifest, parquet_paths)` in PostgreSQL, read Parquet/Arrow columns directly inside Rust `Replay`, restrict `canonical.rs` `keys_match` to small control/config envelopes, and stream multi-asset decision-barrier slices to `candidate-sandbox.ts` as compact **Arrow IPC / flat `Float64Array` binary frames** on declared rebalance barriers.
|
||||
- **Long/short, multi-currency margin & corporate actions:** Signed quantities/targets, short borrow fee accrual, `BTreeMap<Currency, Posting>` (`USD` + `CAD` cash/margin balances with IB benchmark+spread interest on negative balances, plus tradable FX pairs), ex-date split share adjustments, cash dividend postings, TSX/TSXV board-lot sizing (`100`/`500`/`1,000` shares), and OTC/Shumway delisting liquidations.
|
||||
|
||||
### Validation suite, Trial Ledger & 6-Month Vault
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue