You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A production-ready, modular trading bot for Polymarket prediction markets with a modern React dashboard and real-time WebSocket updates.
Quick Start
# 1. Clone and setup Python environmentcd PolyAgent
pip install -r requirements.txt
# 2. Start the backend API server
python -m src.api_server
# 3. In a new terminal, start the frontend dashboardcd frontend
npm install
npm run dev
# 4. Open http://localhost:3000 and create your first bot!
# Cycle illustration:# Price: $0.50 → Set BUY target at $0.485 (−3%)# Price drops to $0.485 → BUY triggered# Set SELL target at $0.509 (entry × 1.05)# Price rises to $0.509 → SELL triggered (+5% profit)# Set new BUY target at $0.494 (−3%)# Repeat...
Multi-Window Spike Detection
Analyzes price changes over multiple time windows:
# Default windows: 10, 30, 60 minutes# For each window:# 1. Get prices from that window# 2. Calculate % change from oldest to current# 3. Check coefficient of variation (volatility filter)# 4. Take maximum spike across all windows
API Reference
REST Endpoints
All endpoints are served from http://localhost:8000.
Bot Management
Method
Endpoint
Description
GET
/api/bots
List all bots with status
POST
/api/bots
Create new bot
GET
/api/bots/{id}
Get bot details
PUT
/api/bots/{id}
Update bot config
DELETE
/api/bots/{id}
Delete bot
POST
/api/bots/{id}/start
Start bot
POST
/api/bots/{id}/stop
Stop bot
POST
/api/bots/{id}/trade
Execute manual trade
POST
/api/bots/{id}/close
Close position
GET
/api/bots/{id}/activities
Get activity log
GET
/api/bots/{id}/chart-data
Get price chart data
Market Data
Method
Endpoint
Description
GET
/api/markets/{slug}
Get market info
GET
/api/prices/{token_id}
Get current price
GET
/api/orderbook/{token_id}
Get orderbook
Settings
Method
Endpoint
Description
GET
/api/settings
Get global settings
POST
/api/settings
Update global settings
GET
/api/profiles
List trading profiles
WebSocket Events
Connect to ws://localhost:8000/ws for real-time updates.
# Check your setup
python scripts/check_setup.py
# Find a liquid market to trade
python scripts/find_best_market.py
# Test a trade cycle
python scripts/test_full_cycle.py
# Emergency: close all positions
python scripts/sell_all_positions.py
Testing
Backend Tests (pytest)
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_trading_cycle.py -v
# Run with coverage
pytest tests/ --cov=src --cov-report=html
Test Files
Test File
Coverage
test_end_to_end.py
Full trading flow
test_trading_cycle.py
Buy→Sell cycle logic
test_midprice_and_spike.py
Price calculation and spike detection
test_websocket_callbacks.py
WebSocket event handling
test_rebuy_config.py
Rebuy strategy configuration
test_runtime_state.py
State persistence
test_market_endpoints.py
API endpoint testing
Frontend Tests (Playwright)
cd frontend
# Run all E2E tests
npm run test:e2e
# Run with UI mode
npm run test:e2e:ui
# Run with visible browser
npm run test:e2e:headed
Operations Guide
Starting Everything
# 1. Start API server (keep running)
python -m src.api_server
# 2. Start frontend (keep running)cd frontend && npm run dev
# 3. Access dashboard at http://localhost:3000
Creating Your First Bot
Click "Create Bot" in the Bot Manager Panel
Enter bot name and description
Paste your private key (64 hex characters, no 0x prefix)
Choose signature type (EOA for most users)
Enter market slug from Polymarket URL
Select a trading profile or customize settings
Enable Dry Run for testing
Click Create Bot
Going Live
Verify setup with dry run trades
Monitor bot for expected behavior
Edit bot configuration
Set Dry Run: false
Start with small amounts ($1-5)
Monitor continuously initially
Emergency Stop
Dashboard: Click the Killswitch button in Settings
Trading on prediction markets involves significant risk. You can lose your entire investment. This software is provided "as is" without warranty. The authors are not responsible for any financial losses incurred. Only trade with funds you can afford to lose.
Happy Trading!
Made with ❤️ for the Polymarket community
About
A production-ready, modular trading bot for Polymarket prediction markets implementing the Spike Sam fade strategy with real-time WebSocket spike detection, multi-window analysis, dual signature modes (EOA/Proxy), comprehensive risk controls, and P&L tracking.