How andydoc/prediction-trading works
Project type & purpose (from file tree + README)
This is a Python-based prediction-market trading system that appears to support multiple platforms/strategies and at least two operating modes:
• Live trading (live_trading.py)
• Paper trading (paper_trading.py)
The architecture is explicitly layered/pipelined:
• layer1_market_data/ → ingest/normalize market data
• layer2_constraint_detection/ → validate feasibility / detect constraints
• layer3_arbitrage_math/ → compute opportunities / sizing via an arbitrage engine
• Runners (layer1_runner.py, layer2_runner.py, layer3_runner.py, layer4_runner.py) → orchestration across layers
There is also clear infrastructure for:
• WebSocket connectivity (websocket_manager.py, test_clob_connect.py)
• Execution control & coordination (execution_control.py, execution_control_client.py)
• Trading engine orchestration (trading_engine.py, main.py)
• Dashboard/monitoring server (dashboard_server.py)
• Config-driven runtime (config/config.yaml)
• Ops scripts for starting/stopping, VPS setup, health checks, etc. (scripts/, start_all.sh, setup.ps1)
Trading Orchestrator
• main.py (entrypoint)
• trading_engine.py (core coordinator)
• Mode selectors:
• live_trading.py
• paper_trading.py
Market Data Ingestion Container
• websocket_manager.py (WS connectivity lifecycle)
• layer1_market_data/market_data.py
• orderbook_depth.py (order book depth handling)
• resolution_validator.py (data sanity / resolution checks)
Strategy / Decision Pipeline
This explicitly as a pipeline of containers or as one container with internal components:
• Layer 1 Runner: layer1_runner.py
• Layer 2 Runner: layer2_runner.py
• Layer 3 Runner: layer3_runner.py
Constraint & Opportunity Engines
• layer2_constraint_detection/constraint_detector.py
• layer3_arbitrage_math/arbitrage_engine.py
Execution Control Plane
• execution_control.py (server/controller)
• execution_control_client.py (client used by engine or tools)
Observability / UI
• dashboard_server.py (monitoring/ops UI service)
Configuration
• config/config.yaml (runtime config)
• config/ (config package)
Ops / Lifecycle Scripts (non-runtime, but important)
• start_all.sh, setup.ps1
• scripts/START_TRADER*.bat, scripts/STOP_TRADER.bat, scripts/status.sh, etc.
• VPS/bootstrap: scripts/setup_vps.sh, scripts/cloud_init_oracle*.sh
• Market Data Ingestion → Strategy Pipeline (normalized market snapshots/events)
• Strategy Pipeline → Execution (orders/cancels)
• Execution Control ↔ Trading Orchestrator (pause/resume/kill-switch, mode changes)
• Trading Orchestrator → Dashboard Server (metrics/events), or Dashboard pulls from it (pick one and label “push” vs “pull”)
• Config → all runtime containers (read at startup; some may reload)
Goal: reflect the repo’s most distinctive structure: the layered runners + engines.
Layer 1: Market Data
• WebsocketManager (websocket_manager.py)
• MarketData (layer1_market_data/market_data.py)
• OrderbookDepth (orderbook_depth.py)
• Outputs: “Orderbook snapshots”, “Trades”, “Market state events”
Layer 2: Constraint Detection
• ConstraintDetector (layer2_constraint_detection/constraint_detector.py)
• Inputs: market state
• Outputs: “Feasible set”, “Filtered opportunities”, “Constraint violations”
Layer 3: Arbitrage Math
• ArbitrageEngine (layer3_arbitrage_math/arbitrage_engine.py)
• Inputs: feasible/filtered state
• Outputs: “Candidate trades”, “Sizing”, “Expected value/edge”
Layer 4: (Execution / Portfolio / Risk)
• layer4_runner.py as:
• “Execution + risk checks + order management” (until you confirm actual contents)
• Outputs: orders to external venue OR simulated fills in paper mode
Cross-cutting
• resolution_validator.py as a validator stage (either between L1→L2 or as part of L1)
• execution_control_client.py as a control input into runners (“pause”, “throttle”, “shutdown”)
• “WS event” → “normalized tick/orderbook”
• “constraints” → “trade candidates”
• “trade candidates” → “orders”
Relationships & interactions to highlight (what matters architecturally)
For accuracy, emphasize these interaction categories:
Data plane (high-throughput)
• WebSocket feeds → parsing → order book state → analytics
• Usually asynchronous/event-driven; represent this with:
Control plane (safety & operations)
• execution_control.py / execution_control_client.py
• Start/stop scripts
• Dashboard server
This is often overlooked; in trading systems it’s critical—show it explicitly separate from the data plane.
Mode switching
• Live vs paper trading: show a branch:
• Live path → external venue execution
• Paper path → simulated fills + PnL/accounting (you have scripts/accounting.py which hints at accounting workflows)
• Python runtime (entire repo)
• WebSockets (websocket_manager.py, check_ws_*.sh, test_ws_import.sh)
• YAML configuration (config/config.yaml)
• OS scripting / deployment tooling
• Bash (*.sh)
• Windows scripts (*.bat, *.vbs)
• PowerShell (setup.ps1)
• Cloud/VPS bootstrapping (Oracle hinted by cloud_init_oracle*.sh)
Container: “Processes/services/modules and how they connect”
3) Component (Pipeline): “Layer1→Layer4 detailed flow, including validators and control hooks”