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.
- 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
- Market discovery — resolves active 5m markets from the Gamma API (
{asset}-updown-5m-{window_start}). - Signal evaluation — inside the entry window, reads CLOB best ask/bid and Binance 5m window delta.
- Entry — when the leading side meets price thresholds and spot direction aligns, submits a limit BUY.
- Post-entry — monitors open positions for reactive hedging, enforces risk limits, and periodically redeems resolved winners.
Default entry window: 60 → 1 seconds before window end, leading ask ≥ 0.93. All thresholds are tunable via environment variables.
- 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
cd polymarket-endcycle-bot
cp .env.example .env
cargo build --release
cargo run -- runDry-run mode logs signals only. Enable live trading with --live and wallet credentials in .env.
# 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-pollInspect current order books and Binance window delta:
cargo run -- status --assets btc,eth,sol,xrpAnalyze 5m crypto entry timing for any Polymarket wallet via the Data API:
cargo run -- analyze --wallet 0xYourWalletAddress --limit 500Copy .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=falseThen run with --live:
cargo run -- run --live --assets btc,eth,sol| Type | Value | Use case |
|---|---|---|
| EOA | 0 |
Standalone wallet |
| Proxy | 1 |
Polymarket proxy (legacy) |
| Gnosis Safe | 2 |
Polymarket.com browser wallet |
| Poly1271 | 3 |
Deposit wallet |
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.
All settings are loaded from environment variables. See .env.example for the full list.
| 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| 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 |
| 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 |
| 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.
| 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 |
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 ───────────┘
| 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.
- Uses limit orders at the observed ask; FOK/market orders are not supported yet.
This software is provided for research and educational purposes. Prediction markets involve financial risk. Use at your own discretion. No guarantees of profitability.