A Python-based automated trading bot for weather derivatives on Kalshi. Features live P&L tracking, forecast fusion, risk management, and portfolio analytics.
- Automated Trading: Real-time decision making based on weather forecasts and market prices
- Forecast Fusion: Combines multiple weather sources (NWS, OpenMeteo, ensemble methods)
- Risk Management: Portfolio-level risk constraints, position sizing, concentration limits
- Order Management: Smart order amendment for improved fill execution
- P&L Tracking: Real-time profit/loss analytics with daily breakdown
- Forecast Accuracy: Calibration tracking and forecast outcome resolution
- Correlation Hedging: Portfolio correlation analysis to reduce systematic risk
- Greeks-lite: Delta exposure and volatility detection
- Live Dashboard: Streamlit dashboard for performance visualization
- Python 3.10+
- pip / conda
- Git
# Clone repository
git clone https://github.com/yourusername/kalshi-trading-bot.git
cd kalshi-trading-bot
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt- Create
.envfile with your settings:
# API Keys
KALSHI_API_KEY=your_key_here
KALSHI_API_SECRET=your_secret_here
# Trading Parameters
MAX_TOTAL_RISK_DOLLARS=60.0
TRADE_STEP=1
BASE_TARGET=1
MAX_TARGET=2
MIN_EDGE_CENTS=0.5
# Feature Toggles
ENABLE_CORRELATION_HEDGE=true
ENABLE_ORDER_AMENDING=true
ENABLE_GREEK_ALERTS=true- Place API keys in
keys/directory (never commit!)
python src/run_bot.pystreamlit run src/dashboard.pypython src/check_pnl.py # P&L analysis
python src/check_fills.py # Trade statistics
python src/check_forecast.py # Forecast accuracy
python src/check_correlation.py # Portfolio diversification
python src/check_balance.py # Account balance
python src/check_greeks.py # Portfolio Greeks
python src/check_trading_activity.py # Recent tradesβββ src/
β βββ run_bot.py # Main trading loop
β βββ db.py # Database schema & analytics
β βββ kalshi_client.py # Kalshi API client
β βββ weather_sources.py # Forecast providers
β βββ nws.py # NWS integration
β βββ dashboard.py # Streamlit analytics UI
β βββ check_*.py # Diagnostic scripts
β βββ liquidate_positions.py # Emergency position liquidation
β βββ backfill_climo.py # Historical data backfill
βββ data/
β βββ kalshi_quotes.sqlite # SQLite database (trading data)
βββ keys/ # API credentials (DO NOT COMMIT)
βββ .env # Configuration (DO NOT COMMIT)
βββ requirements.txt # Python dependencies
βββ README.md # This file
- quotes: Market price snapshots (bid/ask)
- trades: Executed trades (buys/sells)
- positions: Current holdings by ticker
- forecast_predictions: Model predictions
- provider_readings: Raw weather data
- outcomes: Resolved market outcomes
- correlations: Position correlations
The bot identifies profitable trades by computing the expected value vs. market prices. Only trades with edge > MIN_EDGE_CENTS are executed.
MAX_TOTAL_RISK_DOLLARS: Portfolio-level risk capMAX_ABS_QTY_PER_TICKER: Concentration limit per marketPERSIST_SECONDS: Minimum hold time to reduce noise
Predictions are tracked and compared to actual outcomes for model calibration. Accuracy metrics by provider/series help tune parameters.
- Realized: Closed positions (locked-in gains/losses)
- Unrealized: Open positions marked-to-market
- Daily breakdown: Performance by trading date
- Push code to GitHub
- Go to streamlit.io
- Connect repo and deploy
src/dashboard.py - Add secrets in Streamlit dashboard settings
See DEPLOYMENT.md for cloud deployment options.
Real-time metrics displayed on dashboard:
- Sharpe Ratio: Risk-adjusted returns (annualized)
- Win Rate: % of profitable trades
- Portfolio Risk: Current risk usage vs. limit
- Equity Curve: Cumulative P&L over time
- Daily P&L: Breakdown by date
- Forecast Fusion: Combine multiple weather forecasts
- Market Analysis: Get current quotes and compute fair value
- Candidate Generation: Identify mispricings vs. forecasts
- Risk Checks: Verify position doesn't exceed constraints
- Order Execution: Place limit orders via Kalshi API
- Order Management: Monitor and amend stale orders
- P&L Tracking: Log trades and update positions
- Emergency Liquidation:
liquidate_positions.pyfor rapid exit - Stale Quote Detection: Skip trades when prices are old
- Liquidity Checks: Verify bid-ask depth before trading
- Manual Controls: Easy parameter tuning via
.env
python src/check_greeks.py # Check portfolio Greeks
python src/check_trading_activity.py # Verify recent trades
python src/check_balance.py # Confirm account fundingrm data/kalshi_quotes.sqlite*
# Bot will reinitialize on next run- Verify
KALSHI_API_KEYandKALSHI_API_SECRETin.env - Check network connectivity and Kalshi API status
- Review logs in terminal output
Contributions welcome! Please:
- Create feature branch
- Add tests for new functionality
- Update docs and README
- Submit pull request
Real-time alerts and diagnostics already built in:
- Volatility spike detection
- Portfolio concentration warnings
- Fill quality analytics
- Forecast calibration tracking
MIT License - See LICENSE file
This bot trades real capital on Kalshi. Use at your own risk. Past performance is not indicative of future results. Always test thoroughly in paper trading first.
For issues or questions:
- Check diagnostics:
python src/check_*.py - Review logs in terminal
- Check
.envconfiguration - Open GitHub issue with details
kalshi bot sells and buys stock based off statistics
04eec4092ca85ec18cee494e28377c296acb4fb1