Rust trading automation for Polymarket short-horizon crypto and related markets. The workspace ships multiple binaries: dual-limit starters, a trailing stop strategy, backtests, and small utilities to validate balance, allowance, orders, merge, and redemption against the CLOB.
The bot loads a JSON config and optional .env secrets, authenticates to Polymarket’s CLOB (including proxy wallet modes), and runs strategies with simulation, live, or backtest / history-replay options. A native CLOB SDK is loaded at runtime; Linux deployments should use SDK builds matched to the host glibc (or Docker).

https://github.com/user-attachments/assets/9e20bab4-431e-4f8d-8a69-147a34b7ea3b
test_* binaries for cash balance, allowance, limits, sell, merge, redeem, and multi-order checks.Dockerfile for environments where glibc and bundled SDK layout must match.rust-toolchain.toml / Cargo.toml for MSRV relative to alloy and dependencies; rustc 1.91+ is expected for this tree)reqwest, tokio-tungstenite where usedlibloading (see Technical details)config.json (non-secrets) plus .env for keys (see Installation)Load config + .env → L1/L2 CLOB auth → Market polling / strategy
→ Order placement (or simulation) → Logs + optional history / backtest
rustc (e.g. 1.91+ for current dependencies).lib/libclob_sdk-ubuntu-22.04.so and lib/libclob_sdk-ubuntu-24.04.so on Linux, or libclob_sdk.dylib / clob_sdk.dll on macOS / Windows, or set LIBCOB_SDK_SO to an explicit path.bash
git clone <repository-url>
cd Polymarket-Trading-Bot-Rust
bash
cargo build --release
config.jsonbash
cp config.example.json config.json
Edit config.json for trading intervals, enabled assets, dual-limit parameters, and base API URLs. Prefer not pasting private_key in the file; use .env instead.
.envbash
# RUST_LOG=info
POLYMARKET_PRIVATE_KEY=0xYOUR_KEY
POLYMARKET_SIGNATURE_TYPE=2
POLYMARKET_PROXY_WALLET_ADDRESS=0xYOUR_PROXY_OR_SAFE
POLYMARKET_API_KEY_NONCE=0
# Optional: LIBCOB_SDK_SO=/absolute/path/to/libclob_sdk.so
bash
docker build -t polymarket-trading-bot .
docker run --rm -it --env-file .env \
-v "$(pwd)/config.json:/app/config.json:ro" \
polymarket-trading-bot
config.json (summary)| Section | Role |
|---|---|
polymarket |
gamma_api_url, clob_api_url, optional inline secrets (prefer env) |
trading |
Polling, dual-limit price/shares, hedge timing, trailing options, and enable_*_trading flags |
See config.example.json for the full shape.
| Variable | Description |
|---|---|
POLYMARKET_PRIVATE_KEY |
Hex private key (with or without 0x) for live auth and orders |
POLYMARKET_SIGNATURE_TYPE |
0 EOA, 1 proxy, 2 browser / Safe style proxy (typical for MetaMask + Polymarket proxy) |
POLYMARKET_PROXY_WALLET_ADDRESS |
Funder / proxy when using types 1 or 2 |
POLYMARKET_API_KEY / SECRET / PASSPHRASE |
Optional cached L2 API credentials; otherwise derived via L1 auth |
POLYMARKET_API_KEY_NONCE |
Optional nonce for stable derived API keys |
LIBCOB_SDK_SO |
Override path to the CLOB SDK shared library |
RUST_LOG |
Log level: error, warn, info, debug, trace |
src/config.rs Args)| Flag | Role |
|---|---|
--config |
Path to JSON config (default config.json) |
--simulation / -s |
Simulation (no real trades) where applicable |
--no-simulation |
Force live mode |
--backtest |
Backtest mode |
--history-file |
Replay a history/*.toml file |
default-run in Cargo.toml)cargo run --release -- --config config.json
cargo run --release --bin main_dual_limit_045_same_size -- --config config.json --no-simulation
cargo run --release --bin main_dual_limit_045_5m_btc -- --config config.json
cargo run --release --bin main_trailing -- --config config.json
cargo run --release --bin backtest -- --config config.json
cargo run --release --bin test_allowance -- --config config.json
cargo run --release --bin test_limit_order -- --config config.json
cargo run --release --bin test_merge -- --config config.json
cargo run --release --bin test_redeem -- --config config.json
cargo run --release --bin test_sell -- --config config.json
cargo run --release --bin test_predict_fun -- --config config.json
See Cargo.toml [[bin]] for registered binary names.
.so built on Ubuntu 24.04 on an Ubuntu 22.04 host) are not fixed by changing the Rust toolchain. Use versioned lib/ artifacts, LIBCOB_SDK_SO, Docker, or an SDK built on the same glibc as production.trading in config.json.src/bin/*.rs for entry points.Polymarket-Trading-Bot-Rust/
├── public/
│ ├── trading-rust.png # README / demo still (add asset)
│ └── trading-rust.mp4 # optional local demo
├── lib/ # CLOB SDK .so / .dylib / .dll (not always in repo)
├── history/ # local price history / replay (gitignored)
├── src/
│ ├── lib.rs
│ ├── config.rs
│ ├── clob_sdk.rs
│ ├── api.rs
│ ├── trader.rs
│ ├── monitor.rs
│ ├── detector.rs
│ ├── merge.rs
│ ├── rtds.rs
│ ├── backtest.rs
│ ├── simulation.rs
│ ├── term_ui.rs
│ ├── models.rs
│ └── bin/
│ ├── main_dual_limit_045_same_size.rs
│ ├── main_dual_limit_045_5m_btc.rs
│ ├── main_trailing.rs
│ ├── backtest.rs
│ └── test_*.rs
├── config.example.json
├── rust-toolchain.toml
├── Cargo.toml
├── Dockerfile
└── README.md
config.json under polymarket.*.src/.RUST_LOG for env_logger output levels.Maintenance notes worth tracking in this repo:
rustc beyond upstream SDK baselines.LIBCOB_SDK_SO and lib/ layout are deployment-specific; document the host OS when sharing issues.Operational suggestions: Prove simulation and backtest first, use Docker when glibc is uncertain, and keep API keys and config.json out of version control if they hold secrets.
cargo check
cargo build --release
Use repository issues for bugs and feature requests. For CLOB and Gamma behavior, use Polymarket’s official documentation.
Disclaimer: This software is provided as-is, without warranty. Prediction markets and digital assets involve substantial risk of loss. Use only capital you can afford to lose and comply with applicable laws in your jurisdiction.
Version: 0.1.0
Last updated: April 2026
$ claude mcp add Polymarket-Trading-Bot-Rust \
-- python -m otcore.mcp_server <graph>