Automated trading bot for Polymarket 15-minute crypto prediction markets. Trades BTC, ETH, SOL, and XRP simultaneously using the Late Entry V3 strategy.
- Multi-Market Trading — Trade 4 cryptocurrencies in parallel (BTC, ETH, SOL, XRP)
- Late Entry Strategy — Enter positions in the last 4 minutes before market close
- Real-time WebSocket Data — Live orderbook updates from Polymarket
- Automatic Redeem — Background collection of winnings after market resolution
- Telegram Integration — Commands for monitoring, charts, balance, and emergency shutdown
- Safety Guard — Protection layer with order limits and emergency stop
- Position Tracking — Real-time position monitoring via REST API
- Stop-Loss & Flip-Stop — Configurable exit strategies per coin
- PnL Charts — Visual performance tracking with matplotlib
┌──────────────────────────────────────────────────────────────┐
│ MAIN TRADING LOOP │
├──────────────────────────────────────────────────────────────┤
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ BTC │ │ ETH │ │ SOL │ │ XRP │ │
│ │ Trader │ │ Trader │ │ Trader │ │ Trader │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │
│ └──────────┬─┴───────────┬┘──────────┘ │
│ ┌───┴───┐ ┌────┴────┐ │
│ │ Order │ │ Data │ │
│ │Executor│ │ Feed │ │
│ └───────┘ └─────────┘ │
└──────────────────────────────────────────────────────────────┘
- Python 3.10 or higher
- Polygon wallet with USDC (bridged)
- Small amount of POL/MATIC for gas fees
- Polymarket API credentials
- VPN (if needed for geo-restrictions)
git clone https://github.com/txbabaxyz/4coinsbot.git
cd 4coins-trading-botIMPORTANT: You must use a virtual environment (venv)!
# Create venv
python3 -m venv venv
# Activate venv
# Linux/macOS:
source venv/bin/activate
# Windows:
.\venv\Scripts\activatepip install -r requirements.txt# Copy configuration files
cp .env.example .env
cp config/config.example.json config/config.json
# Edit .env with your credentials
nano .env
# Edit config.json for trading parameters
nano config/config.json# Wallet (REQUIRED)
PRIVATE_KEY=0x...your_private_key...
# Polygon Network
RPC_URL=https://polygon-rpc.com
CHAIN_ID=137
# Polymarket API (REQUIRED)
CLOB_HOST=https://clob.polymarket.com
POLYMARKET_API_KEY=your_api_key
POLYMARKET_API_SECRET=your_api_secret
POLYMARKET_API_PASSPHRASE=your_api_passphrase
# Telegram Notifications (optional)
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_idKey parameters:
| Section | Parameter | Description |
|---|---|---|
safety.dry_run |
true/false |
Enable dry run mode (no real trades) |
safety.max_order_size_usd |
150 |
Maximum single order size in USD |
safety.max_total_investment |
1000 |
Maximum investment per market |
trading.btc/eth/sol/xrp.enabled |
true/false |
Enable/disable specific coins |
strategy.entry_window_sec |
240 |
Entry window (last 4 minutes) |
strategy.min_confidence |
0.30 |
Minimum price difference to enter |
strategy.price_max |
0.92 |
Maximum entry price |
exit.stop_loss.per_coin.*.value |
-12 |
Stop-loss threshold in USD |
# Activate virtual environment
source venv/bin/activate
# Run the trading bot
cd src
python3 main.py| Key | Action |
|---|---|
Q |
Quit gracefully |
E |
Emergency stop (blocks all trading) |
| Command | Description |
|---|---|
/chart or /pnl |
Generate current PnL chart |
/b or /balance |
Show wallet balance (USDC + POL) |
/t or /positions |
Show active positions |
/r or /redeem |
Redeem completed markets (interactive) |
/off or /stop |
Emergency shutdown (with confirmation) |
/help |
Show all available commands |
4coins_live/
├── src/
│ ├── main.py # Main entry point
│ ├── strategy.py # Late Entry V3 strategy
│ ├── data_feed.py # WebSocket data feeds
│ ├── multi_trader.py # Multi-market trader manager
│ ├── trader.py # Individual trader logic
│ ├── order_executor.py # Order execution engine
│ ├── position_tracker.py # Real-time position tracking
│ ├── safety_guard.py # Safety limits and emergency stop
│ ├── simple_redeem_collector.py # Automatic redeem collection
│ ├── telegram_notifier.py # Telegram bot integration
│ ├── dashboard_multi_ab.py # Terminal dashboard
│ ├── polymarket_api.py # Polymarket API wrapper
│ ├── pnl_chart_generator.py # PnL chart generation
│ ├── trade_logger.py # Trade logging
│ └── keyboard_listener.py # Keyboard input handler
├── config/
│ └── config.json # Trading configuration
├── logs/ # Log files
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md # This file
The bot uses the "Late Entry V3" strategy:
- Entry Window: Only enter positions in the last 4 minutes (240 seconds) before market close
- Favorite Detection: Buy the side with higher ask price (market consensus)
- Confidence Filter: Only enter when price difference exceeds 30%
- Time-based Sizing:
- Above 180s remaining: 8 contracts
- Above 120s remaining: 10 contracts
- Below 120s remaining: 12 contracts
- Exit Strategies:
- Natural close (market resolution)
- Stop-loss (configurable per coin)
- Flip-stop (when our position becomes underdog)
- Dry Run Mode: Test without real trades
- Order Size Limits: Maximum per-order and per-market limits
- Rate Limiting: Maximum orders per minute
- Emergency Stop: Keyboard shortcut to halt all trading
- Investment Tracking: Per-market investment limits
- Position Persistence: Save positions on shutdown
Logs are stored in the logs/ directory:
trades.jsonl— All executed trades (JSON Lines format)orders.jsonl— Order execution detailssafety.log— Safety guard eventssession.json— Current session stateerror.log— Error messages
Use a private RPC endpoint:
RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_API_KEY- Check that API credentials are correct
- Verify the private key matches the Polymarket account
- Regenerate API credentials on Polymarket
The bot automatically reconnects. If persistent:
- Check internet connection
- Use a VPN
- Change DNS to 1.1.1.1 or 8.8.8.8
- Wait for oracle resolution (1-2 minutes after market close)
- Use
/rcommand in Telegram to manually trigger - Check
logs/for error messages
- USDC Type: Polymarket uses USDC (Bridged), not USDC.e (Native)
- Gas Fees: Keep POL/MATIC balance for transactions
- API Limits: Public RPCs have rate limits — use private RPC for stability
- Risks: Cryptocurrency trading involves significant risks
MIT License
This software is for educational purposes only. Trading cryptocurrency derivatives involves substantial risk of loss. Use at your own risk.