GitHub - tufstraka/polybot (original) (raw)

๐ŸŽฏ Polybot - Multi-Market Arbitrage Bot

Find risk-free profit on Polymarket by exploiting pricing inefficiencies across related markets.

Python 3.10+ License: MIT AWS Bedrock


๐Ÿš€ What Changed?

Old Strategy: Mean reversion (spike trading)

New Strategy: Multi-Market Arbitrage


๐Ÿ’ก 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:

3. Review After 1 Week

Check these metrics:

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?


๐Ÿ“š Documentation


๐Ÿ—๏ธ 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?

  1. Execution Failure - Prices move before you execute
  2. False Positives - Misidentified relationships
  3. Resolution Risk - Market resolves incorrectly
  4. Capital Lock-Up - Arbitrage doesn't resolve for months
  5. Fees - Eat into profit at small scales

Mitigation:


๐Ÿ’ฐ Cost Analysis

Monthly Costs:

Total: $0-15/month

Compare to old strategy:

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



โš ๏ธ DISCLAIMER:

๐ŸŽฏ Recommendation:

Good luck! ๐Ÿš€