Skip to content

miracle709/polymarket-arbitrage-bot--version1.0

Repository files navigation

Polymarket Speed Arbitrage Bot

A production-ready Python bot exploiting the ~2.7-second lag between Binance price moves and Polymarket odds updates on short-duration BTC/ETH markets.

⚠️ Important Disclaimers

  1. Run in paper trading mode for at least 1 week before going live
  2. This edge is time-limited — the lag may narrow or disappear as the market matures
  3. Monitor win rate closely — if it drops below ~60%, stop and investigate
  4. Never risk capital you cannot afford to lose
  5. Ensure your use of Polymarket complies with their Terms of Service and your local regulations

Support

👉 Contact: Miacle709 📞

Monitoring


The POLYARB web dashboard (default port in .env, e.g. http://localhost:8080) shows run status, KPIs (balance, drawdown, win rate, latency, PnL, max bet), pause / resume / kill, and a recent-trades table.

POLYARB Bot dashboard

  • Dashboard: http://localhost:8080
  • Pause trading: curl -X POST http://localhost:8080/api/pause
  • Resume: curl -X POST http://localhost:8080/api/resume
  • Kill: curl -X POST -H "X-Confirm-Kill: CONFIRM" http://localhost:8080/api/kill
  • Stats JSON: curl http://localhost:8080/api/stats
  • Health JSON: curl -i http://localhost:8080/api/health (returns 503 if degraded)
  • Recent trades: curl http://localhost:8080/api/trades?n=20
  • Periodic status logs: logs/status_YYYY-MM-DD.jsonl (stats + health snapshots)
  • Daily summaries: logs/daily_summary_YYYY-MM-DD.json

Architecture

BinanceFeed (WebSocket) ──signals──► PolymarketTrader ──orders──► Polymarket CLOB
                                           │
                                     RiskManager (Kelly + Kill Switch)
                                           │
                                     DashboardServer (HTTP :8080)
                                           │
                                     TradeLogger (JSONL files)

Quick Start

1. Clone and install

git clone <repo>
cd polymarket-arbitrage-bot
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configure

cp .env.example .env
# Edit .env — at minimum set PAPER_TRADING=true to start

3. Run the simulator (recommended first step)

python simulator.py --days 7 --asset BTCUSDT --threshold 0.15
# Outputs simulation_results.json with win rate, PnL, drawdown stats

4. Start the bot in paper trading mode

python main.py
# Dashboard: http://localhost:8080

Optional preflight check (recommended before service start):

python main.py --check-config

5. Go live (only after ≥1 week paper trading with >60% win rate)

# In .env:
PAPER_TRADING=false
POLYMARKET_PRIVATE_KEY=0x...
POLYMARKET_API_KEY=...
POLYMARKET_API_SECRET=...
POLYMARKET_API_PASSPHRASE=...

VPS Deployment (Ubuntu 22.04)

Systemd service

sudo cp polymarket-arb.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable polymarket-arb
sudo systemctl start polymarket-arb
sudo journalctl -u polymarket-arb -f    # follow logs

Recommended VPS specs

  • Location: AWS us-east-1 or eu-west-1 (close to Binance/Polymarket CDN)
  • RAM: 2 GB minimum
  • CPU: 2 vCPUs
  • Network: Low-latency provider (Hetzner, Vultr, AWS Lightsail)

Latency optimisation tips

  1. Use a VPS in the same region as Binance's WebSocket servers
  2. Enable TCP_NODELAY (already set in websockets library)
  3. Prefer IPv4 over IPv6 for WebSocket connections
  4. Monitor avg_latency_ms on the dashboard; aim for <50ms

File Structure

main.py                   # Entry point, asyncio orchestrator
config.py                 # All parameters, loaded from .env
state.py                  # Shared mutable state (thread-safe)
binance_feed.py           # Binance WebSocket feed + signal detection
polymarket_trader.py      # Signal processing + CLOB order placement
risk_manager.py           # Kelly sizing, kill switch, daily limits
logger.py                 # Structured logging + JSONL trade journal
dashboard_server.py       # aiohttp HTTP dashboard
simulator.py              # Standalone paper trading simulator
logs/
├── bot.log               # Human-readable rolling log
└── trades_YYYY-MM-DD.jsonl  # Machine-readable trade journal

Risk Controls

Control Default Description
Kill switch -40% drawdown Stops all trading permanently
Daily pause -10% daily Pauses until next UTC day
Max open positions 3 Concurrent bet limit
Min edge 3% Minimum edge required to enter
Fractional Kelly 0.25× Reduces variance vs full Kelly
Max bet $50 Hard cap per trade
Signal staleness 200ms Discard signals older than this

Analysing Trade Logs

The JSONL trade log is easy to analyse with pandas:

import pandas as pd
df = pd.read_json("logs/trades_2025-12-01.jsonl", lines=True)
entries = df[df.event == "ENTRY"]
print(entries.groupby("asset")[["edge", "size_usd"]].mean())

Polymarket API Setup

  1. Create a Polygon wallet (MetaMask or hardware wallet)
  2. Fund with USDC on Polygon network
  3. Visit https://polymarket.com and connect wallet
  4. Generate API credentials: https://docs.polymarket.com/#authentication
  5. For order signing, review EIP-712 signing in polymarket_trader.py (or use the official py-clob-client library)

Edge Calibration

After 1 week of paper trading, calibrate _estimate_fair_prob() in polymarket_trader.py to match your actual observed win rate per move size:

# Example calibration from paper trading results:
# move_pct=0.15 → actual win rate 63% → set base to 0.63
# move_pct=0.30 → actual win rate 71% → check curve shape
# move_pct=0.50 → actual win rate 79%

This is the most important tuning step for live profitability.

About

Python bot that trades short-duration Polymarket BTC/ETH Up/Down markets using Binance WebSocket price moves, with paper trading, Kelly-based risk controls, and a local HTTP dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages