This repository contains a privacy-first Polymarket trading bot specifically built for the SolRouter bounty.
In highly competitive 5-minute resolution markets like the Polymarket BTC "Price Up/Down" contracts, alpha decay happens in seconds. Using public LLM endpoints or public RPCs risks front-running and strategy leaking.
By utilizing SolRouter and the private gpt-oss-20b models with encryption, this agent guarantees that our sentiment summaries, volume spike analysis, and liquidity sweep detections remain confidential, ensuring our strategy retains its edge without adversarial exploit.
- Add your SolRouter API key to the
.envfile:SOLROUTER_API_KEY=your_secure_key_here
- Run the secure research agent:
node agent.js
The contents below represent the pre-existing, underlying Python pipeline for LightGBM inference and execution on the Polygon network.
ML-driven, gasless trading bot that exploits mispricings in Polymarket's 5-minute BTC resolution markets using LightGBM inference, real-time Binance price streams, and post-only maker execution on Polygon.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Binance WS │────▶│ Rolling State │────▶│ Feature │
│ btcusdt@agg │ │ (deque, 50k) │ │ Pipeline │
└─────────────────┘ └──────────────────┘ └────────┬────────┘
│
┌─────────────────┐ ▼
│ Gamma API │ ┌──────────────────┐ ┌─────────────────┐
│ Market Finder │────▶│ LightGBM │◀────│ Feature Vector │
└─────────────────┘ │ Inference │ │ (20 features) │
└────────┬─────────┘ └─────────────────┘
│ p̂ᵢ
▼
┌──────────────────┐ ┌─────────────────┐
│ Order Router │────▶│ Polymarket │
│ Edge Detection │ │ CLOB (post_only│
└──────────────────┘ │ GTD limit) │
└─────────────────┘
┌──────────────────┐
│ Risk Manager │──── Kill-Switch / Cancel
│ σ Monitor │
└──────────────────┘
# Install Homebrew, Python 3.12, and libomp (required for LightGBM)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python@3.12 libomp
# Setup project
cd /path/to/BTC
rm -rf venv/ && python3.12 -m venv venv
source venv/bin/activate
pip install -r requirements.txtpython3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtRun the entire fetch-engineer-train-validate sequence in one go:
python scripts/01_fetch_historical.py --days 90 && \
python scripts/02_engineer_features.py && \
python scripts/03_train_model.py --n-splits 5 && \
python scripts/04_validate_model.pypython -m pytest tests/ -v# Recommended for first connectivity validation
export DRY_RUN=true
python -m src.execution.engineIf you want the bot to target a strict $1 spend per order, use the
dollar-based sizing path instead of raw shares:
export DRY_RUN=false
export LIVE_TRADING_ENABLED=true
export ORDER_NOTIONAL=1.0
export MAX_ORDER_NOTIONAL=1.0
export BANKROLL_FRACTION_PER_ORDER=1.0
export ALLOW_UPSIZE_TO_MIN_ORDER_SIZE=falsePolymarket venue minimums still apply. If a live market needs more than $1
to satisfy its minimum order size, the bot will skip that trade instead of
upsizing past your cap.
Before enabling live orders, run the account-aware preflight:
venv/bin/python scripts/05_validation_preflight.py --budget 1.0Then run the full engine in authenticated read-only mode:
venv/bin/python -m src.execution.engine --validation-only# On server (Ubuntu 22.04+)
sudo ./deploy/setup_server.sh <git-repo-url>
# Copy model and .env, then:
sudo systemctl start polymarket_bot
journalctl -u polymarket_bot -f| Feature | Description |
|---|---|
| Order Book Imbalance | Buy/sell volume ratio from tick data |
| Micro-Price Momentum | Log returns over 1m, 2m, 5m, 10m windows |
| Hurst Exponent | Rolling R/S analysis for trend detection |
| Fractional Differentiation | Memory-preserving stationarization |
| Rolling Volatility | σ across multiple timeframes |
| VWAP Deviation | Price distance from volume-weighted average |
| Trade Flow Imbalance | Net buy/sell aggressor pressure |
- Volatility Kill-Switch: Cancels all orders on 3σ vol breach
- P&L Floor: Halts trading at -$0.20 cumulative loss
- Position Limits: Max 3 concurrent resting orders
- Post-Only Enforcement: All orders are maker-only (zero fees)
- GTD Expiration: Orders expire after 10 seconds
| Action | Fee |
|---|---|
| Maker (post_only) | 0% + eligible for rebates |
| Taker | ~1.56% (dynamic) |
| Gas (Polygon) | $0 (covered by Relayer) |
Untitled.mov
MIT