Kalshi's REST API lets you programmatically access markets, fetch prices, and place trades. If you're a Python developer, this guide walks you through everything from authentication to building a simple market monitoring script.
Prerequisites
Before starting, you'll need:
- A Kalshi account: Sign up at kalshi.com and complete identity verification.
- API credentials: Generate API keys in your Kalshi account settings.
- Python 3.8+: Installed on your machine.
- Libraries:
requestsfor HTTP calls (install withpip install requests).
Step 1: Authentication
Kalshi uses API key authentication. Every request must include your credentials. Here's how to set up your session:
import requests
Create a session object and set your API key headers. Kalshi's API base URL is typically https://trading-api.kalshi.com/trade-api/v2. Store your API key and secret securely—never hardcode them in your script. Use environment variables instead.
Key points:
- Use environment variables for credentials:
os.environ["KALSHI_API_KEY"] - Set up a
requests.Session()for connection reuse - Add your API key to request headers
- Handle authentication errors gracefully
Step 2: Fetch markets
The /markets endpoint returns available markets. You can filter by status, series, and more:
A basic market fetch queries the markets endpoint with optional parameters like status=open to get active markets, limit=100 for pagination, and series_ticker to filter by category.
Useful market fields:
ticker— Unique market identifier (you'll need this for orders)title— Human-readable market nameyes_ask/yes_bid— Current best pricesvolume— Number of contracts tradedclose_time— When the market closesresult— Resolution status (null if unresolved)
Step 3: Get market orderbook and history
For deeper analysis, fetch the order book and price history:
Order book: The /markets/{ticker}/orderbook endpoint shows current bids and asks with sizes. This tells you liquidity depth.
Trade history: The /markets/{ticker}/trades endpoint shows recent fills with timestamps and prices.
Tips:
- Monitor order book depth before placing large orders
- Use trade history to calculate VWAP (volume-weighted average price)
- Track bid-ask spread changes over time to gauge market efficiency
Step 4: Place orders
To place an order, send a POST request to the orders endpoint with your trade parameters:
Required parameters:
ticker— The market ticker from Step 2action— "buy" or "sell"side— "yes" or "no"type— "limit" or "market"count— Number of contractsyes_priceorno_price— Price in cents (for limit orders)
Important safety tips:
- Always start with small orders to test your code
- Use limit orders to control your entry price
- Implement maximum position size limits in your code
- Add confirmation prompts before live trading
- Test on paper trading first if Kalshi offers a sandbox environment
Step 5: Build a price monitor
A practical first project is a price monitor that alerts you to opportunities. Here's the logic:
- Define a list of market tickers you want to track
- Poll prices at a regular interval (every 30-60 seconds, respecting rate limits)
- Compare current prices to your target thresholds
- Send an alert (print, email, or Slack webhook) when a threshold is crossed
- Log all prices to a CSV for later analysis
Rate limiting: Kalshi enforces rate limits. Implement exponential backoff: if you get a 429 response, wait and retry with increasing delays. A good starting point is polling every 60 seconds for up to 20 markets.
Common Python patterns for Kalshi
Experienced Kalshi API users typically implement these patterns:
- Error handling: Wrap all API calls in try/except blocks. Handle connection errors, rate limits (429), and authentication failures separately.
- Logging: Use Python's
loggingmodule to record all trades and API calls. Essential for debugging and tax reporting. - Configuration: Store API keys, thresholds, and market lists in a config file or environment variables—not in code.
- Retry logic: Use exponential backoff for failed requests. The
tenacitylibrary makes this easy. - Data storage: Save market data to SQLite or CSV for backtesting. You can't backtest strategies without historical data.
Community resources
The Kalshi developer community has built useful tools:
- GitHub: Search "Kalshi Python" for community-maintained API wrappers and example bots.
- Kalshi API docs: The official documentation has complete endpoint references and authentication guides.
- Discord/Reddit: The r/Kalshi and prediction market communities share strategies and code.
Complement your bot with Alphascope
While your Python bot handles execution, Alphascope provides the intelligence layer:
- News → AI-powered news analysis identifies which stories move which markets. Feed this into your bot's decision logic.
- Predictions → See AI probability estimates alongside market prices to find mispriced contracts.
- Arbitrage → Detect cross-platform price gaps your bot can exploit.
FAQ
Is there an official Kalshi Python SDK?
Kalshi provides official API documentation, and there are community-built Python wrappers on GitHub. Check the Kalshi API docs for the latest official resources.
What is the Kalshi API rate limit?
Kalshi enforces rate limits on API requests. Check the official documentation for current limits. Implement exponential backoff and request queuing in your code.
Can I paper trade with the Kalshi API?
Check if Kalshi offers a demo or sandbox environment. If not, start with the smallest possible position sizes while testing your bot.
Is automated trading allowed on Kalshi?
Yes. Kalshi explicitly supports API trading. Many institutional and quantitative traders use the API. Just follow the terms of service and rate limits.
What Python libraries do I need?
At minimum: requests for API calls and json for parsing. For advanced bots, add pandas for data analysis, schedule for timing, and tenacity for retry logic.