close

DEV Community

Harrier
Harrier

Posted on

I built a Directional Arbitrage Bot for Polymarket crypto markets in Rust — here's the architecture

Hey everyone,

Sharing a new bot I've been building — it's a directional arbitrage bot for binary prediction markets (BTC/ETH/SOL Up/Down on Polymarket). Written in Rust for the latency requirements this strategy demands.

The core idea

Pure arbitrage on prediction markets is straightforward — if Up + Down < $1, you buy both and lock in the difference. Safe, but the upside is capped at the spread.

This bot starts from that arbitrage structure but adds a directional tilt. If the model identifies that one side has additional edge beyond the arb, it skews the position — buying more of the stronger side and less of the hedge side. The result is:

  • Arbitrage base = structural protection
  • Directional tilt = additional EV when the model has conviction

Why this matters in short crypto markets

BTC/ETH/SOL 5-15 minute markets on Polymarket are interesting because the underlying asset can move sharply while Polymarket's CLOB reprices one side with a delay. That lag is the exploitable window. By the time the order book catches up, a pure arb bot has already exited. A directional bot can hold the stronger side through the reprice and capture the full move.

Architecture (Rust)

rust// Core position structure
struct Position {
    arb_base: f64,      // guaranteed arb fill on both sides
    directional_tilt: f64,  // extra exposure on favored side
    hedge_ratio: f64,   // partial hedge on weaker side
    edge_threshold: f64, // minimum model edge to tilt
}
Enter fullscreen mode Exit fullscreen mode

Key design decisions:

  • Limit orders only — never market orders. Paying the spread kills the arb base immediately
  • Tilt gated by edge threshold — the model has to show meaningful conviction before skewing the position. No tilt = pure arb fallback
  • Hedge ratio is dynamic — scales down as directional confidence increases, never goes to zero
  • Rust for execution — async order management with Tokio, minimal GC pauses, deterministic latency on the quoting loop

Position logic flow

1. Scan CLOB for Up + Down < $1 (arb opportunity exists)
2. Run edge model on both sides
3. If edge delta > threshold → tilt toward stronger side
4. Place limit orders: full size on strong side, hedge_ratio on weak side
5. Monitor fill state and adjust tilt if market moves before fill
Enter fullscreen mode Exit fullscreen mode

The hedge means a wrong directional call doesn't blow up the position — it just reduces the arb profit. The floor is always the arb spread minus fees.

Current limitations

  • Edge model is still rule-based — pattern recognition on price movement sequences. Not ML yet
  • Liquidity on some markets is thin enough that the tilt size is constrained by available depth
  • Correlated markets (BTC and ETH moving together) need net exposure tracking across both, not per-market limits

Why Rust

Polymarket's CLOB API has enough latency variance that the quoting loop needs to be tight. Rust gives deterministic async performance without the GC pauses you'd get in Node or JVM. The order state machine is also complex enough that Rust's ownership model catches a lot of bugs at compile time that would be runtime errors elsewhere.

GitHub: https://github.com/HarrierOnChain/Prediction-Markets-Trading-Bot-Toolkits

Happy to discuss the edge model, position sizing logic, or the Rust async architecture. Also curious if anyone has solved the correlated market exposure problem cleanly.

Top comments (0)