Skip to content

Gabagool2-2/polymarket-trading-bot-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Polymarket Bot | Polymarket Trading Bot | Polymarket Trading Bot - 5 min market | Polymarket Arbitrage Bot

Polymarket Bot, Polymarket Trading Bot, Polymarket 5min market Trading Bot, Polymarket Automatic Trading Bot

A high-performance, automated trading system for Polymarket prediction markets. Built in Python with real-time WebSocket streaming, gasless L2 execution, and a risk-management framework suited to short-term and high-frequency environments.

image

Contact

Channel Link
Email benjamin.bigdev@gmail.com
Telegram @BenjaminCup
X (Twitter) @benjaminccup

If you'd like, I can show you a profitable bot in action through a meeting.

1. Polymarket Endcycle Sniper bot (Introduction)

Polymarket Endcycle Sniper Bot is an automated trading system designed to monitor short-duration prediction markets and execute high-probability trades near the end of each 5-minute epoch. It connects to the orderbook in real time, triggers buys when prices exceed a configured threshold (e.g., 0.95), manages risk with optional exits or hedging, and redeems winning positions automatically after market resolution. πŸš€πŸ“ˆ polymarket-endcycle-sniper-bot

Recording Video

Benjamin-Cup-Polymarket-Trading-Bot-github.mp4

Running Bot Screenshot

github-update-4- github-update-5-

Result Screenshot

github-update-1 github-update-3

Telegram Trial Version Bot

You can also test the bot directly on Telegram.

image
polymarket-trading-bot-Telegram.mp4

https://t.me/benjamin_polymarket_trading_bot


2. Polymarket Copy Trading Bot (Introduction)

An open-source bot that automatically copies trades from top Polymarket traders to your walletβ€”so you can follow proven strategies 24/7 without watching the market yourself.

Whether you're new to prediction markets or you want to scale your copy-trading across multiple wallets, this bot is built to be simple to run, transparent, and under your control.

polymarket-copy-trading-bot

Recording Video

polymarket-copy-trading-bot.mp4

3. Polymarket Arbitrage Bot (Dual-side)

This Polymarket trading bot explores an automated volatility and probability arbitrage bot designed to identify pricing inefficiencies in prediction markets. Instead of predicting outcomes, the system exploits mispriced probabilities, market imbalances, and short-term volatility using quantitative models and automation. By combining high-frequency execution with strong risk management and hedging, the bot aims to capture small statistical edges and compound them over large trade volumes. πŸš€

image

Result Screenshot

image

4. Polymarket Arbitrage (Ladder Trading) Bot (Introduction)

This bot does not speculate on market direction. Instead, it captures spread by selling both YES and NO outcome tokens at prices whose combined value exceeds $1. The strategy focuses on market making, not directional trading. image

Recording Video

Polymarket-ladder-trading-bot-video.mp4

Result Screenshot

polymarket-trading-ladder-bot-pnl

1. Polymarket Endcycle Sniper bot (Explain)

πŸš€ Key Features

  • Signal + Execution Pipeline: Combines real-time orderbook + spot prices vs strike β†’ generates UP/DOWN signals β†’ executes optionally.
  • Buy-Above Strategy: Enter momentum trades when an outcome is expensive (YES > threshold) with risk exit and optional hedge.
  • Buy-Opposite Strategy: Contrarian trades when one side spikes (> threshold) β†’ buys the other outcome.
  • Multi-Asset Support: Run BTC, ETH, SOL, XRP simultaneously.
  • Configurable & Extensible: YAML + environment variable overrides (POLYBOT5M_*).
  • Redeem Automation: Auto redeem positions after resolution using Builder relayer (gasless).

πŸ“Š How It Works

1. Main Pipeline (polybot5m run)

Generates UP/DOWN signals every 5 minutes using:

  1. Market Discovery: Finds active 5-minute slug (e.g., btc-updown-5m-{epoch_ts}) β†’ fetches condition_id & asset IDs via Gamma API.
  2. Orderbook Capture: Uses CLOB WebSocket β†’ stores in memory for analysis.
  3. Price History: Rolling midpoint (bid+ask)/2 over tracking window (default 60s).
  4. Reference Price: Real-time spot from Coinbase or Binance; optional strike price scrape.
  5. Signal Engine: Compares first-half vs second-half midpoint averages β†’ predicts UP or DOWN.
  6. Optional Execution: Market or limit buy at best ask per asset if credentials and execution.enabled.

Flow Diagram (simplified):

Market Discovery β†’ CLOB Orderbook β†’ Price History β†’ Spot vs Strike β†’ Signal Engine β†’ Execute

2. Buy-Above Strategy (scripts/run_5m_core.py)

  • Trigger: When best_ask > threshold (e.g., 0.95) β†’ market buy YES.
  • Risk Management: Optional stop-loss (sell_on_drop) and hedge (hedge_on_risk).
  • Redeem: Auto redeem after resolution with redeem_delay_seconds.
  • Multi-Cycle: Supports multiple assets and epochs in parallel.

3. Buy-Opposite Strategy (scripts/test_buy_opposite_098.py)

  • Trigger: When one outcome spikes above threshold (e.g., >0.98), buy the other outcome.
  • Use Case: Profits from mean reversion when price spikes are temporary.
  • Multi-Cycle: Repeat for multiple assets and epochs.

πŸ—‚ Project Layout

polymarket-trading-bot-5m-v4/
β”œβ”€β”€ config/
β”‚   └── default.yaml          # All configs: bot, api, markets, entry, risk, execution, buy_above, buy_opposite
β”œβ”€β”€ src/polybot5m/
β”‚   β”œβ”€β”€ cli.py                # Main run
β”‚   β”œβ”€β”€ entry/engine.py       # Signal computation
β”‚   β”œβ”€β”€ data/                 # APIs, WS, orderbook, price_diff, scrape
β”‚   └── execution/            # CLOB client, executor, redeem
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ run_5m_core.py        # Buy-above
β”‚   β”œβ”€β”€ test_buy_opposite_098.py  # Buy-opposite
β”‚   β”œβ”€β”€ run_until_resolution.py   # Full cycle
β”‚   └── step01-12_*.py        # Step-by-step tests
└── exports/                  # Logs & activity JSONL

βš™ Configuration (High-Level)

Section Purpose
bot dry_run, log_level
api Gamma & CLOB URLs
markets Enabled assets & intervals
entry Signal sampling, tracking window, confidence threshold
risk Stop-loss %, max positions
execution API keys, private key, order type, buy/sell style
buy_above Threshold, amount, cycles, risk, hedge
buy_opposite Threshold, amount, offset, cycles
reference_price Coinbase/Binance, optional strike scrape

⚑ Tip: Override any config with POLYBOT5M_* environment variables.


πŸ’° How It Can Make Money

  1. Main Run: Predicts 5-minute market outcomes better than average β†’ executes trades.
  2. Buy-Above: Exploits momentum when YES price is high; profits if outcome wins more often than implied by price.
  3. Buy-Opposite: Profits from mean-reversion on price spikes.

⚠️ Risk Note: All strategies are directional speculation. Losses can occur if prediction is wrong or price slips.


🏁 Beginner Workflow (WORKFLOW_BEGINNER.md)

  1. Setup:

    python -m venv .venv
    source .venv/bin/activate
    pip install -e .

    Optional: Playwright for strike scraping.

  2. Verify Config: Run step scripts (step01_config.py, step02_slug.py) without network keys.

  3. Dry-Run Main Pipeline:

    .venv/bin/polybot5m run --dry-run
    .venv/bin/python scripts/run_until_resolution.py --cycles 1
  4. Dry-Run Strategy Scripts:

    .venv/bin/python scripts/run_5m_core.py --dry-run --cycles 1
    .venv/bin/python scripts/test_buy_opposite_098.py --dry-run --cycles 1
  5. Add Credentials: .env file with CLOB & Builder keys for execution/redeem.

  6. First Live Run: Start with dry_run=False, small amount, one cycle β†’ verify signals and execution.

πŸ“Œ Quick Reference Table: Install β†’ signals β†’ dry-run strategies β†’ add credentials β†’ first live run.


πŸ’» Running It

# Main pipeline
.venv/bin/polybot5m run
.venv/bin/polybot5m -c config/default.yaml run

# Buy-above strategy
.venv/bin/python scripts/run_5m_core.py --dry-run --cycles 1

# Buy-opposite strategy
.venv/bin/python scripts/test_buy_opposite_098.py --dry-run --cycles 5

# Full cycle until resolution
.venv/bin/python scripts/run_until_resolution.py

Ensure API keys and private key are set for execution; redeem uses Builder relayer keys.


πŸ“Œ Summary

Aspect polymarket-trading-bot-5m-v4
Role Signal + execution bot for 5m crypto UP/DOWN markets
Main Run Orderbook + spot vs strike β†’ UP/DOWN signal β†’ optional execution
Strategies Buy-above (momentum + risk exit), Buy-opposite (contrarian)
Markets BTC, ETH, SOL, XRP (configurable)
Data Sources Gamma, CLOB WS, Coinbase/Binance WS, optional strike scrape
Config YAML + POLYBOT5M_* env overrides
Beginner Path Clone β†’ setup β†’ dry-run β†’ try strategies β†’ add keys β†’ first live run

2. Polymarket Copy Trading Bot (Explain)

✨ Why use this bot?

  • Real copy trading β€” Mirrors every trade from the proxy wallets you choose (buy, sell, merge).
  • Your keys, your rules β€” Runs on your machine with your wallet; no custody, no middleman.
  • Flexible sizing β€” Copy by percentage of the trader’s order, or a fixed USD amount per trade.
  • Multi-wallet β€” Run one executor and copy into several follower wallets at once.
  • Monitor + Executor β€” Run a monitor (sleuth) to watch traders and fill the DB, and a separate executor to place orders (great for scaling or separating concerns).
  • PnL at a glance β€” Check copy-trading performance with npm run check-copy-pnl.
  • Preview mode β€” Dry-run: see what would be traded without sending real orders.

πŸ—οΈ How it works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Trade Monitor   │────▢│     MongoDB      │◀────│ Trade Executor   β”‚
β”‚  (sleuth)        β”‚     β”‚  (pending trades)β”‚     β”‚ (places orders)   β”‚
β”‚  β€’ Polls API     β”‚     β”‚                  β”‚     β”‚ β€’ Validates       β”‚
β”‚  β€’ Saves trades  β”‚     β”‚                  β”‚     β”‚ β€’ Copy % or $     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚ β€’ Multi-wallet   β”‚
        β”‚                          β”‚               β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                          β”‚                        β”‚
        β–Ό                          β–Ό                        β–Ό
  Polymarket API            Your config              Polymarket CLOB
  (activity, positions)      (COPY_STRATEGY, etc.)    (orders)
  • Monitor fetches target traders’ activity and positions, deduplicates, and stores new trades.
  • Executor reads pending trades, applies your copy strategy (percentage or fixed size), validates balance/positions, and posts orders for each follower wallet.
  • You can run monitor and executor together (npm run dev) or separately (npm run monitor + npm run executor).

πŸ“Š PnL and monitoring

  • Copy-trading PnL β€” Run npm run check-copy-pnl to see value, initial cost, unrealized/realized PnL, and position count for your follower wallet(s). Data comes from the Polymarket positions API.
  • Logs β€” The bot logs trades, balance checks, and errors; use your normal process (e.g. logs/ directory, PM2, Docker logs) to monitor.

πŸ”’ Security and safety

  • Private keys β€” Stored only in your .env; never committed. Use a dedicated wallet with limited funds.
  • Preview mode β€” Use PREVIEW_MODE=true to test without sending orders.
  • Limits β€” MAX_ORDER_SIZE_USD, MIN_ORDER_SIZE_USD, and optional MAX_POSITION_SIZE_USD / MAX_DAILY_VOLUME_USD help cap risk.

4. Polymarket Arbitrage (Ladder Trading) Bot (5m / 15m / 1h / 4h / 1d crypto Up/Down markets) (Explain)

Overview

Polymarket trading bot is designed to provide automated liquidity in Polymarket prediction markets.

Bot Workflow

πŸ”„ Polymarket Bot Workflow

1. Split collateral

Divide USDC into YES/NO outcome tokens.

2. Pair selling

Sell both YES and NO tokens simultaneously.

3. Market resolution

Wait until the prediction market resolves.

4. Redeem

Redeem the winning tokens for collateral.

Profit is generated from spread capture, where the bot sells both outcomes at prices that sum to greater than $1.

Strategy Concept

When a market is created on Polymarket:

  • YES token = pays $1 if event happens

  • NO token = pays $1 if event does not happen

The bot:

Converts USDC.e into YES + NO tokens

Sells both tokens

Ensures the sum of prices β‰₯ target spread

Example:

Token Sell Price
YES 0.54
NO 0.49

Total received:

0.54 + 0.49 = 1.03

Cost to create pair:

1.00

Profit before fees:

1.03 - 1.00 = 0.03 per pair

Typical range:

Total received β‰ˆ 1.03 – 1.10

After the market resolves:

  • One token becomes $1
  • The other becomes $0

The bot redeems the winning token.


Strategy Flow

The bot runs a state machine cycle:

IDLE
  ↓
SPLIT
  ↓
PAIR_SELL
  ↓
MONITOR
  ↓
REDEEM
  ↓
IDLE

Phase Explanation

Phase Description
SPLIT Convert USDC.e into YES and NO tokens
PAIR_SELL Sell YES and NO tokens in sequential pairs
MONITOR Wait for market resolution
REDEEM Redeem winning tokens for USDC.e

Pair Selling Logic

The bot sells tokens in pairs rather than all at once.

### For every pair:

1. Fetch orderbook

2. Read best bid prices

3. Compute optimal sell prices

4. Place YES and NO limit orders

5. Wait until both fill

6. Retry if timeout occurs

image

Dynamic Pricing

Sell prices are calculated using:

yes_price = best_bid_yes + spread
no_price  = best_bid_no  + spread

Then the bot enforces:

yes_price + no_price β‰₯ min_pair_sum

Example configuration:

best_bid_yes = 0.49
best_bid_no  = 0.50
spread       = 0.01

Calculated:

yes_price = 0.50
no_price  = 0.51
sum = 1.01

If min_pair_sum = 1.03, the bot increases both prices proportionally.

If running continuously

Markets Cycles per hour Hourly Profit
1 market (5m) 12 ~$36
2 markets 12 ~$72
4 markets 12 ~$144
polymarket-trading-ladder-bot
β”‚
β”œβ”€β”€ config
β”‚   β”œβ”€β”€ default.yaml
β”‚   └── paper.yaml
β”‚
β”œβ”€β”€ src/polybot5m
β”‚
β”‚   β”œβ”€β”€ cli.py
β”‚   β”œβ”€β”€ config.py
β”‚   β”œβ”€β”€ constants.py
β”‚   β”œβ”€β”€ engine.py
β”‚
β”‚   β”œβ”€β”€ data
β”‚   β”‚   β”œβ”€β”€ gamma.py
β”‚   β”‚   └── slug_builder.py
β”‚
β”‚   └── execution
β”‚       β”œβ”€β”€ clob_client.py
β”‚       β”œβ”€β”€ executor.py
β”‚       β”œβ”€β”€ split.py
β”‚       └── redeem.py
β”‚
└── exports
    └── liquidity_maker_activity.json

Configuration

Main configuration file:

config/default.yaml

Example:

liquidity_maker:
  portfolio_allocation_usdc: 100

  pair_size: 5
  min_pair_sum: 1.03

  price_follow_spread: 0.01

  pair_sell_timeout_seconds: 300
  order_check_interval_seconds: 5

  redeem_delay_seconds: 10
  stagger_delay_seconds: 2

Important Parameters

Parameter Description
portfolio_allocation_usdc USDC used per market cycle
pair_size Shares per YES/NO pair
min_pair_sum Minimum combined sell price
price_follow_spread Price offset above best bid
pair_sell_timeout_seconds Cancel orders if not filled
order_check_interval_seconds Poll order status

Supported Markets

Designed for short-term Polymarket crypto markets:

Asset 5m 15m 1h 4h 1d
BTC βœ… βœ… βœ… βœ… βœ…
ETH βœ… βœ… βœ… βœ… βœ…
SOL βœ… βœ… βœ… βœ… βœ…
XRP βœ… βœ… βœ… βœ… βœ…

Slug format:

{symbol}-updown-{interval}-{epoch_timestamp}

Example:

btc-updown-5m-1709916600

Run Modes

Paper Trading (Recommended First)

Uses real orderbook data but no real trades.

polybot5m -c config/paper.yaml run

or

polybot5m run --dry-run

Live Trading

Example:

polybot5m run --cycles 1 --allocation 10

Meaning:

  • run one cycle
  • allocate $10 per market

Custom Run

polybot5m run \
  --allocation 500 \
  --cycles 5

Environment Variables

Required for live trading.

PRIVATE_KEY=
FUNDER=

API_KEY=
API_SECRET=
API_PASSPHRASE=

Optional builder relayer keys:

BUILDER_API_KEY_1=
BUILDER_API_SECRET_1=
BUILDER_API_PASSPHRASE_1=

Multiple keys can be used to avoid rate limits.


Activity Logs

Trading activity is exported to:

exports/liquidity_maker_activity.json

Example record:

{
  "market": "btc-updown-5m",
  "action": "pair_sell",
  "yes_price": 0.52,
  "no_price": 0.51,
  "size": 5,
  "timestamp": 1709916600
}

Summary

Feature Description
Strategy Liquidity market making
Profit source Spread capture
Market type Polymarket 5m / 15m / 1h / 4h / 1d crypto
Language Python / Rust
APIs Gamma API + CLOB API
Execution Builder Relayer

About

polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot polymarket trading bot poly

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages