A Python-based dashboard for analyzing Kalshi prediction markets with AI-powered screening capabilities and interactive visualizations.
- Interactive Dashboard: Streamlit-based web interface for market analysis
- AI-Powered Screening: Natural language queries using Gemini AI for custom market filtering
- Configurable Criteria: Customizable screening parameters (volume, spread, liquidity, etc.)
- Market Analysis: Detailed scoring system based on multiple factors
- On-Demand Data: Fetch and analyze current market data with manual refresh
- Portfolio Tracking: Complete portfolio management with accurate P&L calculations
- API Integration: Full integration with Kalshi's Python SDK
- Clean Architecture: Streamlined codebase without real-time websocket dependencies
- Clone the repository:
git clone <repository-url>
cd event_betting- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
# Create .env file with your Kalshi API credentials
# See SETUP.md for detailed instructionsCreate a .env file with your Kalshi API credentials. See SETUP.md for detailed instructions:
# Kalshi API Configuration
KALSHI_API_KEY_ID=your-api-key-id-here
KALSHI_PRIVATE_KEY_PATH=path/to/private_key.pem
# Environment (demo or production)
KALSHI_DEMO_MODE=true
KALSHI_API_HOST=https://api.elections.kalshi.com/trade-api/v2
# Dashboard Configuration
DASHBOARD_PORT=8501
DASHBOARD_HOST=localhost
# Optional: Gemini AI Configuration
GEMINI_API_KEY=your-gemini-api-key-hereImportant: This dashboard uses proper Kalshi API authentication following the official documentation. You need to:
- Generate API credentials from your Kalshi account
- Save your private key as a
.pemfile - Configure the environment variables
- (Optional) Get a Gemini API key for AI features
Use the startup script (recommended):
./run_dashboard.shOr run directly with Streamlit:
streamlit run dashboard/dashboard.pyThe dashboard will be available at http://localhost:8501
- Complete Portfolio Tracking: Cash balance, positions, and accurate P&L calculations
- Real-time Market Values: Current market prices and position values
- Performance Analytics: Realized and unrealized P&L with detailed breakdowns
- Position Management: View all active and closed positions with trading history
- P&L Charts: Visual representation of trading performance over time
- AI-Powered Screening: Use natural language to create custom market filters
- Interactive Tables: Sortable and filterable market data
- Visual Analytics: Charts and graphs for market distribution and trends
- Market Details: Detailed view of individual markets with full information
- Custom Filtering: Advanced filtering options for market characteristics
- On-Demand Data: Manual refresh for current market data
The dashboard can filter and analyze markets based on:
- Volume: Trading volume requirements (total and 24h)
- Spread: Bid-ask spread analysis (percentage and cents)
- Liquidity: Market liquidity requirements
- Time to Close: Days until market close
- Category: Market categories (politics, economics, etc.)
- Price Range: Market price ranges and volatility
- AI Queries: Natural language filtering with Gemini AI
The dashboard includes advanced AI features powered by Google Gemini:
- Natural Language Queries: Ask questions like "Show me markets closing soon with high volume" or "Find undervalued political markets"
- Custom Screening Functions: AI generates Python code to filter markets based on your specific criteria
- Interactive Code Editing: Review and modify AI-generated screening logic
- Smart Market Insights: Get AI-powered analysis of market trends and opportunities
- "Markets with tight spreads and high liquidity"
- "Election markets closing in the next 30 days"
- "Undervalued markets with recent volume spikes"
- "Markets where the probability seems disconnected from fundamentals"
The dashboard provides comprehensive portfolio management:
- Total Portfolio Value: Cash + current market value of all positions
- Cash Balance: Available funds for trading
- Position Value: Current market value of all holdings
- Position Count: Number of active positions
- 24-Hour P&L: Realized gains/losses from completed trades
- Trading Activity: Number of trades and total volume
- Return Percentage: Performance relative to portfolio size
- Top Positions: Largest holdings by value
The dashboard uses a realized P&L approach for performance tracking:
- Tracks actual gains/losses from completed trades
- Calculates based on trade fills from the last 24 hours
- Shows trading volume and activity metrics
- Simple and transparent - no complex historical tracking required
All portfolio data comes directly from the Kalshi Portfolio API:
/portfolio/balance- Cash balance/portfolio/positions- Current positions/portfolio/fills- Trading history for P&L calculation
event_betting/
├── main.py # Main application entry point
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── run_dashboard.sh # Quick start script
├── README.md # This file
├── SETUP.md # Detailed setup instructions
├── dashboard/ # Dashboard application
│ ├── __init__.py
│ ├── dashboard.py # Main dashboard interface
│ ├── main.py # Alternative dashboard entry point
│ ├── portfolio.py # Portfolio management page
│ ├── screener.py # Market screening page
│ └── constants.py # Dashboard constants
├── kalshi/ # Kalshi API integration
│ ├── __init__.py
│ ├── client.py # Kalshi API client
│ ├── models.py # Data models and classes
│ ├── portfolio_functions.py # Portfolio calculations
│ ├── market_functions.py # Market data functions
│ ├── websocket.py # WebSocket functionality (optional)
│ └── ...
├── screening/ # Market screening logic
│ ├── __init__.py
│ ├── market_screener.py # Rule-based screening
│ └── gemini_screener.py # AI-powered screening
└── tests/ # Test utilities
├── test_setup.py
└── ...
To use the dashboard, you'll need:
- Kalshi API Key ID: Get from your Kalshi account profile
- RSA Private Key: Generated by Kalshi (saved as .pem file)
- Gemini API Key: For AI-powered features (get from Google AI Studio)
The application uses proper RSA-PSS signature authentication as specified in the Kalshi API documentation. This provides better security and follows Kalshi's recommended authentication method.
Note: Portfolio features require authentication. The dashboard will show "Login required for portfolio data" if not properly authenticated.
The application logs to console:
- Dashboard startup and status
- API connection status
- Error messages
- User interactions
- Update
ScreeningCriteriainkalshi/models.py - Add filtering logic in
screening/market_screener.py - Update dashboard UI in
dashboard/dashboard.py - Add AI prompts in
screening/gemini_screener.pyfor natural language support
The dashboard is built with Streamlit and can be customized by modifying files in the dashboard/ directory:
- Main Interface:
dashboard/dashboard.py- Primary dashboard layout - Portfolio Page:
dashboard/portfolio.py- Portfolio management features - Screener Page:
dashboard/screener.py- Market screening interface - Constants:
dashboard/constants.py- UI configuration and defaults
Customization Options:
- Add new charts and visualizations
- Modify the layout and styling
- Add new filtering and analysis options
- Integrate additional AI capabilities
- Extend portfolio tracking features
- API Connection Failed: Check your API credentials and network connection
- No Markets Found: Verify the API is returning data and check filters
- Dashboard Not Loading: Ensure Streamlit is installed and port is available
- AI Features Not Working: Verify your Gemini API key is set in the
.envfile - Portfolio Data Missing: Check that your Kalshi API credentials are valid and authenticated
- Permission Errors: Make sure the startup script is executable:
chmod +x run_dashboard.sh - Portfolio Values Incorrect: Use the refresh button to update portfolio data manually
Enable debug logging by setting the environment variable:
export PYTHONPATH=. && python -c "import logging; logging.basicConfig(level=logging.DEBUG)" && streamlit run dashboard/dashboard.pyThis project is for educational and research purposes. Please ensure compliance with Kalshi's terms of service and applicable regulations.
This software is provided as-is for educational and analysis purposes. This is a market analysis tool, not a trading bot. Any trading decisions should be made carefully with proper research and risk management. Always comply with applicable regulations and platform terms of service.