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:
Boki 2026-11-27 00:11:50 -05:00
parent ce9e2df67c
commit 4cd6038063
432 changed files with 1247 additions and 44469 deletions

View file

@ -129,7 +129,18 @@ Plus `resolution_conflict`, `override` (keyed by `(source, source_id, valid_from
### A. DuckDB + Hive Parquet (`/mnt/data/stockbot/curated/`)
All Parquet files use `ZSTD` compression, integer `listing_id` (`INT32`), UTC `TIMESTAMPTZ` (`ts`, `known_at`), and explicit `known_at_source`:
All Parquet files use `ZSTD` compression, integer `listing_id` (`INT32`), UTC `TIMESTAMPTZ` (`ts`, `known_at`), and explicit `known_at_source`.
- **Bulk ETL rule (`tools/curate-etl`):** Multi-hundred-million and multi-billion-row collections (`eodPrices` `846M`, `eodIntraday1M` `3.40B`, `eodIntraday5M` `1.08B`, `qmFilings` `30.5M`) are curated via a dedicated Rust binary in the Cargo workspace (`mongodb::bson::RawDocumentBuf` zero-copy BSON cursors + in-RAM `provider_mapping`/`qmSplits` lookup tables + `rayon` sharded `parquet`/ILP writers)—**never** through single-threaded JS/Node object-allocation loops.
- **DuckDB connection budget:** Every `MarketDataStore` (TS) and `stockbot.data` (Python) DuckDB instance must execute at connection open:
```sql
SET memory_limit = '6GB';
SET threads = 4;
SET temp_directory = '/mnt/data/stockbot/tmp/duckdb';
```
(overridable via env on local dev, e.g. `2GB`/`2` threads) so concurrent campaign workers never inherit DuckDB's default `80%` host-RAM (`~100 GiB`) ceiling.
Schemas:
- **`bars_1d/year=YYYY/part.parquet`**: `(listing_id INT32, ts TIMESTAMPTZ, session_date DATE, open DOUBLE, high DOUBLE, low DOUBLE, close DOUBLE, volume DOUBLE, vwap DOUBLE, currency VARCHAR, source VARCHAR, known_at TIMESTAMPTZ)` — strictly raw OHLC and **un-adjusted** share `volume`, sorted by `(listing_id, session_date)`.
- **`adj_factors/part.parquet`**: `(listing_id INT32, ex_date DATE, split_factor DOUBLE, div_cash DOUBLE, div_currency VARCHAR, cum_split_factor DOUBLE, cum_total_factor DOUBLE, known_at TIMESTAMPTZ)`.
@ -146,7 +157,9 @@ All Parquet files use `ZSTD` compression, integer `listing_id` (`INT32`), UTC `T
### B. QuestDB `10.2.0` (Intraday & Live Streaming)
Image pinned to `questdb/questdb:10.2.0`. `listing_id` is stored as decimal string inside `SYMBOL CAPACITY 65536 NOCACHE` and converted to `number` (`INT32`) at the `MarketDataStore` adapter boundary:
Image pinned to `questdb/questdb:10.2.0`. Host kernel must enforce `vm.max_map_count >= 1048576` (`/etc/sysctl.d/99-stockbot.conf`), container `ulimits.nofile` set to `1048576`, and off-heap memory bounded via `QDB_RAM_USAGE_LIMIT_BYTES=21474836480` (`20 GiB`) + JVM `-Xms2g -Xmx4g` inside a `28g` container `mem_limit` on `quant`.
`listing_id` is stored as decimal string inside `SYMBOL CAPACITY 65536 NOCACHE` and converted to `number` (`INT32`) at the `MarketDataStore` adapter boundary. `bars_1m` uses **`PARTITION BY MONTH`** (`270` partitions / `~3,780` files across 22.5 years at `~13.2M` rows/month, vs. `~5,670` partitions / `~79,000` files under `PARTITION BY DAY`—cutting 1-year `W2` cold partition seeks from 252 to 12 while keeping live monthly WAL `< 40 MB`):
```sql
CREATE TABLE IF NOT EXISTS bars_1m (
@ -161,7 +174,7 @@ CREATE TABLE IF NOT EXISTS bars_1m (
source SYMBOL CAPACITY 8 CACHE, -- 'eod_unadj' | 'qm_raw' | 'ib_live'
known_at TIMESTAMP,
ts TIMESTAMP
) TIMESTAMP(ts) PARTITION BY DAY WAL
) TIMESTAMP(ts) PARTITION BY MONTH WAL
DEDUP UPSERT KEYS(ts, listing_id);
CREATE TABLE IF NOT EXISTS fx_1m (