Polymarket Quant Bot
An autonomous, multi-strategy quantitative trading engine built to find and exploit mispricings across 500+ prediction markets in real-time.
Overview
The Problem
Prediction markets like Polymarket are often mispriced. Manual traders cannot process hundreds of markets simultaneously, miss fleeting arbitrage windows, and lack the quantitative rigor to size positions optimally. Resolved markets leave "ghost positions" that distort portfolio accounting.
The Solution
A fully autonomous trading engine that ingests real-time WebSocket data, runs 21 parallel signal strategies (including XGBoost and LSTM neural networks), executes Kelly-optimal trades, and manages the full position lifecycle from entry to resolution settlement — controlled entirely via Telegram.
Architecture
┌──────────────────────────────────────────────────────────────┐
│ DATA SOURCES │
│ WebSocket Firehose · REST API · Gamma Events API │
└──────────┬───────────────────────────────────┬────────────────┘
│ │
▼ ▼
┌──────────────────────────────────────────────────────────────┐
│ CORE ENGINE (3 Loops) │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐ │
│ │ Trading Engine │ │ Exit Engine │ │ Resolution │ │
│ │ Filter → Score │ │ TP/SL/Trail │ │ Poll → PnL │ │
│ │ → Execute │ │ Time Decay │ │ → Settle │ │
│ └─────────────────┘ └─────────────────┘ └──────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐│
│ │ 21 Signal Strategies ││
│ │ ML: XGBoost · LSTM · Diffusion · Meta Predictor ││
│ │ μ-Structure: Orderbook · Wall · Trade Flow · Spoofing ││
│ │ Stream: Whale · Cluster · Arb Scanner ││
│ │ Intel: Insider · Sentiment · LLM · Weather ││
│ └──────────────────────────────────────────────────────────┘│
└──────────────────────────┬───────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────────┐
│ Postgres │ │ Redis │ │ ClickHouse │
│ (Trades) │ │ (Cache) │ │ (Analytics) │
└──────────┘ └──────────┘ └──────────────┘Trading Engine
Scans 500 markets per cycle, applies fast filtering (resolution time, volume, price), then deep-analyses survivors with all 21 strategies in parallel.
Exit Engine
Continuous position monitoring with take-profit, stop-loss, trailing stops, and time-decay exits as markets approach resolution.
Resolution Engine
Polls Gamma API every 30s to detect resolved markets, determines WIN/LOSE outcomes, and settles PnL automatically.
How It Works
1. Live Market Analysis & Trade Execution
Every 2 seconds, the engine fetches 500 markets, applies a fast filter pipeline, and runs deep multi-strategy analysis. Trades are executed with Kelly-optimal sizing and logged with full transparency.

2. Strategy Scoring & Opportunity Detection
Each market is scored by 21 independent strategies that vote on trade direction. The composite edge is calculated using dynamic strategy weighting based on recent performance, ensuring the most accurate signals dominate.

3. Real-Time WebSocket Streaming
A native WebSocket connection to Polymarket streams live orderbook updates, whale trades, and price movements. This sub-millisecond data feeds the microstructure strategies and nanosecond arbitrage scanner.

4. Telegram Command Interface
The bot is controlled entirely via Telegram. Check portfolio status, open positions, PnL breakdown, and trigger analysis — all from your phone. No SSH or terminal access needed.



21 Signal Strategies
Machine Learning
Microstructure
Real-Time Stream
Intelligence
Statistical
Key Technical Achievements
Real-Time WebSocket Firehose
Custom async WebSocket client streams live orderbook updates, trade executions, and price changes from Polymarket's CLOB. A message router dispatches events to the orderbook cache, whale tracker, and arbitrage scanner with sub-millisecond latency.
ML-Driven Edge Detection
An XGBoost gradient boosting model and PyTorch LSTM neural network are trained on historical market snapshots to predict true probabilities. The difference between model prediction and market price becomes the trading edge, sized using the Kelly Criterion.
Full Position Lifecycle Management
Three independent loops run concurrently: the Trading Engine (find & execute), the Exit Engine (TP/SL/trailing/time-decay), and the Resolution Engine (detects resolved markets via Gamma API and settles PnL automatically). No position is ever left as a "ghost."
Cloud-Native Deployment
Dockerized with Docker Compose orchestrating PostgreSQL, Redis, ClickHouse, and the bot. Deployable to any VPS (Hetzner, Railway, AWS) with a single command. Controlled entirely via Telegram — no SSH needed for day-to-day operations.
Explore the Code
Open-source toolkit extracted from the production bot