Automated trading bot for Polymarket BTC Up/Down 15-minute binary markets. The bot monitors real-time market data via WebSocket, calculates technical indicators (VWAP, deviation, momentum, z-score), generates entry signals, executes Fill-And-Kill orders, and optionally hedges positions with Good-Till-Date limit orders on the opposite token.
Every 15 minutes, Polymarket opens a new market asking: "Will BTC go up or down in the next 15 minutes?" Two tokens are available:
- UP token pays $1.00 if BTC rises, $0.00 if it falls
- DOWN token pays $1.00 if BTC falls, $0.00 if it rises
The bot identifies the "favorite" (the token with higher probability), waits for specific technical conditions to align, then buys it. If the prediction is correct, the token resolves to $1.00 for a profit. If wrong, it resolves to $0.00 for a loss.
- Real-time terminal dashboard with Rich library (order book, indicators, signals, position, P&L)
- VWAP-based signal generation with deviation and momentum filters
- Historical win rate filtering by price range and time bin
- FAK order execution with retry logic and WebSocket fill confirmation
- Optional hedging via GTD orders on the opposite token at $0.02
- Timeout recovery: detects fills via User WebSocket even after network timeouts
- Chainlink BTC/USD oracle tracking: real-time BTC price and deviation from market start
- Auto-redemption of winning positions on-chain
- Telegram notifications with trade alerts and equity charts
- Per-trade drawdown tracking with logging
- Persistent trade history in JSON format (survives restarts)
btc-15m-live/
|-- main.py # Main bot: dashboard, signals, execution, all core logic
|-- config.json # Trading parameters (strategy, entry, hedge, etc.)
|-- .env.example # Environment variables template (copy to .env)
|-- requirements.txt # Python dependencies
|-- chart_pnl.py # P&L chart generator (run separately)
|-- PROJECT_LOGIC.md # Detailed technical documentation with formulas
|-- data/
| +-- win_rate.csv # Historical win rate matrix (10 price ranges x 15 time bins)
+-- src/
|-- __init__.py
|-- config_loader.py # Loads config.json + .env, validates settings
|-- order_executor.py # FAK order placement with retry logic
|-- hedge_manager.py # GTD hedge order management
|-- market_finder.py # Discovers active markets via Gamma API
|-- position_tracker.py # Position and P&L tracking
|-- auto_redeemer.py # On-chain redemption of resolved positions
|-- telegram_notifier.py# Telegram alerts and chart sending
|-- user_websocket.py # User channel WebSocket (order/fill tracking)
+-- websocket_client.py # Market data WebSocket (prices, trades, book)
- Linux server (Ubuntu 22.04+ recommended) or macOS
- Python 3.11+
- Polymarket account with funded USDC balance (on Polygon), POL for gas fees, and API credentials
- Private key of your trading wallet
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip python3-venv git
python3 --versioncd ~
git clone https://github.com/txbabaxyz/btc-15m-live.git
cd btc-15m-livepython3 -m venv venv
source venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtcp .env.example .env
nano .envFill in your credentials:
| Variable | Required | Description |
|---|---|---|
| PRIVATE_KEY | Yes | Polygon wallet private key (0x...) |
| FUNDER_ADDRESS | If proxy | Gnosis Safe address (if using proxy wallet) |
| SIGNATURE_TYPE | If proxy | 0=EOA, 1=Poly Proxy, 2=Gnosis Safe |
| POLY_API_KEY | Yes | Polymarket CLOB API key |
| POLY_API_SECRET | Yes | Polymarket CLOB API secret |
| POLY_API_PASSPHRASE | Yes | Polymarket CLOB API passphrase |
| RPC_URL | Recommended | Alchemy/Infura Polygon RPC (default: public RPC) |
| TELEGRAM_BOT_TOKEN | Optional | Telegram bot token from @BotFather |
| TELEGRAM_CHAT_ID | Optional | Your Telegram user/chat ID |
How to get Polymarket API credentials:
- Go to https://polymarket.com and connect your wallet
- Navigate to your account settings
- Generate API credentials (key, secret, passphrase)
- These are used for L2 authentication on the CLOB
nano config.jsonSee the Configuration section below for parameter descriptions.
mkdir -p logssource venv/bin/activate
python3 main.pysudo apt install -y tmux
tmux new -s bot
# Inside tmux:
source venv/bin/activate
python3 main.py
# Detach: Ctrl+B then D
# Reattach: tmux attach -t botThe bot is highly configurable -- every aspect of the strategy, risk management, execution, hedging, and notifications can be fine-tuned through config.json without touching any code. You can adjust the entry window, price filters, indicator sensitivity, bet sizing, and more to match your risk tolerance and trading style.
For a complete parameter-by-parameter guide with explanations, examples, and ready-made presets (Conservative / Moderate / Aggressive), see CONFIG.md.
Quick overview of the most important settings:
| Parameter | Default | What it controls |
|---|---|---|
strategy.min_price |
0.75 | Minimum token price to enter (lower = riskier, more profit) |
strategy.max_price |
0.88 | Maximum token price to enter (higher = safer, less profit) |
strategy.min_elapsed_sec |
530 | Wait this many seconds before entering |
strategy.min_deviation_pct |
3 | Minimum VWAP deviation to trigger signal |
strategy.no_entry_before_end_sec |
335 | Stop entering with this many seconds left |
entry.bet_amount_usd |
5 | USD per trade (start small!) |
entry.max_entry_price |
0.88 | Hard price ceiling for safety |
hedge.enabled |
false | Automatic hedging on opposite token |
telegram.enabled |
false | Trade notifications via Telegram |
The bot evaluates 5 conditions every 250ms. ALL must be true to trigger a BUY:
- Price in range: min_price <= favorite_price <= max_price
- Time elapsed: elapsed_seconds >= min_elapsed_sec
- VWAP deviation: min_deviation_pct < deviation < max_deviation_pct
- Positive momentum: momentum > 0%
- Time remaining: seconds_left > no_entry_before_end_sec
- VWAP (Volume-Weighted Average Price): SUM(price * volume) / SUM(volume) over the last N seconds
- Deviation: (last_price - VWAP) / VWAP * 100% -- how far price moved from its average
- Momentum: (price_now - price_Ns_ago) / price_Ns_ago * 100% -- direction of price movement
- Z-Score: (price - mean) / stdev over the last 5 seconds -- statistical outlier detection
Signal detected
-> FAK order placed
-> Fill confirmed via WebSocket
-> Position recorded
-> Hedge placed (if enabled)
-> Drawdown tracked every 250ms
-> Market ends (10s before expiry)
-> Position resolved, P&L recorded
-> Winning positions auto-redeemed on-chain
Higher entry prices mean higher risk. The break-even win rate equals the entry price:
- Entry at $0.75 needs 75% win rate to break even
- Entry at $0.85 needs 85% win rate to break even
- Entry at $0.88 needs 88% win rate to break even
Start with small bet_amount_usd ($1-5) until you understand the behavior.
The bot creates a logs/ directory with:
| File | Description |
|---|---|
| bot.log | Main application log (connections, errors, BTC price ticks) |
| signals.log | Full indicator snapshot at each trade entry and market end |
| orders.log | Detailed order execution log (prices, retries, fills) |
| hedges.log | Hedge order placement and fill tracking |
| trading_log.json | Persistent trade history (survives restarts) |
After accumulating trades, generate a P&L chart:
source venv/bin/activate
python3 chart_pnl.py
# Output: logs/pnl_chart.pngFor a deep technical dive including all formulas, architecture diagrams, and the complete signal generation logic, see PROJECT_LOGIC.md.
This software is provided for educational and research purposes only. Trading on prediction markets involves significant financial risk. You may lose all funds used for trading. The authors are not responsible for any financial losses. Always start with small amounts and understand the risks before increasing position sizes.
MIT