Build and Test a Kalshi Bot with AI: Copy, Paste, Go

You don't need to know how to code. You need the right prompts and real data. This guide gives you both: paste-ready prompts to pull every kind of Kalshi market, wire them into a simple bot, and (the part most people skip) test it on free data before you risk a dollar.

We'll move in a straight line: set up in one paste, learn the data you can pull, grab exactly the markets you care about (crypto, sports, politics, weather, economics), assemble a small bot, and then backtest it. Every step below is a block you can copy and hand straight to your AI assistant.

New to the words? An API is a doorway your code (or your AI) uses to ask a server for data. An API key is your personal password for that doorway. MCP lets your AI assistant walk through the doorway by itself, so it can pull live Kalshi data while it builds with you. A backtest just means replaying old data to see if your idea would have worked.

Step 1: Set it all up in one paste

Open Claude Code, Cursor, or any AI coding agent. Paste this and answer the two questions it asks. It creates your free account, saves your key, and connects the data so everything below "just works."

Help me set up KalshiAPI (kalshiapi.com), the complete Kalshi prediction-market dataset. Do it for me end to end: 1. Ask me two questions and wait for my answers: (a) my email address, and (b) a password I want. 2. Create my free account: POST JSON {"email": "MY_EMAIL", "password": "MY_PASSWORD"} to https://kalshiapi.com/v1/signup and save the api_key from the response into a .env file as KALSHIAPI_KEY. 3. Every request from now on should send the header X-API-Key: MY_KEY . 4. Confirm it works by calling GET https://kalshiapi.com/v1/stats and show me the market, candle, and trade counts. 5. Give me a one-line summary of what I can now pull, and wait for my next instruction.

Prefer to grab a key by hand first? Use the free key form (no card, instant). Want your AI to pull data on its own? Point it at the MCP server https://kalshiapi.com/mcp (tools: dataset_stats, category_yes_rates, list_markets, get_market, get_candles, get_trades).

Step 2: Know the four data types you can pull

Everything on Kalshi boils down to four kinds of data. Here's what each one is, in one line, plus a copy-paste prompt to fetch it.

Markets: the questions themselves

A market is a yes/no question ("Will Bitcoin close above $100k on Friday?") plus its status, category, price, and outcome. This is your starting point for everything.

Using my KalshiAPI key, call GET https://kalshiapi.com/v1/markets?limit=20 and show me a clean table with columns: ticker, title, category, status. Then tell me which categories appear most.

Candles: the price over time

Candles are the hourly price history for one market: open, high, low, close, plus volume and open interest. This is the backbone of any charting or trend idea.

Pick one active market from the last list. Call GET https://kalshiapi.com/v1/markets/THAT_TICKER/candles and plot (or print) the hourly close price. Tell me the highest and lowest price and roughly when each happened.

Trades: every real fill

Trades are the individual prints: price, size, taker side, and timestamp for each actual trade. Great for measuring real activity and momentum rather than just quoted prices.

For that same ticker, call GET https://kalshiapi.com/v1/markets/THAT_TICKER/trades and summarize: how many trades, total size, and whether buyers or sellers were more aggressive (taker side). Note: trade-level history covers the most recent months and is expanding daily.

Teams: who actually wins

A bonus, sports-only dataset: the win/loss record of every team across settled Kalshi game markets, so you can compare a team's real win rate to what the market was pricing.

Call GET https://kalshiapi.com/v1/teams?league=MLB&sort=win_pct&order=desc and show me the top 10 teams by win percentage. Explain what "gap" means if that column shows up.
Tip The /stats endpoint (GET /v1/stats) is public and free. It tells you exactly how much data exists right now (market, candle, and trade counts). Ask your AI to call it whenever you want to know the size of the haystack.

Step 3: Pull markets by question type

Kalshi isn't only sports. The same /v1/markets endpoint filters by category, so you can grab exactly the flavor of question you want. Here are paste-ready prompts for the big ones, each the same shape with just a different category.

Crypto

Bitcoin/ETH price levels, "will X close above Y." A fun starter fact: in the history, Crypto markets resolve YES only about a quarter of the time, so those long-shot "moon" targets rarely hit.

Call GET https://kalshiapi.com/v1/markets?category=Crypto&status=active&limit=25 and list the open Bitcoin/crypto markets with their current YES price. Flag any priced under 10 cents; those are the long shots.

Sports

Game winners, series, player and team props. Pair this with the /v1/teams data above to compare price vs. real win rate.

Call GET https://kalshiapi.com/v1/markets?category=Sports&status=active&limit=25 and show today's game markets. Then, for any team you recognize, pull GET https://kalshiapi.com/v1/teams/TEAM_NAME and tell me if the market price looks high or low versus their real win rate.

Politics & elections

Elections, nominations, approval, "will a bill pass." Longer-running markets, great for slow, patient strategies.

Call GET https://kalshiapi.com/v1/markets?category=Politics&status=active&limit=25 and list the political markets with their YES price and close date. Sort them by how soon they resolve.

Weather & climate

Daily high temperatures, rain, hurricanes. These resolve fast and often, which makes them a favorite for testing an idea quickly.

Call GET https://kalshiapi.com/v1/markets?q=temperature&status=active&limit=25 and show me the daily high-temperature markets. Which cities are covered, and what price is the market putting on the most likely outcome for each?

Economics & financials

Fed rate decisions, CPI, jobs numbers, index closes. Big, liquid, headline-driven markets.

Call GET https://kalshiapi.com/v1/markets?category=Financials&status=active&limit=25 and list the economics/financial markets (rates, CPI, index closes) with their YES price. Group them by what they're about.
Not sure of the exact category name? Ask your AI: "Call /v1/markets with no filter, then show me the distinct category values so I know what I can filter on." Categories are just labels on the same endpoint.

Step 4: Assemble the bot

Now stitch the pieces into something that runs. This prompt asks your AI to build a small, honest "scanner" bot: it finds markets, scores them, and explains itself. No trading yet; we test first.

Build me a Python script called kalshi_bot.py that uses my KalshiAPI key (from .env) and does this: 1. Pulls active markets in a category I choose at the top of the file (default: Crypto). 2. For each market, pulls its recent candles and computes a simple score: how far the current YES price is from 50 cents, and whether the price has been rising or falling over the last few hours. 3. Prints a ranked table: ticker, title, YES price, trend, score. 4. Adds clear comments so I can understand every line. Keep it under ~60 lines. Do not place any trades; this only reads data and prints. Then run it and show me the output.

Run it, read the table, and refine in plain English: "only show markets closing this week," or "add a column for trade volume," or "rank by biggest recent price move." That back-and-forth is the whole loop.

Step 5: Test it before you trust it

This is the step that separates a toy from a tool. Before a bot ever touches real money, prove it would have worked on data it hasn't seen. Do all of this on the free tier.

1. Backtest on history

Replay the past and check whether your scoring rule actually lines up with outcomes.

Take my kalshi_bot.py scoring rule and backtest it: for a set of already-SETTLED markets in my category (status=settled), pull their candle history, apply the same score using only data from before they resolved, and then check the actual outcome. Report: how many the rule got right, the win rate, and whether a high score really predicted a YES. Be honest if the edge is small or zero.

2. Sanity-check the numbers

AI-written code can look right and be subtly wrong. Make it prove its own math.

Pick one market from my results and walk me through the calculation by hand, step by step, using the raw numbers from the API. Confirm the price, the trend, and the final score all match what the script printed. If anything is off, find and fix the bug.

3. Paper-trade forward

The truest test: log what your bot would do today, then check back later. No money involved.

Add a paper-trading mode: each run, save the top-scored markets and the price at that moment to a paper_trades.csv (never place a real order). Write a second tiny script that re-reads that file, looks up the current price or final outcome for each, and reports my pretend profit or loss. Show me how to run both.
The honest truth about edges Most simple rules have little or no edge. That's normal, and finding out cheaply is the win. Outcome rates vary wildly by category (Crypto long shots rarely hit; favorites in some sports are underpriced). A good bot isn't one that promises profit; it's one that tells you the truth about what the data supports. Ask your AI to always report the downside, not just the upside.

Step 6: Scale up when it earns it

Everything above runs on the free sample tier. Once a strategy survives a backtest and paper-trading, you'll want the full picture to make it real:

  • The complete dataset covers 2.9M markets and hourly candles back to 2023, plus hundreds of millions of individual trades from the most recent months, across Crypto, Sports, Politics, Weather, and Financials.
  • More history means more settled markets to backtest against, which means more trustworthy results.
  • Same endpoints, same prompts, just higher limits and the full depth.

When you're ready, the pricing page has a monthly API plan (auto-refreshed every month) and a one-time full historical download for backtesting offline.

That's the whole playbook

Set up in one paste, learn the four data types, pull the exact market type you care about, assemble a small scanner, and (most importantly) test it three ways before trusting it. From here, have your AI add alerts, a dashboard, or a second strategy. Keep it curious, keep it honest, and go build something fun.