Kalshi has the deepest public API of the prediction markets, which is why it's where most people build their first bot, and where we built ours. Here's the whole path from a blank account to a capped bot placing its first order.
New to the overall setup? Start with the prediction market bot overview, then come back.
Step 1: connect your Kalshi account
Open and verify a Kalshi account at kalshi.com (or through our link). API keys come from the account, so it has to be fully verified first.
Create the API key.
- Go to Profile Settings and find API Keys.
- Click Create New API Key and give it a name you'll recognize, like
btc-bot. - Kalshi shows you a Key ID and downloads a private key file (PEM format, saved as a
.txt).
That private key download happens once. Kalshi doesn't store it, so if you lose it, you delete the key and make a new one. New keys default to Ed25519; RSA is still offered.
Store it like a password. Move the file somewhere outside your code folder, for example ~/.kalshi/btc-bot.pem, and point the bot at it with an environment variable. Never commit it to GitHub and never paste it into a chat.
How signing works, so the AI's code makes sense to you. Every request carries three headers:
| Header | What goes in it |
|---|---|
KALSHI-ACCESS-KEY | Your Key ID |
KALSHI-ACCESS-TIMESTAMP | The current time in milliseconds |
KALSHI-ACCESS-SIGNATURE | Base64 signature over timestamp + METHOD + path (path without the query string) |
Ed25519 keys sign that string directly. RSA keys sign it with RSA-PSS and SHA-256.
Two environments:
- Production:
https://api.elections.kalshi.com/trade-api/v2 - Demo:
https://external-api.demo.kalshi.co(separate demo account and separate keys, fake money)
Build against demo first. It's free, and it's where you find out your bot sends the wrong side.
Step 2: build the bot with AI
Paste this into Claude or ChatGPT. Fill in the market and your rule. It already knows Kalshi's auth.
You are a senior engineer helping me build a small, safe Kalshi trading bot.
Venue: Kalshi Trade API v2.
- Production base URL: https://api.elections.kalshi.com/trade-api/v2
- Demo base URL: https://external-api.demo.kalshi.co (use this while KALSHI_ENV=demo)
- Docs: https://docs.kalshi.com
Auth: every request sends KALSHI-ACCESS-KEY (Key ID), KALSHI-ACCESS-TIMESTAMP (ms)
and KALSHI-ACCESS-SIGNATURE = base64 signature of timestamp + METHOD + path
(path without query params). My key type is [Ed25519 / RSA]. For RSA, sign with
RSA-PSS, SHA-256, MGF1 SHA-256, salt length = digest length.
Read KALSHI_KEY_ID and KALSHI_PRIVATE_KEY_PATH from environment variables.
Never print or log the key. Never ask me to paste it here.
Market: [e.g. Bitcoin 15-minute up/down markets, series KXBTC15M].
Rule: [YOUR RULE, e.g. "buy YES when the model price beats the best ask by 8 cents"].
Build:
1. [Python 3.12 / Node 24]. No axios. Official SDK or the standard library.
2. ingest.py/js: list open markets for the series, read the order book, and
reject data older than [N] seconds.
3. decide.py/js: apply my rule, return side, limit price in cents, and contract count.
4. execute.py/js: place limit orders via POST /portfolio/orders with a unique
client_order_id. Check fills. Cancel anything still resting at window close.
5. Rails in config.yaml: max_dollars_per_position, max_open_positions,
daily_loss_stop, and a KILL file that halts everything.
6. DRY_RUN=true by default. Log every decision and skip to decisions.csv with a reason.
7. Backoff on 429s and reconnects. Stale data = no trade.
8. If you are unsure of an endpoint or field name, say so and point me to the
section of docs.kalshi.com to check. Do not invent endpoints.
List the files first, then write them one at a time. Finish with a test plan:
demo-exchange test, dry-run against production prices, and what the log should show.
Before you arm it, ask the AI to walk you through execute line by line, and to write tests for the rails. Fees matter here too: Kalshi charges a per-contract fee on every fill, so plug your typical edge into the Kalshi fee calculator before you trust a thin one.
Step 3: fund it and fence it
Deposit from the Kalshi app or site with any of the methods Kalshi lists on its deposit page. Kalshi doesn't have subaccounts, so the fence lives in your code:
- Max per position. Our Kalshi BTC 15-minute lanes started at $3 max per position.
- Daily loss stop. Ours started at $25 a day: hit it and the bot stops until tomorrow.
- Lifetime stop and a kill switch. One file or one database flag that stops every order.
- Keep the bot balance small. Deposit what the bot is allowed to lose, not your whole stack.
Then: demo first, dry-run against real prices second, live at minimum size third. Raise size only after the order log earns it.
Step 4: start with our stuff
Our Kalshi bot trades Bitcoin's 15-minute windows at small size, in public. Here's its record:
Our bot on Kalshi, live
R-TOP-OF-HOUR-MOM v4- Settled positions
- 196
- Won–lost
- 70–126
- Net after fees
- +$83.85
Live at small size on our own Kalshi account since October 10, max $3 a position. This version of the strategy. Strategies evolve. They stay until they break. We watch the overall regime. The full record →
The reads behind it are free on the site:
- Bitcoin Edge 15-Minute: the directional read on every Kalshi BTC 15-minute window.
- Bitcoin Edge: the hourly read, model price against Kalshi's price.
- Kalshi 15-minute markets and how KXBTC15M settles, so your bot reads the same number the market settles on.
- Edge Alerts API: the signals as JSON for your bot. Pro gets them live; /alerts shows them free, 24 hours delayed. Our non-custodial executor is in the alerts API guide.
Want to copy how ours is wired? The Bot Playbook is the build sheet for our three-machine setup: a Fly server that ingests prices, an engine that does the math, and a bot that places only what the math recommends. Get it with Pro →
Other venues: Polymarket US · Novig · ProphetX
Bots lose money too. Start small, log everything, and trade responsibly.
