# `@stock-bot/data-pipeline` Normalizes raw provider collections from MongoDB (`stock`) into canonical PostgreSQL security-master records and curated research datasets. ## Safety & Connection Model - **Port:** `2002` (`PIPELINE_SERVICE_PORT`, default `2002` in `docker-compose.yml` / `docker-compose.dev.yml`). - **Read-Only MongoDB Enforcement:** Bootstraps its DI container with `mongoReadOnly: true`, connecting via `MONGODB_READ_URI` (`studio_stock_bot_read@stock`) and blocking all write, index, and collection-mutation methods at the client wrapper layer. - **Dev vs QA Targets:** - In `development`, reads QA MongoDB read-only and writes only to isolated dev PostgreSQL (`localhost:5433/trading_bot_dev`). `assertEnvironmentSafety()` hard-blocks writable connections to QA MongoDB (`27017/stock`) or QA PostgreSQL (`5432/trading_bot`). - Destructive sync flags (`?clear=true`, `POST /sync/clear`) are restricted in non-test environments; never run destructive clears against `trading_bot`. ## Current Runtime Scope - **MongoDB Inputs:** `exchanges`, `eodExchanges`, `ibExchanges`, `qmExchanges`, `eodSymbols`, `ibSymbols`, `qmSymbols`. - **PostgreSQL Tables (`database/postgres/init/02-exchange-symbol-schema.sql`):** - `exchanges` & `provider_exchange_mappings` - `symbols` & `provider_mappings` - `sync_status` - **HTTP Endpoints (`src/routes/`):** - `GET /health` — liveness & database readiness - `GET /sync/status` & `GET /sync/status/enhanced` — sync state and counts - `POST /sync/exchanges/all` — normalize exchange reference catalog - `POST /sync/symbols/:provider` — sync `qm`, `eod`, or `ib` symbol mappings ## Target Architecture (`Milestone M1` & `M2`) Full specifications live in: - [DATA-CONTRACTS.md](../../../docs/DATA-CONTRACTS.md) — Empirical 31-collection rules, bi-temporal security master (`instruments`, `instrument_listings`, `provider_symbol_map`, `corporate_actions`), Hive Parquet + DuckDB schemas (`bars_1d`, `fundamentals_pit`, `earnings_events_pit`, `short_interest_pit`, `macro_pit`, `fx_rates_1d`), and QuestDB `10.2.0` intraday schema. - [MILESTONES.md](../../../docs/MILESTONES.md) — Step-by-step `M0` (read-only wrapper hardening), `M1` (US + Canada security master & `bars_1d` + `fx_rates_1d` curation), and `M2` (`qmFilings`-backed PIT fundamentals, earnings, short interest, and macro curation). - [phase1-investigation.md](../../../docs/data-pipeline/phase1-investigation.md) — Initial provider exchange/symbol investigation notes. ## Commands Run from the repository root: ```bash # Start pipeline in dev mode (targets localhost:5433/trading_bot_dev) bun run --cwd apps/stock/data-pipeline dev # Typecheck & build bun run typecheck bun run build # Run PostgreSQL environment & read-only MongoDB safety tests bun --env-file=/home/boki/.studio/test-env/stock-bot.env test test/postgres/pipeline-safety.test.ts ```