Polymarket-Kalshi Arbitrage Bot
Polymarket-Kalshi Arbitrage Bot
An arbitrage system for cross-platform prediction market trading between Kalshi and Polymarket.
<div align="center">π― Perfect for Beginners! This bot is designed specifically for people who don't know how to code. Even if you've never written a single line of code, you can use this bot with our comprehensive step-by-step guides. No programming experience required!
π IMPORTANT: Please Refer to the Complete Documentation
β οΈ CRITICAL: Before starting, please refer to our comprehensive documentation in the doc/ folder for detailed step-by-step guides, troubleshooting, and complete setup instructions.

π Click here to start with the Getting Started Guide | π Download Complete PDF Guide
All guides are designed for beginners with no coding experience - everything is explained step-by-step!
</div>π What is this? This bot automatically monitors prices on both platforms and executes trades when it finds opportunities where you can buy both YES and NO for less than $1.00, guaranteeing a profit when the market resolves.
π What's Coming Next: I'm developing other innovative arbitrage bots with revolutionary strategies. Stay tuned for more advanced trading systems!
Quick Start
1. Install Dependencies
# Rust 1.75+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Navigate to project directory
cd prediction-market-arbitrage # or your project directory name
# Build
cargo build --release
π Detailed installation guide: Installation Guide
2. Set Up Credentials
Create a .env file:
# === KALSHI CREDENTIALS ===
KALSHI_API_KEY_ID=your_kalshi_api_key_id
KALSHI_PRIVATE_KEY_PATH=/path/to/kalshi_private_key.pem
# === POLYMARKET CREDENTIALS ===
POLY_PRIVATE_KEY=0xYOUR_WALLET_PRIVATE_KEY
POLY_FUNDER=0xYOUR_WALLET_ADDRESS
# === BOT CONFIGURATION ===
DRY_RUN=1
RUST_LOG=info
π Complete credentials setup guide: Getting Your Credentials | Configuration Setup
3. Run
# Dry run (paper trading)
dotenvx run -- cargo run --release
# Live execution
DRY_RUN=0 dotenvx run -- cargo run --release
π Running the bot guide: Running the Bot
π Documentation
β οΈ CRITICAL: Before Starting - Read the Documentation!
This README provides a quick overview. For complete setup instructions, troubleshooting, and detailed explanations, you MUST refer to the comprehensive documentation in the
doc/folder. All guides are designed for beginners with no coding experience.
Follow these comprehensive guides in order:
- π Getting Started Guide - Overview and introduction - START HERE!
- π§ Installation Guide - Install Rust and dependencies (Windows/Mac/Linux)
- π Getting Your Credentials - Get API keys from Kalshi and Polymarket
- βοΈ Configuration Setup - Complete guide to all configuration options
- βΆοΈ Running the Bot - Start and monitor your bot
- π§ Troubleshooting - Common problems and solutions
π PDF Version: A complete PDF guide combining all documentation: π₯ Download Polymarket-Kalshi-Arbitrage-Bot-User-Guide.pdf
Why refer to the documentation?
- β Step-by-step instructions for every step
- β Screenshots and visual guides
- β Troubleshooting for common issues
- β Configuration explanations
- β Safety warnings and best practices
- β Written specifically for non-technical users
Environment Variables
Required
| Variable | Description |
|----------|-------------|
| KALSHI_API_KEY_ID | Your Kalshi API key ID |
| KALSHI_PRIVATE_KEY_PATH | Path to RSA private key (PEM format) for Kalshi API signing |
| POLY_PRIVATE_KEY | Ethereum private key (with 0x prefix) for Polymarket wallet |
| POLY_FUNDER | Your Polymarket wallet address (with 0x prefix) |
Bot Configuration
| Variable | Default | Description |
|----------|---------|-------------|
| DRY_RUN | 1 | 1 = paper trading (no orders), 0 = live execution |
| RUST_LOG | info | Log level: error, warn, info, debug, trace |
| FORCE_DISCOVERY | 0 | 1 = re-fetch market mappings (ignore cache) |
| PRICE_LOGGING | 0 | 1 = verbose price update logging |
Test Mode
| Variable | Default | Description |
|----------|---------|-------------|
| TEST_ARB | 0 | 1 = inject synthetic arb opportunity for testing |
| TEST_ARB_TYPE | poly_yes_kalshi_no | Arb type: poly_yes_kalshi_no, kalshi_yes_poly_no, poly_same_market, kalshi_same_market |
Circuit Breaker
| Variable | Default | Description |
|----------|---------|-------------|
| CB_ENABLED | true | Enable/disable circuit breaker |
| CB_MAX_POSITION_PER_MARKET | 100 | Max contracts per market |
| CB_MAX_TOTAL_POSITION | 500 | Max total contracts across all markets |
| CB_MAX_DAILY_LOSS | 5000 | Max daily loss in cents before halt |
| CB_MAX_CONSECUTIVE_ERRORS | 5 | Consecutive errors before halt |
| CB_COOLDOWN_SECS | 60 | Cooldown period after circuit breaker trips |
π Detailed configuration guide: Configuration Setup
Obtaining Credentials
Kalshi
- Log in to Kalshi
- Go to Settings β API Keys
- Create a new API key with trading permissions
- Download the private key (PEM file)
- Note the API Key ID
Polymarket
- Create or import an Ethereum wallet (MetaMask, etc.)
- Export the private key (include
0xprefix) - Fund your wallet on Polygon network with USDC
- The wallet address is your
POLY_FUNDER
π Step-by-step credentials guide: Getting Your Credentials
Usage Examples
Paper Trading (Development)
# Full logging, dry run
RUST_LOG=debug DRY_RUN=1 dotenvx run -- cargo run --release
Test Arbitrage Execution
# Inject synthetic arb to test execution path
TEST_ARB=1 DRY_RUN=0 dotenvx run -- cargo run --release
Production
# Live trading with circuit breaker
DRY_RUN=0 CB_MAX_DAILY_LOSS=10000 dotenvx run -- cargo run --release
Force Market Re-Discovery
# Clear cache and re-fetch all market mappings
FORCE_DISCOVERY=1 dotenvx run -- cargo run --release
How It Works
Arbitrage Mechanics
In prediction markets, YES + NO = $1.00 guaranteed.
Arbitrage exists when:
Best YES ask (platform A) + Best NO ask (platform B) < $1.00
Example:
Kalshi YES ask: 42Β’
Poly NO ask: 56Β’
Total cost: 98Β’
Guaranteed: 100Β’
Profit: 2Β’ per contract
Four Arbitrage Types
| Type | Buy | Sell |
|------|-----|------|
| poly_yes_kalshi_no | Polymarket YES | Kalshi NO |
| kalshi_yes_poly_no | Kalshi YES | Polymarket NO |
| poly_same_market | Polymarket YES + NO | (rare) |
| kalshi_same_market | Kalshi YES + NO | (rare) |
Fee Handling
- Kalshi:
ceil(0.07 Γ contracts Γ price Γ (1-price))- factored into arb detection - Polymarket: Zero trading fees
Architecture
src/
βββ main.rs # Entry point, WebSocket orchestration
βββ types.rs # MarketArbState
βββ execution.rs # Concurrent leg execution, in-flight deduplication
βββ position_tracker.rs # Channel-based fill recording, P&L tracking
βββ circuit_breaker.rs # Risk limits, error tracking, auto-halt
βββ discovery.rs # KalshiβPolymarket market matching
βββ cache.rs # Team code mappings (EPL, NBA, etc.)
βββ kalshi.rs # Kalshi REST/WS client
βββ polymarket.rs # Polymarket WS client
βββ polymarket_clob.rs # Polymarket CLOB order execution
βββ config.rs # League configs, thresholds
Key Features
- β Lock-free orderbook cache using atomic operations
- β SIMD-accelerated arbitrage detection for sub-millisecond latency
- β Concurrent order execution with automatic position reconciliation
- β Circuit breaker protection with configurable risk limits
- β Intelligent market discovery with caching and incremental updates
Development
Run Tests
cargo test
Enable Profiling
cargo build --release --features profiling
Benchmarks
cargo bench
Project Status
β Completed Features
- β Kalshi REST/WebSocket client
- β Polymarket REST/WebSocket client
- β Lock-free orderbook cache
- β SIMD arb detection
- β Concurrent order execution
- β Position & P&L tracking
- β Circuit breaker
- β Market discovery & caching
- β Beginner-friendly documentation and guides
π§ Future Enhancements
- [ ] Risk limit configuration UI
- [ ] Multi-account support
- [ ] Advanced order routing strategies
- [ ] Historical performance analytics dashboard
π Coming Soon
I'm actively developing other innovative arbitrage bots with revolutionary strategies. These will feature advanced trading algorithms and cutting-edge market analysis techniques. Stay updated by following this repository or contacting me on Telegram @terauss!
Supported Markets
The bot supports multiple sports leagues:
- Soccer: EPL, Bundesliga, La Liga, Serie A, Ligue 1, UCL, UEL, EFL Championship
- Basketball: NBA
- Football: NFL
- Hockey: NHL
- Baseball: MLB, MLS
- College Football: NCAAF
Troubleshooting
Having problems? Check the Troubleshooting Guide for:
- Installation issues
- Credential problems
- Runtime errors
- Connection issues
- Performance problems
Common issues:
- "cargo: command not found" β Installation Guide
- "KALSHI_API_KEY_ID not set" β Configuration Guide
- "No market pairs found" β Troubleshooting Guide
- Bot won't execute trades β Check
DRY_RUNsetting and circuit breaker limits
Safety & Warnings
β οΈ Important Safety Notes:
- Always start with
DRY_RUN=1- Test mode lets you verify everything works without risking real money - Start with small amounts - Even when going live, use small position sizes initially
- Monitor your bot - Check on it regularly, especially when starting
- Keep credentials secret - Never share your API keys or private keys
- This is not financial advice - Trade at your own risk
About This Project
This bot was created with beginners in mind. You don't need to know how to code to use it - just follow the guides in the doc/ folder. Whether you're a complete beginner or an experienced trader, this bot makes arbitrage trading accessible to everyone.
Upcoming Projects: I'm working on other arbitrage bots with revolutionary strategies and advanced features. This beginner-friendly bot is just the first in a series of innovative trading systems I'm developing.
Contributing
Contributions are welcome! This project is open source and designed to help the prediction market trading community, especially those new to automated trading.
Support & Contact
π¬ Need help? Contact me on Telegram: @terauss
π Documentation: Check the documentation folder for detailed guides
π Issues: Report bugs or request features on GitHub
License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Related Projects & Keywords
Keywords: polymarket arbitrage bot, polymarket-kalshi arbitrage bot, kalshi-poly arbitrage, poly-poly arbitrage, kalshi-kalshi arbitrage, kalshi arbitrage, prediction market arbitrage, cross-platform trading bot, automated trading, sports betting arbitrage, Rust trading bot
Ready to start? Follow the guides in order:
- Getting Started β 2. Installation β 3. Credentials β 4. Configuration β 5. Running the Bot