stock-bot/AGENTS.md
2026-11-26 22:23:07 -05:00

3.9 KiB
Raw Blame History

Stock Bot — Studio Agent Guide

Runtime & Tooling

  • Use Bun (bun, bun test, bun run) and Turbo (turbo) for builds, scripts, and tests.
  • Build: bun run build
  • Typecheck: bun run typecheck
  • Tests: bun test (PostgreSQL safety tests require PIPELINE_TEST_DATABASE_URL pointing to a dedicated stock_bot_safety* database, configured via /home/boki/.studio/test-env/stock-bot.env).

Environments (dev / qa / prod)

Environment NODE_ENV Compose File PostgreSQL MongoDB (Write) MongoDB (Read / Pipeline) Dragonfly QuestDB
dev development docker-compose.dev.yml localhost:5433 (trading_bot_dev) localhost:27018 (stock_dev) localhost:27017 (stock, read-only via MONGODB_READ_URI) localhost:6380 localhost:9100
qa qa docker-compose.yml localhost:5432 (trading_bot) localhost:27017 (stock) localhost:27017 (stock) localhost:6379 localhost:9000
prod production docker-compose.prod.yml Separate host (env-driven) Separate host (env-driven) Separate host (MONGODB_READ_URI optional) Env-driven Env-driven

Data Flow & Strict Safety Rules

  1. QA MongoDB (stock-bot_mongodb_data on localhost:27017, database stock) holds the full ingested multi-billion-document dataset. NEVER drop, reset, or write to QA MongoDB from dev or automated tests.
    • Never run docker compose down -v against docker-compose.yml.
    • ./scripts/docker.sh reset is hard-blocked for qa and prod.
  2. data-pipeline reads MongoDB and writes master records to PostgreSQL.
    • apps/stock/data-pipeline initializes its container with mongoReadOnly: true, which uses database.mongodb.readUri (MONGODB_READ_URI) when set and rejects all MongoDB write/index/collection-mutation operations at the client layer.
    • In dev, data-pipeline reads QA MongoDB read-only (studio_stock_bot_read@stock) and writes master records into isolated dev PostgreSQL (localhost:5433/trading_bot_dev).
  3. data-ingestion writes raw provider data to MongoDB.
    • In dev, data-ingestion must target isolated dev MongoDB (localhost:27018/stock_dev).
    • assertEnvironmentSafety() in apps/stock/config/src/env-safety.ts blocks development services from opening writable connections to QA MongoDB (27017/stock) or QA PostgreSQL (5432/trading_bot).
  4. Tests must never mutate QA Postgres (trading_bot) or QA MongoDB (stock). Use isolated schemas in stock_bot_safety* or in-memory/testcontainer databases.

Key Modules

  • apps/stock/data-ingestion: Provider crawlers/ingesters writing raw documents into MongoDB.
  • apps/stock/data-pipeline: Processes raw MongoDB documents into normalized master records in PostgreSQL (exchanges, symbols, provider_exchange_mappings, provider_mappings, sync_status).
  • apps/stock/config & libs/core/config: Environment config schemas (development, qa, test, production) and startup safety guards.
  • apps/stock/web-api & apps/stock/web-app: API and dashboard UI.
  • apps/stock/orchestrator & apps/stock/engine: Backtest/paper/live orchestration and Rust execution engine.

Documentation

  • docs/README.md: Documentation index and navigation map.
  • docs/PLATFORM-PLAN.md: Target platform architecture and locked decisions (D1–D12).
  • docs/MILESTONES.md: Ordered M0–M5 build plan, file targets, and exit criteria.
  • docs/DATA-CONTRACTS.md: Empirical MongoDB provider rules, PostgreSQL security master, DuckDB/Parquet, and QuestDB 10.2.0 schemas.
  • docs/VALIDATION-AND-RIGOR.md: Canonical metrics, trial_ledger, DSR/PBO/CPCV math, 6-month vault + post-2023 recency gate, and IBKR Margin (USD/CAD) execution rules.
  • docs/servers.md: Hardware and container topology (quant 10.0.0.51, 9900K, TrueNAS, local dev).