A high-frequency trading bot for Polymarket designed to capture short-term volatility ("spikes") caused by emotional trading or breaking news. Built with Python and py-clob-client.
โ ๏ธ DISCLAIMER: This software is for educational purposes only. Algorithmic trading involves significant risk. The authors are not responsible for any financial losses incurred while using this bot. Use at your own risk.
โ FULLY IMPLEMENTED - Ready to use!
The bot currently runs in Paper Trading Mode:
- โ Real market data from Polymarket API
- โ Simulated trades with fake balance ($100 starting)
- โ Complete strategy, risk management, and reporting
- โ No real money at risk - pure simulation
The bot operates on a Spike Hunter / Mean Reversion strategy:
- Monitor: Polls 50 highest-volume Polymarket markets every second
- Detect: Identifies price spikes (ยฑ3% deviation from moving average)
- Enter: Opens simulated $5 position when spike detected
- Exit: Closes position at:
- Take Profit: +4% gain
- Stop Loss: -2% loss
- Log: Records all trades to JSON and market data to CSV
- ๐ Paper Trading: Risk-free simulation with fake balance
- โก Low Latency: Fully asynchronous architecture using
asyncio - ๐ Real Data: Live market data from Polymarket CLOB API
- ๐ฏ Smart Strategy: Spike detection with moving average analysis
- ๐ก๏ธ Risk Management: Position sizing, max drawdown, cooldowns
- ๐ Real-time Reporting: CSV/JSON logging of trades and market data
- ๐ก MQTT Integration: Real-time events pro Discord bot monitoring
- ๐ง Highly Configurable: All parameters via
.envfile
Bot publishes real-time events via MQTT for monitoring and Discord notifications:
Events:
- โ Bot status (started/stopped/heartbeat)
- โ Spike detection
- โ Position opened/closed
- โ Trade completed (+ P&L)
- โ Balance updates (every 12h)
- โ Session statistics
MQTT Broker:
- Localhost (port 1883)
- No authentication
- Topic prefix:
polyspike/
Documentation: See docs/MQTT_API.md for complete API reference.
Discord Bot: Separate repository (coming soon)
pip install -r requirements.txtThe bot comes with sensible defaults in .env.example. For testing:
cp .env.example .env
# Edit .env if you want to change settingspython run_bot.pyOr:
python main.py- Watch real-time logs in console
- Press Ctrl+C to stop
- Check
data/sessions/TIMESTAMP/for results
๐น PolySpike Hunter - Paper Trading Mode
============================================================
๐ Configuration:
Initial Balance: $100.0
Spike Threshold: 3%
Position Size: $5.0
Max Markets: 50
============================================================
Starting bot...
2025-12-25T18:10:03Z [info] ๐ Starting PolySpikeHunter...
2025-12-25T18:10:04Z [info] โ
Bot is now running. Press Ctrl+C to stop.
2025-12-25T18:10:15Z [info] spike_detected direction=down spike_pct=-3.2%
2025-12-25T18:10:15Z [info] โ
ENTRY EXECUTED price=0.4800 size=$5.00
2025-12-25T18:10:45Z [info] take_profit_triggered pnl_pct=+4.12%
2025-12-25T18:10:45Z [info] โ
EXIT EXECUTED pnl=$+0.20 balance=$100.20
...
After each session, find your results in data/sessions/TIMESTAMP/:
trades.json- All completed trades with entry/exit prices, P&Lmarkets.csv- Market snapshots (price, MA, volatility)summary.json- Session statistics and performance metrics
MQTT Events: See docs/MQTT_API.md for real-time event streaming via MQTT.
Edit .env to customize:
# Paper Trading
INITIAL_BALANCE=100.0 # Starting fake balance
PAPER_TRADING=true # Always true for now
# Strategy
SPIKE_THRESHOLD=0.03 # 3% spike to trigger entry
POSITION_SIZE=5.0 # $5 per trade
TAKE_PROFIT_PCT=0.04 # 4% take profit
STOP_LOSS_PCT=0.02 # 2% stop loss
# Monitoring
MAX_MONITORED_MARKETS=50 # Number of markets to watch
MONITOR_STRATEGY=volume # Use highest volume markets
POLL_INTERVAL=1.0 # Poll every second
# Risk Management
MAX_DRAWDOWN=50.0 # Stop if losses reach $50
MAX_OPEN_POSITIONS=10 # Max concurrent positions
# MQTT Integration
MQTT_ENABLED=true # Enable MQTT publishing
MQTT_HOST=localhost # MQTT broker host
MQTT_PORT=1883 # MQTT broker port
MQTT_BALANCE_UPDATE_INTERVAL=43200 # Balance updates (12h)
MQTT_HEARTBEAT_INTERVAL=30 # Heartbeat intervalโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Main Bot Loop โ
โ (main.py) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโ
โ โ
โโโโโโโผโโโโโโโ โโโโโโโผโโโโโโโโโโ
โ Market โ โ Strategy โ
โ Monitor โโโโถโ Spike Hunter โ
โโโโโโโโโโโโโโ โโโโโโโโโฌโโโโโโโโ
โ โ
โ โโโโโโโโผโโโโโโโโโ
โ โ Paper Trading โ
โ โ Engine โ
โ โโโโโโโโฌโโโโโโโโโ
โ โ
โโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโ
โ Risk Manager โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโโ
โ Reporting โ
โ (CSV/JSON) โ
โโโโโโโโโโโโโโโโโโ
main.py- Main bot orchestratorsrc/core/market_monitor.py- Async market pollingsrc/core/paper_trading.py- Simulated trading enginesrc/strategy/spike_hunter.py- Spike detection logicsrc/core/risk_manager.py- Safety limits and validationsrc/utils/reporting.py- CSV/JSON logging
Test individual components:
# Test API connection
python test_connection.py
# Test market monitoring
python test_monitor.py
# Test MQTT integration
python test_mqtt.py subscribe # Listen to all MQTT events
python test_mqtt.py publish # Send test events
# Run full integration test
python -c "from main import PolySpikeHunter; print('โ
All imports OK')"- QUICKSTART.md - Detailed setup guide
- AGENTS.md - Development guidelines and architecture
- MQTT_API.md - MQTT API documentation for Discord bot integration
Future enhancements:
- Live trading mode (with real API keys and real money)
- WebSocket support for lower latency
- More sophisticated strategies (ML-based?)
- Backtesting framework
- Web dashboard for monitoring
- Multiple strategy support
MIT License - See LICENSE for details
This is experimental software for educational purposes only.
- Paper trading mode is completely safe (no real money)
- Live trading (when implemented) will involve real financial risk
- Never trade with money you can't afford to lose
- Cryptocurrency/prediction markets are highly volatile
- Past performance does not guarantee future results
Use at your own risk!