Kalshi API Starter: Markets, Order Books & Signed Requests in Python (2026)

Kalshi Read-only

PASS WITH FIXES Tested on Composer 2.5, , result: PASS WITH FIXES. We built this client from the prompt, ran the signing tests with a throwaway key, and listed live public markets. Signed balance and positions calls were not run: no real keys, orders or money. The prompt below includes the fixes from that run.

Short answer: The Kalshi Trade API v2 lives at https://external-api.kalshi.com/trade-api/v2, with a separate demo environment at https://external-api.demo.kalshi.co/trade-api/v2. Market data such as GET /markets and order books needs no key. Account calls need three headers and a signature over timestamp + METHOD + path (no query string), using RSA-PSS or Ed25519. This recipe builds that client against demo.

What are the key facts?

  • Production REST base: https://external-api.kalshi.com/trade-api/v2 (https://api.elections.kalshi.com/trade-api/v2 also works and covers all markets, not just elections).
  • Demo REST base: https://external-api.demo.kalshi.co/trade-api/v2. Demo keys only work on demo and production keys only on production.
  • Public market data needs no auth, e.g. GET /markets?status=open, GET /markets/{ticker}, GET /markets/{ticker}/orderbook, GET /events.
  • Auth headers: KALSHI-ACCESS-KEY, KALSHI-ACCESS-TIMESTAMP (ms), KALSHI-ACCESS-SIGNATURE. Sign timestamp + METHOD + path with the path from /trade-api/v2/... and no query string. RSA keys use RSA-PSS with SHA-256; Ed25519 keys sign directly.
  • Prices are fixed-point dollar strings (e.g. yes_bid_dollars, yes_ask_dollars); order books return bids only for YES and NO.
  • Rate limits are token buckets: most requests cost 10 tokens; the Basic tier gets 200 read / 100 write tokens per second.
DifficultyBeginner
Time45–60 min
Cost$0
Works withClaude Code, Cursor, ChatGPT / Codex, Grok

What will you build?

A Python client that lists Kalshi markets, prints order books, and makes correctly signed requests (balance, positions) against the demo environment, ready to be the data layer for a bot.

Who is it for?

Developers and vibe coders who searched "kalshi api" and keep hitting 401s on signing, or who want a clean base before building a bot.

What prompt do you paste into your AI coding tool?

Works in Claude Code, Cursor, Codex/ChatGPT, Grok or any agent that can write files. Paste it into an empty folder. Read what it builds before you run anything.

Build a small Python client for the Kalshi Trade API v2. Use only endpoints
and fields documented at https://docs.kalshi.com. If unsure, ask me.

- Python 3.10+, requests, cryptography, python-dotenv.
- Environments from env var KALSHI_ENV = "demo" (default) or "prod":
    demo: https://external-api.demo.kalshi.co/trade-api/v2
    prod: https://external-api.kalshi.com/trade-api/v2
- kalshi_public.py (no auth):
    list_markets(status="open", limit=20, series_ticker=None, mve_filter="exclude")
      -> GET /markets
    get_market(ticker)    -> GET /markets/{ticker}
    get_orderbook(ticker) -> GET /markets/{ticker}/orderbook
    list_events(limit=20) -> GET /events
- kalshi_auth.py:
    Load the private key from the PEM file path in KALSHI_PRIVATE_KEY_PATH
    (the file must live OUTSIDE this repo) and the key id from KALSHI_API_KEY_ID.
    sign(method, path): message = timestamp_ms + METHOD + path where path is
    the full URL path starting /trade-api/v2/... with the query string removed.
    RSA keys: RSA-PSS, MGF1(SHA256), salt_length=DIGEST_LENGTH, SHA256.
    Ed25519 keys: sign the message directly. Detect key type after loading.
    Headers: KALSHI-ACCESS-KEY, KALSHI-ACCESS-TIMESTAMP, KALSHI-ACCESS-SIGNATURE.
    get_balance()   -> GET /portfolio/balance (balance is in cents)
    get_positions() -> GET /portfolio/positions
- cli.py: markets | market <ticker> | book <ticker> | balance | positions
  Show prices from the *_dollars fields and implied % next to them. Explain in
  output that the order book lists YES bids and NO bids only.
- NO order placement in this project.
- Retry 429 with bounded exponential backoff. Don't poll balance more than
  once a second.
- .env.example with blanks, .env in .gitignore, never print secrets.
- pytest tests for the signing message format (path without query string).
  Tests generate a throwaway Ed25519 key in a temp dir; never use a real key.
- Demo and prod list different markets: a ticker from prod returns 404 on
  demo. Say that in the README, and when `market`/`book` gets a 404, print a
  hint to use a ticker from the same KALSHI_ENV.

Show the plan, build it, then tell me the commands to run against demo.

How do you build it, step by step?

  1. Create a Kalshi demo account at demo.kalshi.co (Kalshi's step-by-step guide). It uses mock funds and separate credentials.
  2. Create a demo API key: Account & security → API Keys → Create Key. Save the downloaded private key file outside your project folder (for example ~/.config/kalshi/demo.pem) and note the Key ID. Kalshi can't show the private key again.
  3. New folder + Safety Pack. Add the rules file, .gitignore and deny rules from the Safety Pack.
  4. Paste the prompt into your AI tool. Check that kalshi_auth.py strips the query string before signing. It's the #1 cause of signature errors.
  5. Set env vars in .env: KALSHI_ENV=demo, KALSHI_API_KEY_ID=..., KALSHI_PRIVATE_KEY_PATH=/home/you/.config/kalshi/demo.pem.
  6. Try public data: python cli.py markets. Pass mve_filter=exclude to hide multivariate combo markets, which otherwise crowd the list. Demo and production list different markets: a ticker you copied from kalshi.com usually returns 404 on demo, so take tickers from the same environment you're querying.
  7. Try signed calls: python cli.py balance. A 401 usually means the wrong key type or algorithm, or a timestamp in seconds instead of milliseconds.
  8. Read an order book: python cli.py book <ticker>. You'll see yes_dollars and no_dollars bid ladders. A YES ask is implied by the best NO bid (1.00 minus it), which is why there's no ask side.

How do you test it in paper or demo mode first?

Everything here runs against Kalshi demo by default, with mock money and separate keys, so a mistake costs nothing. Kalshi warns that demo prices and behavior may not match real markets, so don't treat demo results as evidence a strategy works.

Keep the environment switch boring and explicit: KALSHI_ENV=demo is the default, and prod should print a loud banner. When you build the bot in the next recipe, live trading gets a second, separate gate.

What safety checks does it need before real money?

Tick every box before the bot touches real money. The full rules file, .gitignore and pre-commit hook are in the Safety Pack.

Which official docs did we check?

Endpoints and rules were checked against these pages on Oct 19, 2026. APIs change, so if something here disagrees with the official docs, trust the docs and tell us.

Frequently asked questions

What is the Kalshi API base URL?

Production is https://external-api.kalshi.com/trade-api/v2 (the older https://api.elections.kalshi.com/trade-api/v2 still works and covers all markets). Demo is https://external-api.demo.kalshi.co/trade-api/v2.

Do I need an API key for Kalshi market data?

No. Public market data like GET /markets and GET /markets/{ticker}/orderbook works without authentication. You need a key for anything about your account: balance, positions and orders.

Why does my Kalshi API signature fail?

The most common causes are signing the path with the query string attached, using a timestamp in seconds instead of milliseconds, signing only /portfolio/balance instead of /trade-api/v2/portfolio/balance, or using the wrong algorithm for your key type (RSA-PSS for RSA keys, a direct signature for Ed25519 keys).

What are Kalshi API rate limits?

Kalshi uses token buckets. Most requests cost 10 tokens. The Basic tier refills 200 read tokens and 100 write tokens per second, and higher tiers get more. A 429 means back off exponentially; there's no extra penalty.

Does Kalshi have a demo environment?

Yes, at demo.kalshi.co, with mock funds and its own API keys and endpoints.

Related recipes

Build a Kalshi AI Trading Bot (Demo First, With Hard Limits)

Use an AI coding tool to build your own Kalshi trading bot that runs on the Kalshi demo environment first, with order groups, reduce-only exits, a kill switch and optional LLM-assisted research that never sees your keys.

Kalshi Paper / demo first Intermediate