Skip to content

polymarket arbitrage trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot

License

Notifications You must be signed in to change notification settings

crymeer/polymarket-arbitrage-bot

Repository files navigation

Polymarket Arbitrage Bot

Production-ready Python trading bot for Polymarket with gasless transactions and real-time WebSocket orderbook streaming.

Repository: https://github.com/crymeer/polymarket-arbitrage-bot

Features

  • Gasless Trading - Builder Program integration for zero gas fees
  • Real-time WebSocket - Live orderbook updates and market data
  • 15-Minute Markets - Built-in support for BTC/ETH/SOL/XRP markets
  • Flash Crash Strategy - Pre-built volatility trading strategy
  • Secure Storage - PBKDF2 + Fernet encrypted private key storage
  • Simple API - Clean, intuitive Python interface

Quick Start

Configuration

Set environment variables:

export POLY_PRIVATE_KEY=your_private_key
export POLY_PROXY_WALLET=0xYourPolymarketProxyWallet

Safe Address: Find at polymarket.com/settings

Easy Run (Recommended)

Windows:

# Interactive menu (best option)
python run.py

# Or use batch files
run_bot.bat          # Run trading bot
run_viewer.bat       # View orderbook (no trading)
quick_start.bat      # Quick start with defaults

Linux/Mac:

python run.py        # Interactive menu

Manual Run

python apps/flash_crash_runner.py --coin BTC

Trading Strategies

Flash Crash Strategy

Monitors 15-minute markets for sudden probability drops and executes trades automatically.

# Default settings
python apps/flash_crash_runner.py --coin BTC

# Custom parameters
python apps/flash_crash_runner.py --coin ETH --drop 0.25 --size 10 --take-profit 0.10 --stop-loss 0.05

Parameters:

  • --coin - BTC, ETH, SOL, XRP (default: ETH)
  • --drop - Drop threshold (default: 0.30)
  • --size - Trade size in USDC (default: 5.0)
  • --lookback - Detection window in seconds (default: 10)
  • --take-profit - Take profit in dollars (default: 0.10)
  • --stop-loss - Stop loss in dollars (default: 0.05)
  • --speed - Main loop interval in seconds (default: 0.05 = 50ms). Lower = faster

Orderbook Viewer

Real-time orderbook visualization:

# Default (50ms updates)
python apps/orderbook_viewer.py --coin BTC

# Faster scanning (10ms updates)
python apps/orderbook_viewer.py --coin BTC --speed 0.01

# Custom levels
python apps/orderbook_viewer.py --coin BTC --levels 10

Parameters:

  • --coin - BTC, ETH, SOL, XRP (default: ETH)
  • --speed - Update interval in seconds (default: 0.05 = 50ms). Lower = faster scanning
  • --levels - Number of price levels to display (default: 10)

Usage Examples

Basic Usage

from src import create_bot_from_env
import asyncio

async def main():
    bot = create_bot_from_env()
    orders = await bot.get_open_orders()
    print(f"Open orders: {len(orders)}")

asyncio.run(main())

Place Order

from src import ArbitrageBot, Config

bot = ArbitrageBot(config=Config(safe_address="0x..."), private_key="0x...")
result = await bot.place_order(token_id="...", price=0.65, size=10.0, side="BUY")

WebSocket Streaming

from src.websocket_client import MarketWebSocket

ws = MarketWebSocket()
ws.on_book = lambda s: print(f"Price: {s.mid_price:.4f}")
await ws.subscribe(["token_id"])
await ws.run()

Configuration

Environment Variables

Variable Required Description
POLY_PRIVATE_KEY Yes Wallet private key
POLY_PROXY_WALLET Yes Polymarket Proxy wallet address
POLY_BUILDER_API_KEY Optional Builder Program API key (gasless)
POLY_BUILDER_API_SECRET Optional Builder Program API secret
POLY_BUILDER_API_PASSPHRASE Optional Builder Program passphrase

Config File

Create config.yaml:

safe_address: "0xYourAddress"
builder:
  api_key: "your_key"
  api_secret: "your_secret"
  api_passphrase: "your_passphrase"

Load with: ArbitrageBot(config_path="config.yaml", private_key="0x...")

Gasless Trading

Enable gasless trading via Builder Program:

  1. Apply at polymarket.com/settings?tab=builder
  2. Set environment variables: POLY_BUILDER_API_KEY, POLY_BUILDER_API_SECRET, POLY_BUILDER_API_PASSPHRASE

The bot automatically uses gasless mode when credentials are present.

Project Structure

polymarket-arbitrage-bot/
├── src/                    # Core library
├── strategies/             # Trading strategies
├── apps/                   # Application entry points
├── scripts/                # Utility scripts
└── lib/                    # Reusable components

Security

Private keys are encrypted using PBKDF2 (480,000 iterations) + Fernet symmetric encryption. Best practices:

  • Never commit .env files
  • Use a dedicated trading wallet
  • Keep encrypted key files secure (permissions: 0600)

API Reference

ArbitrageBot: place_order(), cancel_order(), get_open_orders(), get_trades(), get_order_book(), get_market_price()

MarketWebSocket: subscribe(), run(), disconnect(), get_orderbook(), get_mid_price()

GammaClient: get_market_info(), get_current_15m_market(), get_all_15m_markets()

Speed Optimization

The bot uses event-driven detection for instant flash crash detection (1-5ms latency). You can further increase speed:

Increase Trading Bot Speed

# Ultra-fast (10ms loop - 10x faster than default)
python apps/flash_crash_runner.py --coin BTC --speed 0.01

# Fast (20ms loop - 4x faster)
python apps/flash_crash_runner.py --coin BTC --speed 0.02

# Default (50ms loop - already 2x faster than before)
python apps/flash_crash_runner.py --coin BTC

Speed Settings:

  • --speed 0.01 = 10ms (100 updates/sec) - Ultra-fast
  • --speed 0.02 = 20ms (50 updates/sec) - Fast
  • --speed 0.05 = 50ms (20 updates/sec) - Default (2x faster)
  • --speed 0.1 = 100ms (10 updates/sec) - Slower (old default)

Increase Orderbook Viewer Speed

# Ultra-fast scanning (10ms - 100 updates/sec)
python apps/orderbook_viewer.py --coin BTC --speed 0.01

# Fast scanning (20ms - 50 updates/sec)
python apps/orderbook_viewer.py --coin BTC --speed 0.02

# Default (50ms - 20 updates/sec)
python apps/orderbook_viewer.py --coin BTC

Note: Flash crash detection is always event-driven (1-5ms latency) regardless of --speed setting. The --speed parameter only affects exit checks (TP/SL monitoring) and display updates.

Troubleshooting

Issue Solution
Missing credentials Set POLY_PRIVATE_KEY and POLY_PROXY_WALLET
Invalid private key Ensure 64 hex characters (0x prefix optional)
Order failed Check sufficient balance
WebSocket errors Verify network/firewall settings

License

MIT License - see LICENSE file for details.

Advanced Version - Dutch Book Arbitrage Bot

High-ROI Polymarket Arbitrage in 2026:

Programmatic Dutch-Book Strategies, Bots, and Portfolio OptimizationDutch-book arbitrage on Polymarket remains a solid edge—buy a complete set of mutually exclusive outcomes for under 1 USDC, guaranteeing profit when one resolves to 1. But in 2026, success hinges on execution, fees, and robustness amid evolved APIs and fiercer competition. image (7) image (8) image (10)

Trading tool

I've also developed a trading bot for Polymarket built with Rust.

image (21) https://www.youtube.com/watch?v=4f6jHT4-DQs

Disclaimer: This software is for educational purposes only. Trading involves risk of loss. The developers are not responsible for any financial losses incurred while using this bot.

Support: For questions or issues, contact via Telegram: @vladmeer | Twitter: @vladmeer

About

polymarket arbitrage trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot polymarket arbitrage bot

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published