A high-performance, production-ready arbitrage trading system for cross-platform prediction markets. Automatically detects and executes arbitrage opportunities between Kalshi and Polymarket with sub-millisecond latency.
This arbitrage bot exploits price inefficiencies across prediction market platforms by simultaneously purchasing complementary outcomes (YES/NO) when their combined cost is less than the guaranteed $1.00 payout. The system features:
- Real-time monitoring via WebSocket connections to both platforms
- Sub-millisecond arbitrage detection using SIMD-accelerated algorithms
- Concurrent order execution with automatic position reconciliation
- Comprehensive risk management including circuit breakers and position limits
- Full trade history tracking with SQLite database and analytics tools
- Beginner-friendly with extensive documentation for non-technical users
Complete setup and usage documentation is available in the doc/ folder.
- Getting Started Guide - System overview and prerequisites
- Installation Guide - Platform-specific installation (Windows/Mac/Linux)
- Credentials Setup - API key configuration for both platforms
- Configuration Guide - Environment variables and advanced settings
- Running the Bot - Operational procedures and monitoring
- Troubleshooting - Common issues and solutions
PDF Version: Complete User Guide (PDF)
- Cross-Platform Arbitrage: Kalshi ↔ Polymarket and same-platform opportunities
- Real-Time Price Feeds: WebSocket connections for instant market updates
- Atomic Orderbook Cache: Lock-free data structures for zero-copy updates
- SIMD Acceleration: Parallel arbitrage detection across multiple markets
- Concurrent Execution: Simultaneous order placement on both platforms
- Automatic Reconciliation: Position balancing for mismatched fills
- Circuit Breaker System: Configurable limits for positions, losses, and errors
- Position Tracking: Real-time P&L and exposure monitoring
- Dry-Run Mode: Paper trading for testing without capital risk
- Fee Optimization: Automatic fee calculation and profit validation
- SQLite Database: Persistent storage of all trading activity
- Trade Analytics: Performance metrics, success rates, and execution statistics
- CSV Export: Data export for external analysis
- Historical Queries: Comprehensive reporting on trades and opportunities
# 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 --releaseDetailed installation guide: Installation Guide
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=infoComplete credentials setup guide: Getting Your Credentials | Configuration Setup
# Dry run (paper trading)
dotenvx run -- cargo run --release
# Live execution
DRY_RUN=0 dotenvx run -- cargo run --releaseRunning the bot guide: Running the Bot
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
| 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) |
| 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 |
| 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 |
| 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
- 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
- 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
The system includes a comprehensive SQLite database that automatically records all trading activity, providing persistent storage and advanced analytics capabilities.
# View recent trading activity
cargo run --bin trading_history
# Display today's performance summary
cargo run --bin trading_history summary
# Generate all-time statistics
cargo run --bin trading_history stats
# Export complete trade history to CSV
cargo run --bin trading_history export- Complete Trade Logging: Every fill recorded with timestamp, price, size, and fees
- Opportunity Tracking: All detected arbitrage opportunities (executed and missed)
- Performance Metrics: Success rates, execution latency, and profit statistics
- Time-Series Analysis: Daily, weekly, and monthly performance summaries
- Data Export: CSV format compatible with Excel, Python, and R
- SQL Access: Direct database queries for custom analysis
Documentation: Detailed usage instructions available in README_DATABASE.md
# Full logging, dry run
RUST_LOG=debug DRY_RUN=1 dotenvx run -- cargo run --release# Inject synthetic arb to test execution path
TEST_ARB=1 DRY_RUN=0 dotenvx run -- cargo run --release# Live trading with circuit breaker
DRY_RUN=0 CB_MAX_DAILY_LOSS=10000 dotenvx run -- cargo run --release# Clear cache and re-fetch all market mappings
FORCE_DISCOVERY=1 dotenvx run -- cargo run --releasePrediction markets guarantee that complementary outcomes sum to $1.00 (YES + NO = $1.00). This fundamental property creates arbitrage opportunities when:
Best YES ask (Platform A) + Best NO ask (Platform B) < $1.00
Kalshi YES ask: $0.42
Polymarket NO ask: $0.56
──────────────────────────
Total acquisition: $0.98
Guaranteed payout: $1.00
Risk-free profit: $0.02 per contract pair
The system continuously monitors all available markets across both platforms, detecting these inefficiencies in real-time and executing trades within microseconds of discovery.
| 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) |
- Kalshi:
ceil(0.07 × contracts × price × (1-price))- factored into arb detection - Polymarket: Zero trading fees
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
- Lock-Free Architecture: Atomic operations for zero-copy orderbook updates
- SIMD Optimization: Parallel computation achieving sub-millisecond arbitrage detection
- Concurrent Execution: Asynchronous order placement across multiple platforms
- Intelligent Caching: Market discovery with incremental updates and persistence
- Risk Management: Multi-layered protection including circuit breakers and position limits
cargo testcargo build --release --features profilingcargo bench- Kalshi REST API and WebSocket client
- Polymarket REST API and WebSocket client
- Lock-free atomic orderbook cache
- SIMD-accelerated arbitrage detection
- Concurrent multi-platform order execution
- Real-time position and P&L tracking
- SQLite trade history database
- Comprehensive analytics and reporting
- Circuit breaker risk management
- Intelligent market discovery with caching
- Complete documentation suite
- Configuration management interface
- Multi-account portfolio support
- Advanced order routing algorithms
- Enhanced performance analytics dashboard
- Machine learning integration for opportunity prediction
Additional trading systems with advanced strategies are currently in development. These will feature enhanced algorithmic trading capabilities and sophisticated market analysis tools. For updates and inquiries, contact:
The system monitors prediction markets across multiple professional sports leagues:
| Sport | Leagues |
|---|---|
| Soccer | English Premier League, Bundesliga, La Liga, Serie A, Ligue 1, UEFA Champions League, UEFA Europa League, EFL Championship |
| Basketball | NBA |
| American Football | NFL, NCAAF |
| Hockey | NHL |
| Baseball | MLB |
| Soccer (Americas) | MLS |
Market coverage includes moneyline, spread, total, and both-teams-to-score (BTTS) market types where available on both platforms.
For operational issues, consult the Troubleshooting Guide which covers:
- Platform-specific installation procedures
- API credential configuration errors
- Runtime and execution issues
- Network connectivity problems
- Performance optimization
| Error | Resolution |
|---|---|
cargo: command not found |
Install Rust toolchain - see Installation Guide |
KALSHI_API_KEY_ID not set |
Configure environment variables - see Configuration Guide |
No market pairs found |
Force discovery refresh or check market hours - see Troubleshooting Guide |
| No trade execution | Verify DRY_RUN=0 and circuit breaker thresholds |
Important Notices:
- Testing Required: Always begin with
DRY_RUN=1to validate configuration without capital exposure - Position Sizing: Start with minimal position sizes when transitioning to live trading
- Active Monitoring: Regular oversight is essential, particularly during initial operation
- Credential Security: API keys and private keys must be kept confidential and never committed to version control
- No Financial Advice: This software is provided for informational and educational purposes only. Users assume all risks associated with trading activities
- No Guarantees: Past performance and simulated results do not guarantee future outcomes
- Regulatory Compliance: Users are responsible for ensuring compliance with applicable laws and regulations in their jurisdiction
This project provides a production-ready arbitrage trading system designed to be accessible to both technical and non-technical users. The comprehensive documentation in the doc/ folder includes step-by-step instructions for setup and operation, making sophisticated algorithmic trading accessible to users of all experience levels.
The system is built with Rust for maximum performance and reliability, utilizing modern concurrency patterns and zero-copy optimization techniques to achieve institutional-grade execution speeds.
Contributions are welcome from developers interested in prediction market technology and algorithmic trading systems. Please review the codebase architecture and existing patterns before submitting pull requests.
- Telegram: @MistKail
- X (Twitter): @MistKail
- GitHub: mistKail
- Documentation: Comprehensive guides are available in the documentation folder
- Bug Reports: Submit issues via GitHub's issue tracker
- Feature Requests: Proposals for enhancements can be discussed via GitHub issues or Telegram
This software is dual-licensed under your choice of:
- Apache License 2.0 (LICENSE-APACHE or apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or opensource.org/licenses/MIT)
This software is provided "as is" without warranty of any kind. Users assume all responsibility for trading decisions and outcomes. The authors and contributors are not liable for any financial losses incurred through the use of this software.
Search Terms: polymarket arbitrage, kalshi arbitrage, prediction market arbitrage, cross-platform trading, automated market making, algorithmic trading, SIMD optimization, lock-free concurrency, high-frequency trading, sports prediction markets, cryptocurrency trading bot, Rust financial systems, WebSocket trading, arbitrage detection, market microstructure
To begin using the arbitrage bot, follow the documentation in sequence:
- Getting Started → 2. Installation → 3. Credentials → 4. Configuration → 5. Running the Bot
For technical inquiries or support, contact:
- Telegram: @Blacksky
