A Python-based automated trading system for Kalshi prediction markets. Features market analysis, real-time WebSocket streaming, and automated market making strategies.
- Market Analysis: Scan thousands of markets for spread opportunities
- Real-time Data: WebSocket streaming for live orderbook and trade updates
- Market Making: Automated bid/ask placement to capture spreads
- Web Dashboard: Flask-based UI for monitoring markets in real-time
- Dual Environment: Support for both demo and production trading
# 1. Clone and install dependencies
git clone https://github.com/eshan327/Kalshi_MM.git
cd Kalshi_MM
pip install -r requirements.txt
# 2. Set up credentials (see Setup section below)
cp Setup/config_template.py Setup/config.py
# Edit Setup/config.py with your API credentials
# 3. Run the universal launcher
python Setup/run_universal.py demo # Safe testing mode
python Setup/run_universal.py prod # Production (real money!)Kalshi_MM/
├── Setup/ # Configuration & API setup
│ ├── apiSetup.py # KalshiAPI client wrapper
│ ├── config_template.py # Template for credentials
│ ├── config.py # Your credentials (gitignored)
│ └── run_universal.py # Universal launcher script
│
├── Strategies/ # Trading strategies
│ └── basicMM.py # Market maker (spread detection + trading)
│
├── Getdata/ # Market data utilities
│ ├── getData.py # Fetch & sort markets by spread
│ ├── filterMarkets.py # Filter markets by type/volume
│ └── orderBookListener.py # Monitor orderbook changes
│
├── Websocket/ # Real-time streaming
│ ├── market_streamer.py # WebSocket client for live data
│ └── websocket_interactive.py # Interactive CLI for streaming
│
├── WebsocketApp/ # Web dashboard
│ ├── app.py # Flask application
│ ├── websocket_handler.py # WebSocket-to-Flask bridge
│ ├── templates/ # HTML templates
│ └── static/ # CSS/JS assets
│
├── visualize_orderbook.py # Orderbook visualization tool
├── requirements.txt # Python dependencies
├── data/ # Output data (gitignored)
└── logs/ # Trade logs (gitignored)
pip install -r requirements.txt- Get your API credentials from Kalshi (Settings → API Keys)
- Create your config file:
cp Setup/config_template.py Setup/config.py- Edit
Setup/config.pywith your credentials:
PRODUCTION_API_KEY_ID = "your-api-key-id-here"
DEMO_API_KEY_ID = "your-demo-api-key-id-here" # Optional- Place your private key files in
Setup/:- Production:
Setup/private_key.pem - Demo:
Setup/private_demo_key.pem
- Production:
python Setup/run_universal.py demo
# Should display account balance and market opportunities# Interactive mode
python Setup/run_universal.py
# Command line mode
python Setup/run_universal.py demo # Demo environment
python Setup/run_universal.py production # Production (real money!)python Strategies/basicMM.pyThis will:
- Fetch all active markets
- Identify opportunities with spread > 3% and volume > 1000
- Save results to
data/marketData/
python Getdata/getData.py --top 20
python Getdata/getData.py --limit 100 --top 10 --output my_markets.json# Stream a specific market
python Websocket/market_streamer.py --market-id KXBTC-25JAN03-T98500
# Interactive mode
python Websocket/websocket_interactive.py --market-id KXBTC-25JAN03-T98500
# Demo environment
python Websocket/market_streamer.py --market-id KXBTC-25JAN03-T98500 --democd WebsocketApp
python app.py
# Open http://localhost:5001The basicMM.py market maker uses a spread capture strategy:
- Scan: Find markets with bid-ask spread > 3% and volume > 1000
- Quote: Place buy order at
bid + 1¢, sell order atask - 1¢ - Capture: Profit from the spread when both orders fill
Example:
Market: "Will BTC exceed $98,500?"
Current: Bid 45¢ / Ask 52¢ (7¢ spread)
Bot places: Buy @ 46¢, Sell @ 51¢
Potential profit: 5¢ per contract
Edit Strategies/basicMM.py to adjust parameters:
# In BasicMM.__init__():
reserve_limit = 10 # Keep $10 in reserve
demo = False # True for demo environment
# In filter_market_opportunities():
min_spread = 0.03 # Minimum 3% spread
min_volume = 1000 # Minimum volume
max_spread = 0.10 # Maximum 10% spreadfrom Setup.apiSetup import KalshiAPI
client = KalshiAPI().get_client(demo=False)
balance = client.get_balance()
markets = client.get_markets(limit=100)from Strategies.basicMM import BasicMM
mm = BasicMM(reserve_limit=10, demo=True)
mm.identify_market_opportunities()
print(f"Found {len(mm.market_opportunities)} opportunities")| Type | Location | Format |
|---|---|---|
| Market opportunities | data/marketData/ |
CSV |
| Orderbook snapshots | data/orderbookData/ |
JSON |
| Trade logs | logs/trade_logs/ |
LOG |
| Price data | WebsocketApp/data/ |
JSON |
| Feature | Demo | Production |
|---|---|---|
| API URL | demo-api.kalshi.co | api.elections.kalshi.com |
| Real money | No | Yes |
| Credentials | DEMO_API_KEY_ID | PRODUCTION_API_KEY_ID |
| Error | Solution |
|---|---|
| "Private key file not found" | Ensure Setup/private_key.pem exists |
| "API key ID not found" | Create Setup/config.py from template |
| WebSocket won't connect | Check credentials, try --demo flag |
| "Invalid status filter" | Pass status=None to get_markets() |
- Always test in demo mode first
- Start with small positions
- Monitor your positions actively
- Set appropriate reserve limits
- Review code before running in production
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - Use at your own risk.