Skip to content

PollyProphet/polymarket-endcycle-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polymarket Endcycle Bot

Automated trading bot for Polymarket 5-minute crypto Up/Down markets. It monitors short-interval prediction markets and enters near the end of each window when price action and spot data indicate a high-confidence outcome.

Built in Rust with WebSocket feeds, configurable risk controls, hedging, and optional live CLOB execution.

Features

  • Endcycle entry — configurable entry window in the final seconds of each 5-minute market
  • Multi-asset — BTC, ETH, SOL, XRP, DOGE (and any asset with the standard slug pattern)
  • Real-time feeds — Polymarket CLOB WebSocket quotes and Binance spot prices (HTTP fallback available)
  • Live trading — limit BUY orders via polymarket_client_sdk_v2 (EIP-712 + L2 HMAC)
  • Risk limits — position caps, daily volume/loss limits, loss-streak circuit breaker
  • Hedging — proactive opposite-side entry and reactive stop-loss hedge
  • Auto-redeem — scans for resolved positions and redeems winning tokens on-chain
  • Dry-run by default — safe signal logging without submitting orders

How it works

  1. Market discovery — resolves active 5m markets from the Gamma API ({asset}-updown-5m-{window_start}).
  2. Signal evaluation — inside the entry window, reads CLOB best ask/bid and Binance 5m window delta.
  3. Entry — when the leading side meets price thresholds and spot direction aligns, submits a limit BUY.
  4. Post-entry — monitors open positions for reactive hedging, enforces risk limits, and periodically redeems resolved winners.
image

Default entry window: 60 → 1 seconds before window end, leading ask ≥ 0.93. All thresholds are tunable via environment variables.

Requirements

  • Rust 1.70+ (rustup)
  • Network access to Polymarket and Binance APIs
  • For live mode: Polygon private key and Polymarket funder/proxy address with USDC balance

Quick start

cd polymarket-endcycle-bot
cp .env.example .env
cargo build --release
cargo run -- run

Dry-run mode logs signals only. Enable live trading with --live and wallet credentials in .env.

Commands

Run the bot

# Dry-run (default)
cargo run -- run
cargo run -- run --assets btc,eth,sol,xrp,doge

# Live CLOB orders
cargo run -- run --live --assets btc,eth,sol

# HTTP polling instead of WebSockets
cargo run -- run --http-poll

Market snapshot

Inspect current order books and Binance window delta:

cargo run -- status --assets btc,eth,sol,xrp

Wallet trade analysis

Analyze 5m crypto entry timing for any Polymarket wallet via the Data API:

cargo run -- analyze --wallet 0xYourWalletAddress --limit 500

Live trading setup

Copy .env.example to .env and configure:

POLYGON_PRIVATE_KEY=0x...
POLYMARKET_FUNDER_ADDRESS=0x...   # your Polymarket proxy / funder address
POLYMARKET_SIGNATURE_TYPE=2       # Gnosis Safe (Polymarket.com browser wallet)
ENDCYCLE_DRY_RUN=false

Then run with --live:

cargo run -- run --live --assets btc,eth,sol

Signature types

Type Value Use case
EOA 0 Standalone wallet
Proxy 1 Polymarket proxy (legacy)
Gnosis Safe 2 Polymarket.com browser wallet
Poly1271 3 Deposit wallet

Optional CLOB API credentials

Pre-derived credentials skip L1 auth at startup:

POLYMARKET_API_KEY=...
POLYMARKET_API_SECRET=...
POLYMARKET_API_PASSPHRASE=...

The bot uses polymarket_client_sdk_v2 for L1 authentication, EIP-712 order signing, and L2 HMAC submission to https://clob.polymarket.com.

Configuration

All settings are loaded from environment variables. See .env.example for the full list.

Strategy

Variable Default Description
ENDCYCLE_DRY_RUN true Log only; no orders
ENDCYCLE_ORDER_SIZE_USDC 50 USDC notional per trade
ENDCYCLE_MIN_PRICE 0.93 Minimum leading ask
ENDCYCLE_MAX_PRICE 0.995 Maximum leading ask
ENDCYCLE_ENTRY_START_SECS 60 Open entry window N seconds before window end
ENDCYCLE_ENTRY_END_SECS 1 Close entry window N seconds before window end

Example — tighter late-window entries:

ENDCYCLE_ENTRY_START_SECS=20
ENDCYCLE_ENTRY_END_SECS=1
ENDCYCLE_MIN_PRICE=0.99
ENDCYCLE_MAX_PRICE=0.999

Risk limits

Variable Default Description
ENDCYCLE_RISK_ENABLED true Enable risk checks
ENDCYCLE_MAX_POSITIONS 5 Max concurrent open positions
ENDCYCLE_MAX_POSITION_SIZE_USDC 100 Per-trade size cap
ENDCYCLE_MAX_DAILY_VOLUME_USDC 2000 Daily entry volume cap
ENDCYCLE_MAX_DAILY_LOSS_USDC 150 Daily loss limit
ENDCYCLE_LOSS_STREAK_PAUSE 3 Pause after N consecutive losses

Hedging

Variable Default Description
ENDCYCLE_HEDGE_ENABLED true Proactive hedge at entry
ENDCYCLE_HEDGE_RATIO 0.30 Opposite-side size vs main entry
ENDCYCLE_REACTIVE_HEDGE true Reactive hedge on bid drop
ENDCYCLE_STOP_LOSS_PERCENT 8 Bid drop % that triggers reactive hedge
ENDCYCLE_REACTIVE_HEDGE_RATIO 0.50 Reactive hedge size vs main

Auto-redeem

Variable Default Description
ENDCYCLE_REDEEM_ENABLED true Poll and redeem resolved positions
ENDCYCLE_REDEEM_POLL_SECS 60 Scan interval (seconds)
POLYGON_RPC_URL https://polygon-rpc.com RPC for on-chain CTF redeem

Proxy wallets (signature type 2) may hold tokens on the funder address — on-chain redeem from the signing EOA can fail in that case. Dry-run still reports redeemable positions; manual redeem via the Polymarket UI remains an option.

Wallet / API

Variable Default Description
POLYGON_PRIVATE_KEY Required for --live
POLYMARKET_FUNDER_ADDRESS Funder / proxy address
POLYMARKET_SIGNATURE_TYPE 2 Wallet signature type (0–3)
RUST_LOG info Log level

Architecture

Gamma API (markets) ──┐
Binance WS (spot)   ──┼──► StrategyEngine ──► EntrySignal ──► Trade (risk + hedge)
CLOB WS (bid/ask)   ──┘                              │
                                                     ├──► LiveExecutor (CLOB orders)
Position monitor ── reactive hedge / stop-loss ──────┤
RedeemService ───── Data API + CTF redeem ───────────┘

Data feeds

Feed Source Data
CLOB quotes wss://ws-subscriptions-clob.polymarket.com Best bid/ask per token
Binance spot wss://stream.binance.com @miniTicker last price
Window open Binance REST (once per 5m window) 5m kline open
Markets Gamma REST Active 5m market metadata

Use --http-poll to fall back to HTTP for all price and order book data.

Limitations

  • Uses limit orders at the observed ask; FOK/market orders are not supported yet.

Disclaimer

This software is provided for research and educational purposes. Prediction markets involve financial risk. Use at your own discretion. No guarantees of profitability.

About

Automated Rust trading bot for Polymarket 5-minute crypto Up/Down markets — WebSocket feeds, live CLOB execution, risk limits, hedging, and auto-redeem.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages