What is Polymarket Bot?
A real-time BTC price prediction engine for Polymarket 5-minute binary markets. The system monitors live BTC prices, predicts market outcomes using mathematical models, compares predictions against market prices to find positive Expected Value opportunities, and sizes bets using fractional Kelly criterion with sophisticated risk management.This is a prediction engine, not a simple price tracker. It combines Black-Scholes option pricing, EWMA volatility estimation, and momentum analysis in logit space to produce calibrated probability forecasts.
System Workflow
The engine operates in a continuous loop (1-second intervals) processing real-time data through multiple stages:Core Components
Data Feeds
Data Feeds
Chainlink WebSocket (
src/feeds/chainlink.js:8)- Connects to
wss://ws-live-data.polymarket.com - Streams BTC/USD price updates every ~1 second
- NaN guard and 10% spike filter protect against bad data
- Auto-reconnect with 3-second delay
src/feeds/vatic.js:4)- Fetches strike prices aligned to 5-minute boundaries
- Cached per epoch to minimize requests
- Endpoint:
https://api.vatic.trading/api/v1/targets/timestamp
src/feeds/polymarket.js:10-12)- Gamma API discovers active markets via slug patterns
- CLOB
/priceendpoint provides live market probabilities - Rate-limited to 1 request per second
- Polled every 5 seconds (configurable)
Prediction Engine
Prediction Engine
The
PredictionEngine class (src/engine/predictor.js:37) orchestrates:- Volatility Estimation - EWMA tracker with λ=0.94
- Base Probability - Black-Scholes binary call probability N(d₂)
- Momentum Signals - Weighted ROC across 10s/30s/60s windows
- Mean Reversion - 2-minute SMA deviation detection
- Logit-Space Combination - Mathematically sound probability fusion
- Platt Calibration - Sigmoid recalibration after 200+ samples
{ probability, direction, volatility, momentum, reversion }Risk Management
Risk Management
Position Sizer (
src/risk/position-sizer.js:7)- Maps Brier Score to fractional Kelly alpha (0 → 0.40)
- Computes optimal bet size:
f = α × (p-q)/(1-q) × bankroll - Caps at 5% of bankroll per trade
- Minimum bet: $1 USD
src/risk/drawdown-tracker.js:7)- Tracks 4 risk levels from high-water mark
- Green (0-10%): Full sizing
- Yellow (10-20%): Half alpha, higher EV threshold
- Red (20-30%): Trading suspended
- Critical (30%+): Trading suspended
- Cold-streak detection: 5 consecutive misses → force yellow
Abstention System
Abstention System
7-Condition Safety Filter (
src/engine/predictor.js:82-180)The system abstains when:- Insufficient data (< 50 ticks)
- Dead zone (probability within 10% of 50%)
- Anomalous volatility (σ > 2× mean)
- Cold streak (accuracy < 40% in 20-interval window)
- Insufficient EV (< 5%)
- Insufficient margin (< 15pp)
- Drawdown suspension (red/critical level)
Data Flow
Per-Tick Processing (1000ms interval)
Per-Interval Lifecycle
Epoch Start
- Detect 5-minute boundary (timestamp % 300 = 0)
- Reset momentum analyzer (preserve volatility state)
- Fetch strike price from Vatic API
- Discover active market from Gamma API
Monitoring Phase (0-240s)
- Stream price ticks continuously
- Update EWMA volatility every tick
- Buffer momentum data (300-tick rolling window)
- Generate predictions every second
- Record predictions at T-60s and T-30s
Near Expiry (240-300s)
- Disable momentum/reversion adjustments (T < 5s)
- Pure Black-Scholes probability only
- Prevents gaming with late-stage volatility spikes
Configuration
All parameters are defined inconfig/default.json:
Performance Metrics
The system tracks multiple accuracy and calibration metrics:| Metric | Target | What It Measures |
|---|---|---|
| Early 1m Accuracy | > 80% | Real trading performance (T-60s predictions) |
| Brier Score | < 0.20 | Calibration quality (0=perfect, 0.25=coin flip) |
| BSS (Brier Skill Score) | > 0 | Improvement over random baseline |
| Log Loss | < 0.60 | Penalizes confident wrong predictions heavily |
| Expected Value | > 5% | Minimum edge vs market to justify trading |
| Edge (p - q) | > 15pp | Safety margin between model and market |
Next Steps
How Predictions Work
Deep dive into Black-Scholes, EWMA, momentum, and logit-space combination
Data Sources
Chainlink WebSocket, Vatic API, Polymarket Gamma/CLOB integration details
Risk Management
Kelly criterion, Brier-tiered alpha, drawdown tracking
Abstention System
The 7 conditions that prevent trading when no edge exists