A Rust-based arbitrage bot for Polymarket that monitors ETH and BTC 15-minute price prediction markets and executes trades when arbitrage opportunities are detected.
The bot continuously monitors two markets:
- ETH 15-minute price change prediction market
- BTC 15-minute price change prediction market
The bot looks for opportunities where the sum of two complementary tokens (one from each market) is less than $1.00.
Example:
- ETH Up token: $0.47
- BTC Down token: $0.40
- Total cost: $0.87
- Expected profit: $0.13 (when market closes, one token will be worth $1.00)
When such an opportunity is detected, the bot:
- Purchases the Up token in the ETH market
- Purchases the Down token in the BTC market
- Waits for market resolution to realize profit
- API Client (
api.rs): Handles communication with Polymarket's Gamma API and CLOB API - Market Monitor (
monitor.rs): Continuously fetches market data for both ETH and BTC markets - Arbitrage Detector (
arbitrage.rs): Analyzes prices and identifies arbitrage opportunities - Trader (
trader.rs): Executes trades in simulation or production mode
-
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Build the project:
cargo build --release
-
Configure the bot:
- Edit
config.json(created on first run) or use command-line arguments - Set
eth_condition_idandbtc_condition_idif you know them - Otherwise, the bot will attempt to discover them automatically
- Edit
Test the bot without executing real trades:
cargo run -- --simulationExecute real trades (requires API key):
cargo run -- --no-simulation--simulation/--no-simulation: Toggle simulation mode--config <path>: Specify config file path (default:config.json)
The bot creates a config.json file on first run with the following structure:
{
"polymarket": {
"gamma_api_url": "https://gamma-api.polymarket.com",
"clob_api_url": "https://clob.polymarket.com",
"ws_url": "wss://clob-ws.polymarket.com",
"api_key": null
},
"trading": {
"min_profit_threshold": 0.01,
"max_position_size": 100.0,
"eth_condition_id": null,
"btc_condition_id": null,
"check_interval_ms": 1000
}
}Important Settings:
min_profit_threshold: Minimum profit (in dollars) required to execute a trademax_position_size: Maximum amount to invest per tradecheck_interval_ms: How often to check for opportunities (in milliseconds)api_key: Your Polymarket API key (required for production mode)
- Market Discovery: The bot searches for active ETH and BTC 15-minute markets using Polymarket's Gamma API
- Price Monitoring: Continuously fetches order book data to get current ask prices for Up/Down tokens
- Arbitrage Calculation: For each combination (ETH Up + BTC Down, ETH Down + BTC Up), calculates total cost
- Opportunity Detection: If total cost < $1.00 and profit >=
min_profit_threshold, executes trade - Trade Execution: Places simultaneous buy orders for both tokens
- The bot runs continuously until stopped (Ctrl+C)
- In simulation mode, all trades are logged but not executed
- The bot automatically discovers condition IDs if not provided in config
- Make sure you have sufficient balance and API permissions for production trading