A Python trading bot for Kalshi prediction markets that identifies high-probability opportunities and compounds profits.
- Scan for markets matching your category filter (e.g., college basketball)
- Filter by volume, liquidity, and probability thresholds
- Enter YES positions on qualifying markets
- Exit when profit target is reached (default: 6.5%) or stop-loss triggers
- Compound profits into subsequent trades
- Python 3.10+
- Kalshi account with API access
- API key and private key from Kalshi
# Clone the repository
git clone https://github.com/matthew-jin/Kalshi-Volume-Bot.git
cd Kalshi-Volume-Bot
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -e .macOS note: If you installed Python from python.org and get SSL certificate errors, run:
/Applications/Python\ 3.XX/Install\ Certificates.commandCopy the example environment file and add your credentials:
cp .env.example .envEdit .env with your Kalshi API credentials:
# For production trading:
KALSHI_ENVIRONMENT=production
KALSHI_PROD_API_KEY_ID=your_api_key_id_here
KALSHI_PROD_PRIVATE_KEY_PATH=/absolute/path/to/your/private_key.pem
# For sandbox/demo testing:
KALSHI_ENVIRONMENT=sandbox
KALSHI_SANDBOX_API_KEY_ID=your_sandbox_key_id_here
KALSHI_SANDBOX_PRIVATE_KEY_PATH=/absolute/path/to/your/sandbox_key.pemTo get your API credentials:
- Go to Kalshi Settings (or demo site for sandbox)
- Create a new API key
- Save the Key ID and download the private key PEM file
- Set the paths in your
.envfile (use absolute paths)
python scripts/run_bot.py
# With debug logging
python scripts/run_bot.py --log-level DEBUGAll trading parameters are in config/config.yaml:
kalshi:
environment: production # sandbox or production
trading:
# Market filtering
market_category: college_basketball # all, crypto, weather, politics, economics, sports, player_props, college_basketball
liquidity_threshold_usd: 0 # Minimum orderbook liquidity in USD (0 for markets with indicative quotes only)
min_market_volume: 10000 # Minimum contracts traded to consider a market
include_live_markets: false # Set to false to skip games already in progress
# Entry thresholds
probability_threshold: 0.70 # Minimum probability to enter (0.5 - 0.99)
max_probability_threshold: 0.90 # Maximum probability (hard cap, never buy above 90c)
# Exit conditions
profit_target_percent: 0.065 # Exit at 6.5% profit
stop_loss_percent: 0.1 # Exit if down 10% (null = disabled)
stop_loss_min_volume: 100000 # Only apply stop-loss to markets with this volume+
# Position sizing
min_position_percent: 0.02 # Min % of portfolio per trade
max_position_percent: 0.10 # Max % of portfolio per trade
max_concurrent_positions: 4 # Max open positions at once
min_contracts: 1 # Minimum contracts per trade
compound_profits: true # Reinvest profits into position sizing
# Timing
scan_interval_seconds: 30 # How often to scan for opportunities
order_timeout_seconds: 300 # Cancel unfilled orders after 5 minutes
max_hours_until_close: 0 # Only consider markets closing within N hours (0 = no limit)
# Safety
dry_run: false # Scan and log without placing real orders
logging:
level: INFO
file: logs/bot.logSettings can also be overridden via environment variables:
KALSHI_ENVIRONMENT=production
TRADING_LIQUIDITY_THRESHOLD_USD=50000
TRADING_PROBABILITY_THRESHOLD=0.85
TRADING_PROFIT_TARGET_PERCENT=0.07| Category | Markets |
|---|---|
all |
All open markets |
crypto |
Bitcoin, Ethereum, crypto prices |
weather |
Temperature, storms, precipitation |
politics |
Elections, policy, government |
economics |
Fed rates, inflation, GDP, jobs |
sports |
NFL, NBA, championships |
player_props |
Player-level stat markets |
college_basketball |
NCAAB game winners, spreads, totals |
├── config/
│ ├── settings.py # Pydantic configuration
│ └── config.yaml # User settings
├── src/
│ ├── api/ # Kalshi API client
│ ├── models/ # Data models
│ ├── scanner/ # Market scanning & filtering
│ ├── strategy/ # Trading strategy
│ ├── executor/ # Order execution
│ ├── portfolio/ # Portfolio tracking
│ └── core/ # Main bot orchestrator
├── scripts/
│ └── run_bot.py # Entry point
├── tests/ # Test suite
└── logs/ # Log files
logs/bot.log- General bot activitylogs/trades.log- Entry and exit records with prices
- Sandbox mode: Test with demo money before going live
- Dry run mode: Scan and log opportunities without placing orders
- Position limits: Cap maximum concurrent positions and per-trade sizing
- Hard price cap: Never buys above 90c entry price
- Stop-loss: Optional automatic loss limiting (with volume threshold to avoid noisy low-volume markets)
- Volume filter: Skip markets with insufficient trading activity
- Rate limiting: Respects Kalshi API limits (5 req/sec)
- Graceful shutdown: Ctrl+C stops cleanly with daily summary
This bot trades real money when in production mode. Always:
- Start with sandbox mode for testing
- Use small position sizes initially
- Monitor the bot regularly
- Understand that past performance doesn't guarantee future results
- Never invest more than you can afford to lose
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with debug logging
python scripts/run_bot.py --log-level DEBUGMIT