https://github.com/gnanam1990/polymarket-copy-bot
Automatically copy trades from top Polymarket wallets. Multi-wallet tracking, smart ROI filtering, paper/live trading, WebSocket prices, real-time Flask dashboard.
https://github.com/gnanam1990/polymarket-copy-bot
asyncio automated-trading clob copy-trading crypto defi flask paper-trading polymarket prediction-markets python trading-bot websocket
Last synced: 14 days ago
JSON representation
Automatically copy trades from top Polymarket wallets. Multi-wallet tracking, smart ROI filtering, paper/live trading, WebSocket prices, real-time Flask dashboard.
- Host: GitHub
- URL: https://github.com/gnanam1990/polymarket-copy-bot
- Owner: gnanam1990
- License: mit
- Created: 2026-03-27T01:38:49.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-03-27T01:47:18.000Z (3 months ago)
- Last Synced: 2026-03-27T14:17:13.321Z (3 months ago)
- Topics: asyncio, automated-trading, clob, copy-trading, crypto, defi, flask, paper-trading, polymarket, prediction-markets, python, trading-bot, websocket
- Language: Python
- Size: 21.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polymarket Copy Trading Bot
**Automatically copy trades from top Polymarket wallets with smart filtering, paper trading, and a real-time dashboard.**
[](https://python.org)
[](LICENSE)
[](https://polymarket.com)
[](https://flask.palletsprojects.com)
[](https://docs.python.org/3/library/asyncio.html)
---
## Architecture Overview
```mermaid
graph TB
subgraph Input["๐ฏ Wallet Sources"]
A1[Config File]
A2[Dashboard UI]
A3[REST API]
end
subgraph Core["โ๏ธ Core Engine"]
B[Tracker] -->|Trade Events| C[Copier]
C -->|Open Position| D[Positions]
E[Prices] -->|Bid/Ask/Mid| D
end
subgraph External["๐ Polymarket APIs"]
F1[Activity API]
F2[CLOB REST]
F3[CLOB WebSocket]
end
subgraph Output["๐ Output"]
G[Flask Dashboard]
H[SSE Live Feed]
I[Position Persistence]
end
A1 & A2 & A3 --> B
F1 -->|Poll every 2s| B
F2 -->|Order Book| E
F3 -->|Price Stream| E
C -->|Paper / Live| F2
D --> G
D --> H
D --> I
style Input fill:#1e1b4b,stroke:#6366f1,color:#e0e7ff
style Core fill:#042f2e,stroke:#22c55e,color:#d1fae5
style External fill:#451a03,stroke:#f59e0b,color:#fef3c7
style Output fill:#1c1917,stroke:#a855f7,color:#f3e8ff
```
## Trade Execution Flow
```mermaid
flowchart LR
A["๐ Detect Trade"] --> B{"Action?"}
B -->|BUY| C{"Price\n3ยข โ 70ยข?"}
B -->|SELL| W["โ ๏ธ Whale Exit Alert"]
C -->|No| X["Skip"]
C -->|Yes| D{"ROI\nโฅ 30%?"}
D -->|No| X
D -->|Yes| E{"Max\nPositions?"}
E -->|Full| X
E -->|OK| F{"Duplicate\nCheck"}
F -->|Dup| X
F -->|New| G{"Mode?"}
G -->|Paper| H["๐ Simulate Fill\n+ Slippage & Gas"]
G -->|Live| I["๐ฐ CLOB FOK Order"]
H & I --> J["๐ Track Position\n+ Live PnL"]
style A fill:#3b82f6,stroke:#1d4ed8,color:#fff
style W fill:#a855f7,stroke:#7c3aed,color:#fff
style X fill:#ef4444,stroke:#dc2626,color:#fff
style H fill:#f59e0b,stroke:#d97706,color:#fff
style I fill:#22c55e,stroke:#16a34a,color:#fff
style J fill:#6366f1,stroke:#4f46e5,color:#fff
```
## Features
| Feature | Description |
|---------|-------------|
| **Multi-Wallet Tracking** | Monitor unlimited Polymarket wallets simultaneously |
| **Smart Copy Engine** | Filters by entry price range, ROI threshold, dedup window |
| **Paper Trading** | Full simulation with slippage, gas fees, and FOK rejection |
| **Live Trading** | Real CLOB orders via Polymarket API (FOK) |
| **Web Dashboard** | Real-time positions, PnL, trade feed at `localhost:8080` |
| **Profile Resolver** | Add wallets by URL, username, or `0x` address |
| **Whale Exit Alerts** | Detects when tracked wallets sell positions you hold |
| **Live Prices** | WebSocket + REST fallback for bid/ask/mid |
| **Auto Settlement** | Detects market resolution, credits wins, debits losses |
| **Hot-Reload Config** | Change settings without restart |
## Quick Start
```bash
# Clone
git clone https://github.com/gnaneshwarvasala/polymarket-copy-bot.git
cd polymarket-copy-bot
# Install
pip install -r requirements.txt
# Configure
cp config.example.toml config.toml
# Edit config.toml โ add wallet addresses to track
# Run (paper mode by default)
python bot.py
# Dashboard โ http://localhost:8080
```
## Configuration
```toml
[mode]
paper = true # true = simulation, false = real USDC
paper_balance = 1000.0
[copy]
min_profit_pct = 30.0 # Min ROI% to copy (30 = max entry ~77ยข)
max_entry_price = 0.70 # Max entry price (0.70 = 70ยข)
min_entry_price = 0.03 # Skip dust trades below 3ยข
position_size = 10.0 # USDC per trade
max_positions = 20 # Max concurrent positions
dedup_window_secs = 60 # Block same market+side within N seconds
[wallets]
track = [
"0xed107a85a4585a381e48c7f7ca4144909e7dd2e5",
]
[poll]
interval_secs = 2
trades_per_wallet = 20
[dashboard]
enabled = true
port = 8080
```
## Adding Wallets
Three ways to add wallets โ all formats auto-resolve:
```
https://polymarket.com/profile/scottilicious โ profile URL
scottilicious โ username
0x000d257d2dc7616feaef4ae0f14600fdf50a758e โ direct address
```
| Method | How |
|--------|-----|
| **Config** | Add to `[wallets] track` in `config.toml` |
| **Dashboard** | Type in the "Add wallet" field |
| **API** | `POST /api/wallet/add {"input": "scottilicious"}` |
## System Architecture
```mermaid
graph LR
subgraph bot.py["๐ bot.py โ Entry Point"]
direction TB
LOAD[Load Config] --> INIT[Init Components]
INIT --> START[Start Async Tasks]
end
subgraph tracker.py["๐ tracker.py"]
POLL[Poll Activity API] --> DETECT[Detect New Trades]
DETECT --> EMIT[Emit TradeEvent]
end
subgraph copier.py["๐ copier.py"]
FILTER[Filter Signal] --> EXEC[Execute Trade]
EXEC --> SETTLE[Settlement Loop]
end
subgraph positions.py["๐ positions.py"]
OPEN[Open Position] --> TRACK[Track PnL]
TRACK --> CLOSE[Settle / Close]
end
subgraph prices.py["๐น prices.py"]
WS[WebSocket Stream] --> CACHE[Price Cache]
REST[REST Fallback] --> CACHE
CACHE --> PUSH[Push to Positions]
end
subgraph dashboard.py["๐ฅ๏ธ dashboard.py"]
FLASK[Flask Server] --> SSE[SSE Live Feed]
FLASK --> API[REST API]
FLASK --> UI[Web UI]
end
subgraph resolver.py["๐ resolver.py"]
RESOLVE[URL / Username / Address โ Proxy Wallet]
end
bot.py --> tracker.py --> copier.py --> positions.py
prices.py --> positions.py
dashboard.py --> positions.py
dashboard.py --> resolver.py
style bot.py fill:#1e3a5f,stroke:#3b82f6,color:#bfdbfe
style tracker.py fill:#1a2e1a,stroke:#22c55e,color:#bbf7d0
style copier.py fill:#3b1f0b,stroke:#f59e0b,color:#fef3c7
style positions.py fill:#2d1b4e,stroke:#a855f7,color:#e9d5ff
style prices.py fill:#1e3a5f,stroke:#3b82f6,color:#bfdbfe
style dashboard.py fill:#1c1917,stroke:#71717a,color:#e4e4e7
style resolver.py fill:#3b0a1e,stroke:#ec4899,color:#fce7f3
```
## Dashboard
Open `http://localhost:8080` after starting the bot:
| Panel | Shows |
|-------|-------|
| **Stats Bar** | Balance, Unrealized PnL, Realized PnL, Total PnL |
| **Positions Table** | Market, Side, Size, Entry, Bid, Ask, Spread, PnL |
| **Live Feed** | Real-time stream of detections, copies, fills, settlements |
| **Wallet List** | All tracked wallets with add/remove controls |
## API Reference
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/status` | `GET` | Bot status, balance, position count |
| `/api/positions` | `GET` | All open positions with live prices |
| `/api/wallets` | `GET` | Tracked wallets list |
| `/api/wallet/add` | `POST` | Add wallet โ `{"input": "0x..."}` |
| `/api/wallet/remove` | `POST` | Remove wallet โ `{"wallet": "0x..."}` |
| `/api/trades` | `GET` | Trade history |
| `/api/feed` | `GET` | SSE live event stream |
| `/api/pause` | `POST` | Pause trading |
| `/api/resume` | `POST` | Resume trading |
## Settlement Flow
```mermaid
sequenceDiagram
participant S as Settlement Loop
participant C as CLOB API
participant P as Positions
participant B as Balance
loop Every 30s
S->>P: Get open positions
loop Each position
S->>C: Check market resolution
alt Market resolved โ WIN
S->>P: Settle (WON)
P->>B: Credit payout (size / entry_price)
Note right of B: โ
Balance increases
else Market resolved โ LOSS
S->>P: Settle (LOST)
Note right of B: โ Size already deducted
else Still open
Note right of S: Skip โ check next cycle
end
end
end
```
## Live Trading
> **Use at your own risk. Always start with paper mode.**
Set environment variables:
```bash
export POLY_KEY="your-api-key"
export POLY_SECRET="your-api-secret"
export POLY_PASSPHRASE="your-passphrase"
export POLY_PRIVATE_KEY="your-private-key"
```
Then in `config.toml`:
```toml
[mode]
paper = false
```
## Tech Stack
| Component | Technology |
|-----------|-----------|
| **Runtime** | Python 3.10+ / asyncio |
| **HTTP Client** | aiohttp |
| **WebSocket** | websockets |
| **Dashboard** | Flask + Server-Sent Events |
| **Config** | TOML (tomli) |
| **Persistence** | JSON file storage |
## License
[MIT](LICENSE)
---
`#polymarket` `#copy-trading` `#trading-bot` `#python` `#prediction-markets` `#crypto` `#defi` `#asyncio` `#flask` `#websocket` `#paper-trading` `#clob` `#automated-trading`