GitHub - tufstraka/polybot (original) (raw)
๐ฏ Polybot - Multi-Market Arbitrage Bot
Find risk-free profit on Polymarket by exploiting pricing inefficiencies across related markets.
๐ What Changed?
Old Strategy: Mean reversion (spike trading)
- Required $5,000/month Twitter API for news edge
- Predicted price reversals
- Win rate: 52-55%
New Strategy: Multi-Market Arbitrage
- $0 external costs (just Polymarket API)
- Math-based, no prediction needed
- Win rate: 80-95%
๐ก How It Works
Type 1: Mutually Exclusive Markets
When two outcomes can't both happen, prices must sum to โค100%.
Example:
Market A: "Trump wins" = 55ยข
Market B: "Biden wins" = 50ยข
Sum: 105ยข (should be โค100ยข)
Action:
1. SELL both markets (collect 105ยข)
2. One MUST win (pay 100ยข)
3. Fees: 4ยข (2% ร 2 trades)
4. Profit: 1ยข (1% return)
Type 2: Dependent Markets
If event B requires event A, then P(B) โค P(A).
Example:
Market A: "Trump wins presidency" = 50ยข
Market B: "Trump wins popular vote" = 60ยข
Problem: Can't win popular vote without winning!
Action:
1. BUY "presidency" @ 50ยข
2. SELL "popular vote" @ 60ยข
3. Profit: 10ยข spread
๐ Expected Performance
| Capital | Opportunities/Day | Daily Profit | Monthly Return |
|---|---|---|---|
| 75โฃ1โ2โฃ75 | 1-2 | 75โฃ1โ2โฃ0.05-0.20 | 2-8% |
| 500โฃ2โ3โฃ500 | 2-3 | 500โฃ2โ3โฃ1-3 | 6-15% |
| 5,000โฃ3โ5โฃ5,000 | 3-5 | 5,000โฃ3โ5โฃ10-40 | 6-20% |
Reality check: Arbitrage opportunities are rare and small. With 75,expect75, expect 75,expect1-5/month profit. It's not life-changing, but it's relatively safe.
๐ ๏ธ Installation
git clone https://github.com/tufstraka/polybot.git cd polybot
Create virtual environment
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate
Install dependencies
pip install -r requirements.txt
Configure
cp .env.example .env nano .env # Add your API keys
Required: Polymarket API
Get API credentials from Polymarket
POLYMARKET_API_KEY=your_key POLYMARKET_API_SECRET=your_secret POLYMARKET_PASSPHRASE=your_passphrase
Optional: Notifications
Telegram
TELEGRAM_BOT_TOKEN=123456:ABC-DEF... TELEGRAM_CHAT_ID=987654321
Discord
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
๐ Quick Start
1. Test in Dry-Run Mode (Paper Trading)
Run arbitrage bot (NO REAL MONEY)
python -m src.bot_arbitrage --dry-run
Expected output:
[INFO] Polybot started (DRY RUN) - Arbitrage Mode
[INFO] Tracking 247 markets (ALL)
[INFO] Found 3 market relationships
๐ฐ ARBITRAGE FOUND: mutually_exclusive | Discrepancy: 5.2%
๐ Executing arbitrage: 2 legs, Expected profit: $0.31 (6.2%)
โ
Leg executed: SELL <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2.50</mn><mi mathvariant="normal">@</mi></mrow><annotation encoding="application/x-tex">2.50 @ </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord">2.50@</span></span></span></span>0.552
โ
Leg executed: SELL <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>2.50</mn><mi mathvariant="normal">@</mi></mrow><annotation encoding="application/x-tex">2.50 @ </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord">2.50@</span></span></span></span>0.503
โ
Arbitrage position opened: 2 legs executed
2. Monitor Dashboard
In another terminal
streamlit run src/dashboard/app.py
Open http://localhost:8501 to see:
- Active arbitrage positions
- Market relationships detected
- P&L tracking
- Real-time monitoring
3. Review After 1 Week
Check these metrics:
- Win rate (should be >80% for true arbitrage)
- Average profit per trade (should be >0%)
- Execution success rate
- False positive rate
If profitable โ go live. If not โ opportunities too rare.
4. Go Live (REAL MONEY)
Edit config/config.yaml
mode: paper_trading: false # โ ๏ธ CAUTION: REAL TRADES
Restart bot
python -m src.bot_arbitrage
โ๏ธ Configuration
Key Settings (config/config.yaml)
money: starting_balance: 75 # Your capital max_daily_loss: 2 # Stop if lose $2 today
arbitrage: min_discrepancy: 0.02 # Need 2%+ profit (covers fees) min_confidence: 0.60 # Must be 60%+ sure max_position_size: 5.0 # Max $5 per arbitrage cooldown_minutes: 30 # Wait 30min before re-trading
Why these values?
min_discrepancy: 0.02โ Polymarket charges 2% per trade. Need >4% total to profit.min_confidence: 0.60โ Filters out uncertain relationships.max_position_size: 5.0โ With 75capital,risk75 capital, risk 75capital,risk5 max per arb.cooldown_minutes: 30โ Prevents spam, lets market stabilize.
๐ Documentation
- ARBITRAGE_STRATEGY.md - Complete strategy guide
- DEPLOYMENT.md - AWS deployment instructions
- config/config.yaml - All settings explained
๐๏ธ Architecture
polybot/
โโโ src/
โ โโโ bot_arbitrage.py # Main arbitrage bot (NEW)
โ โโโ bot.py # Old spike trading bot (DEPRECATED)
โ โโโ core/
โ โ โโโ correlation_analyzer.py # Finds market relationships (NEW)
โ โ โโโ arbitrage_detector.py # Detects opportunities (NEW)
โ โ โโโ scanner.py # Market discovery
โ โ โโโ executor.py # Order execution
โ โ โโโ position_manager.py # Trade tracking
โ โโโ risk/
โ โ โโโ risk_manager.py # Risk management
โ โโโ notifications/
โ โ โโโ telegram.py # Telegram alerts
โ โ โโโ discord.py # Discord webhooks
โ โโโ dashboard/
โ โโโ app.py # Streamlit dashboard
โโโ config/
โ โโโ config.yaml # Configuration
โโโ ARBITRAGE_STRATEGY.md # Strategy documentation (NEW)
โโโ README.md # This file
๐ฌ How Arbitrage Detection Works
Step 1: Market Discovery
Scan all Polymarket markets
markets = scanner.get_tradable_markets()
Returns: 200+ active markets
Step 2: Relationship Detection
Group related markets
analyzer = CorrelationAnalyzer() relationships = analyzer.analyze_markets(markets)
Example relationships found:
- "Trump wins" + "Biden wins" (mutually exclusive)
- "Trump wins" โ "Trump wins popular vote" (dependent)
Step 3: Constraint Checking
Check if prices violate constraints
opportunities = analyzer.detect_opportunities(prices)
Mutually exclusive: sum โค 100%
Dependent: P(specific) โค P(general)
Step 4: Trade Execution
If profitable after fees:
detector = ArbitrageDetector() position = detector.create_arbitrage_trades(opportunity) await detector.execute(position)
โ ๏ธ Risks
What Can Go Wrong?
- Execution Failure - Prices move before you execute
- False Positives - Misidentified relationships
- Resolution Risk - Market resolves incorrectly
- Capital Lock-Up - Arbitrage doesn't resolve for months
- Fees - Eat into profit at small scales
Mitigation:
- High confidence threshold (60%+)
- Verify prices before execution
- Only trade clear-cut markets
- Minimum profit threshold (2%+)
๐ฐ Cost Analysis
Monthly Costs:
- Polymarket API: $0 (free)
- AWS Bedrock: $0-5 (covered by credits, ~100 requests/day)
- VPS (optional): $5-10
Total: $0-15/month
Compare to old strategy:
- Twitter Pro API: $5,000/month โ
- AWS Bedrock: $25/month
- VPS: $20/month
- Total: $5,045/month โ
Arbitrage wins on cost.
๐ Example Trades
Good Arbitrage (Executed)
Date: 2026-03-02 14:23 UTC
Markets:
- "Florida GOP wins" = 72ยข
- "Florida DEM wins" = 32ยข
- Sum: 104ยข
Action:
- SELL GOP <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>3.00</mn><mi mathvariant="normal">@</mi><mn>0.72</mn><mo stretchy="false">(</mo><mi>c</mi><mi>o</mi><mi>l</mi><mi>l</mi><mi>e</mi><mi>c</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">3.00 @ 0.72 (collect </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3.00@0.72</span><span class="mopen">(</span><span class="mord mathnormal">co</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">ec</span><span class="mord mathnormal">t</span></span></span></span>2.16)
- SELL DEM <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>3.00</mn><mi mathvariant="normal">@</mi><mn>0.32</mn><mo stretchy="false">(</mo><mi>c</mi><mi>o</mi><mi>l</mi><mi>l</mi><mi>e</mi><mi>c</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">3.00 @ 0.32 (collect </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord">3.00@0.32</span><span class="mopen">(</span><span class="mord mathnormal">co</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span><span class="mord mathnormal">ec</span><span class="mord mathnormal">t</span></span></span></span>0.96)
- Total collected: $3.12
Result:
- GOP won (paid $3.00)
- Fees: $0.12 (4%)
- Net profit: $0.00 (break-even)
Lesson: Fees ate the profit. Need bigger discrepancy.
Bad Arbitrage (Rejected)
Date: 2026-03-02 15:47 UTC
Markets:
- "Bitcoin > $100k" YES = 52ยข
- "Bitcoin > $100k" NO = 50ยข
- Sum: 102ยข
Decision: REJECTED
Reason: Discrepancy (2ยข) < min_discrepancy (2ยข) + fees (4ยข)
Expected profit: -2ยข (not worth it)
๐งช Testing
Run all tests
pytest tests/ -v
Test arbitrage components
pytest tests/test_correlation_analyzer.py -v pytest tests/test_arbitrage_detector.py -v
Run with coverage
pytest tests/ --cov=src
๐ Deployment
Local
python -m src.bot_arbitrage --dry-run
Docker
docker-compose up -d bot-arbitrage docker-compose logs -f bot-arbitrage
AWS EC2
See docs/DEPLOYMENT.md for full guide.
Quick setup:
Launch t3.micro instance
Install Docker
Clone repo and configure
docker-compose up -d
Cost: ~$8/month (t3.micro)
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
- Polymarket for the API
- py-clob-client for API wrapper
- Arbitrage theory from academic finance literature
- Amazon Bedrock for optional AI analysis
โก Quick Links
- Arbitrage Strategy Guide - Read this first!
- Configuration Guide - All settings explained
- Deployment Guide - AWS setup
- Polymarket Docs - API reference
โ ๏ธ DISCLAIMER:
- This bot trades with real money (when not in dry-run mode)
- Past performance doesn't guarantee future results
- Start with small amounts you can afford to lose
- Test thoroughly in dry-run mode first
- The authors are not responsible for financial losses
๐ฏ Recommendation:
- Start with $75 capital (as designed)
- Run dry-run for 1 week minimum
- Only go live if consistently profitable in paper trading
- Keep max daily loss at $2
Good luck! ๐