Production-focused Rust trading system for Polymarket 5m/15m workflows. This repository is organized for long-term maintainability: clean module boundaries, multiple runtime entrypoints, and operational binaries for trading lifecycle tasks.
Watch the bot in action:
polymarket-arb-bot-v2.mp4
- What This Project Is
- Key Capabilities
- Architecture
- Execution Flows
- Repository Layout
- Prerequisites
- Quick Start
- Configuration
- Run Modes and Binaries
- Tools and Operational Binaries
- Backtesting Workflow
- Deployment Guidance
- Troubleshooting
- Security and Risk Controls
- Development Standards
- Roadmap
- License
Polymarket Arbitrage Bot V2 is a modular execution framework for event-driven market trading on Polymarket CLOB infrastructure.
It is a multi-binary system with:
- strategy runtime executables (
src/bin/live) - research executables (
src/bin/research) - operational executables (
src/bin/tools) - reusable engine components (
src/core,src/engine,src/strategy,src/connectors,src/analytics) This structure allows strategy evolution without destabilizing execution infrastructure.
- Pre-order and dual-limit style workflows for short-duration markets.
- 5-minute BTC-specific runtime variant.
- Trailing strategy runtime variant.
- Simulation mode for dry-run validation.
- Backtest mode for historical replay and analysis.
- Utility binaries for allowance, redeem, merge, and sell workflows.
- Layered architecture to isolate strategy, execution, and transport.
- Support for operator-first workflows with deterministic tools.
The codebase follows layered architecture to separate concerns, reduce coupling, and improve operational debuggability.
Purpose: foundational contracts shared by all higher layers.
config.rsdefines runtime configuration schema and loading behavior.models.rsdefines shared typed market/order/trade entities.clob_sdk.rsdefines low-level SDK integration boundary. Engineering intent:- keep this layer stable and generic,
- avoid strategy-specific branching,
- keep interfaces explicit and typed.
Purpose: all external integrations and protocol adaptation.
api.rshandles Polymarket API integration patterns.rtds.rshandles real-time feed adaptation. Engineering intent:- isolate transport concerns,
- normalize external payloads,
- prevent connector details from leaking into strategy logic.
Purpose: orchestrate runtime loops and side-effectful execution.
monitor.rsdrives market monitoring and time-window checks.trader.rsexecutes order lifecycle actions and transitions. Engineering intent:- engine owns sequencing and state transitions,
- strategy emits intent and policy,
- trading side effects remain centralized.
Purpose: evaluate opportunities and produce decision outcomes.
detector.rscontains entry/trigger decision logic.merge.rscontains merge and strategy-specific position logic. Engineering intent:- strategy modules should be testable in isolation,
- strategy code should avoid direct network calls,
- policy should be configurable rather than hard-coded.
Purpose: simulation and replay/backtest workflows.
simulation.rscontains simulation behavior and metrics semantics.backtest.rscontains historical replay logic. Engineering intent:- reuse models/policies from runtime paths where feasible,
- keep research code from contaminating live execution branches.
Purpose: executable-level composition and mode-specific startup.
live/contains strategy runtime binaries.research/contains backtest binaries.tools/contains operational utility binaries. Engineering intent:- keep binaries thin,
- compose modules, do not duplicate domain logic,
- preserve single responsibility per executable.
- Config and CLI flags initialize runtime contracts.
- Connectors create external communication channels.
- Monitor loop captures current market state.
- Strategy evaluates state and emits action intents.
- Trader converts intents into controlled order actions.
- Logs/artifacts are stored for audit and replay.
- Faster onboarding: clear separation by ownership boundaries.
- Faster debugging: incidents map naturally to one layer.
- Safer releases: strategy changes can ship without connector rewrites.
- Better operations: tool binaries isolate high-risk manual tasks.
- Parse CLI arguments and load config.
- Initialize API and streaming connectors.
- Start market monitor loop.
- Build normalized snapshots.
- Evaluate strategy detector logic.
- Submit/cancel/hedge through trader engine.
- Record logs and outcome artifacts.
Operational binaries run single-purpose tasks:
- allowance checks/approval,
- explicit order tests,
- redeem/merge operations,
- targeted diagnostics. This is safer than editing production strategy binaries for ad-hoc tasks.
- Read history inputs from
history/. - Replay strategy behavior in controlled mode.
- Compare outcomes to live assumptions.
- Promote parameter changes only with replay evidence.
Polymarket-Trading-Bot-Rust-V2/
├── src/
│ ├── core/
│ │ ├── config.rs
│ │ ├── models.rs
│ │ └── clob_sdk.rs
│ ├── connectors/
│ │ ├── api.rs
│ │ └── rtds.rs
│ ├── engine/
│ │ ├── monitor.rs
│ │ └── trader.rs
│ ├── strategy/
│ │ ├── detector.rs
│ │ └── merge.rs
│ ├── analytics/
│ │ ├── backtest.rs
│ │ └── simulation.rs
│ └── bin/
│ ├── live/
│ ├── research/
│ └── tools/
├── config.example.json
├── config.json
└── history/
- Stable Rust toolchain.
- Valid Polymarket API credentials.
- Trading wallet credentials and sufficient network balances.
- Correct permissions for all wallet actions used in your flow.
cp config.example.json config.jsonEdit config.json with credentials and strategy parameters.
cargo build --releasecargo run -- --simulationcargo run -- --no-simulationconfig.json is the operational contract for runtime behavior.
Minimum validation checklist:
- API key fields and endpoints.
- wallet identity and signing config.
- strategy thresholds and position size controls.
- interval and timing settings. Recommended operator practices:
- keep separate configs for
dev,paper, andprod, - require review for parameter changes,
- avoid promoting experimental thresholds without replay evidence.
cargo run -- --simulation
cargo run -- --no-simulationcargo run --bin main_dual_limit_045_5m_btc -- --simulationcargo run --bin main_trailing -- --simulationcargo run --bin backtest -- --backtestBinaries in src/bin/tools/:
test_allowancetest_cash_balancetest_limit_ordertest_mergetest_multiple_orderstest_predict_funtest_redeemtest_sellExample:
cargo run --bin test_allowance -- --approve-only- Prepare artifacts under
history/. - Run backtest binary:
cargo run --bin backtest -- --backtest- Compare outcomes against current live assumptions.
- Promote parameter changes only after deterministic review.
For PM2/systemd style process managers:
- run with explicit working directory,
- pin executable and mode,
- capture and rotate logs,
- avoid uncontrolled auto-restarts during critical market windows. Production rollout pattern:
- Validate in simulation.
- Run constrained canary live session.
- Increase exposure only after expected behavior is confirmed.
- Check mode flags (
--simulationvs--no-simulation). - Check market eligibility windows.
- Confirm API and wallet permissions.
- Verify thresholds are not too restrictive.
- Inspect detector parameters.
- Confirm monitor receives real-time snapshots.
- Check logs for guardrail-triggered skip conditions.
- Confirm same config parameters were used.
- Validate timestamp alignment and dataset quality.
- Recheck assumptions for slippage and fill behavior.
- Never commit secrets or private keys.
- Test every change in simulation first.
- Use dedicated trading wallets.
- Apply external notional and risk caps.
- Keep auditable logs for all live sessions.
- Define emergency stop procedures before scaling exposure.
- Keep strategy logic in
src/strategy. - Keep external integrations in
src/connectors. - Keep side effects and sequencing in
src/engine. - Keep binaries thin and orchestration-focused.
- Prefer additive, testable, layer-aligned changes. Recommended engineering workflow:
- update strategy code,
- run simulation,
- run backtest,
- perform constrained live validation,
- promote after review.
- Expand strategy plugin boundaries.
- Improve structured runtime metrics.
- Add more deterministic replay harness coverage.
- Strengthen operational alerting hooks.
Use according to your repository and organizational licensing policy.