Skip to content

feat: Rust rewrite of Polymarket arbitrage bot with backtesting#7

Open
dsb4 wants to merge 3 commits intoGabagool2-2:mainfrom
dsb4:claude/rust-bot-rewrite-C9k2P
Open

feat: Rust rewrite of Polymarket arbitrage bot with backtesting#7
dsb4 wants to merge 3 commits intoGabagool2-2:mainfrom
dsb4:claude/rust-bot-rewrite-C9k2P

Conversation

@dsb4
Copy link

@dsb4 dsb4 commented Mar 10, 2026

Complete rewrite of rarb in Rust (rust-bot/). Key improvements:

Architecture:

  • tokio async runtime with mpsc channels instead of asyncio callbacks
  • Arc<Mutex<>> for shared state with single-lock balance+circuit-breaker checks to eliminate the TOCTOU race in the Python version
  • All-Decimal arithmetic (no f64 mixing that caused precision loss)
  • Config loaded once as Arc — no global mutable singleton

Fixes vs Python:

  • TOCTOU race: balance check and deduction now under single lock guard
  • Float precision: rust_decimal::Decimal throughout, no float conversions
  • Zombie WS: built into receive loop timeout (no separate watchdog task)
  • Global settings singleton replaced with immutable Arc

New features:

  • Backtesting engine: fetches 1-min price history, simulates arb detection with 0.2% slippage + 1% fee model, computes Sharpe/drawdown/win-rate
  • Demo backtest with synthetic data (no API key needed): rarb backtest --demo
  • AUDIT.md: detailed security/accuracy audit of changes vs Python

Crypto:

  • Native EIP-712 signing via k256 + sha3 (no Python FFI)
  • HMAC-SHA256 L2 auth via hmac + sha2 (auditable, no external client)

CLI: rarb run | backtest | config | status

https://claude.ai/code/session_01PsfoUzGqnBn1DSxM8x8Cw1

claude added 3 commits March 10, 2026 22:02
Complete rewrite of rarb in Rust (rust-bot/). Key improvements:

Architecture:
- tokio async runtime with mpsc channels instead of asyncio callbacks
- Arc<Mutex<>> for shared state with single-lock balance+circuit-breaker checks
  to eliminate the TOCTOU race in the Python version
- All-Decimal arithmetic (no f64 mixing that caused precision loss)
- Config loaded once as Arc<Config> — no global mutable singleton

Fixes vs Python:
- TOCTOU race: balance check and deduction now under single lock guard
- Float precision: rust_decimal::Decimal throughout, no float conversions
- Zombie WS: built into receive loop timeout (no separate watchdog task)
- Global settings singleton replaced with immutable Arc<Config>

New features:
- Backtesting engine: fetches 1-min price history, simulates arb detection
  with 0.2% slippage + 1% fee model, computes Sharpe/drawdown/win-rate
- Demo backtest with synthetic data (no API key needed): `rarb backtest --demo`
- AUDIT.md: detailed security/accuracy audit of changes vs Python

Crypto:
- Native EIP-712 signing via k256 + sha3 (no Python FFI)
- HMAC-SHA256 L2 auth via hmac + sha2 (auditable, no external client)

CLI: `rarb run | backtest | config | status`

https://claude.ai/code/session_01PsfoUzGqnBn1DSxM8x8Cw1
Covers quick start, config reference, CLI usage, backtest output example,
architecture overview, and key design decisions.

https://claude.ai/code/session_01PsfoUzGqnBn1DSxM8x8Cw1
Add detailed backtest section covering:
- Demo vs live mode with concrete examples
- Full flags table with defaults
- Metric explanations (Sharpe, drawdown, win rate, etc.)
- Simulation assumptions (slippage, fees, cooldown, capital constraint)
- Tuning guidance using backtest results
- JSON output schema with example

https://claude.ai/code/session_01PsfoUzGqnBn1DSxM8x8Cw1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants