Claude Trading Bot: What Claude Can (and Can't) Do, Plus a Safe Starter

KalshiPolymarket US Paper / demo first

PASS WITH FIXES Tested on Claude Code (Claude Sonnet 5.5), , result: PASS WITH FIXES. We built this bot from the prompt and dry-ran it on live public Kalshi demo data (17 tests passing). Signed orders and cancels were mocked with a fake HTTP session, and signatures were checked against the public key: no real keys, orders or money. The prompt below includes the fixes from that run.

Short answer: Claude can't find you a winning strategy, but Claude Code is good at building a trading bot's plumbing: API clients from docs, the bot loop, tests and logging. The safe setup is a CLAUDE.md rules file, permissions.deny rules that block reading .env and key files, limits enforced in code, a kill switch, and Kalshi's demo environment before any real money.

What are the key facts?

  • Claude is good at: writing API clients from docs, building the bot loop, tests, logging, refactoring and explaining code. It's weak at: knowing today's API details unless you give it the docs, and anything resembling a guaranteed edge.
  • Put the BotCookery rules in CLAUDE.md. Claude Code reads it for every task in that folder.
  • Block secret files with permissions.deny in .claude/settings.json, e.g. "Read(**/.env)", "Read(**/*.pem)". Claude Code applies deny rules right away.
  • A real 2026 incident: a Claude Code session served a folder containing a .env with a private key over a local web server, and the user reported a $1,324 loss (#34133).
  • Start on Kalshi's demo exchange (https://external-api.demo.kalshi.co/trade-api/v2), with mock funds and separate keys. With no keys at all, the starter dry-runs on public demo market data and sends nothing.
  • Kalshi's V2 order body needs side (bid = buy YES, ask = sell YES), and request signatures cover the full path from the API root, such as /trade-api/v2/portfolio/events/orders, without the query string. Keys can be RSA (RSA-PSS) or Ed25519.
DifficultyBeginner
Time1–2 hours
Cost$0 API · Claude subscription
Works withClaude Code, Claude (chat)

What will you build?

Set up Claude Code so it builds trading bots safely by default, then use it to scaffold a demo-only Kalshi bot you understand line by line.

Who is it for?

People who watched a "Claude made me a trading bot" video and want to try it without leaking keys or blowing up an account.

Not for: Anyone hoping Claude will pick winning trades. It won't, and anyone claiming it does is selling something.

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.

You're helping me build my first trading bot. Safety beats speed.

Step 0 (do this first, then stop and show me):
- Create CLAUDE.md containing the BotCookery Safety Pack rules I paste below.
- Create .gitignore covering .env, .env.*, *.pem, *.key, secrets/, KILL,
  logs/, .venv/ (but keep .env.example tracked).
- Create .claude/settings.json with permissions.deny for
  Read(**/.env), Read(**/.env.*), Read(**/*.pem), Read(**/*.key),
  Read(./secrets/**) and Bash(git push *). (If you are not allowed to write
  under .claude/, tell me and I will approve it; do not work around it.)
- Create limits.json with: max_contracts_per_order 1,
  max_open_exposure_usd 5, max_daily_loss_usd 2, max_orders_per_minute 3.
- Create .env.example with blank KALSHI_API_KEY_ID and KALSHI_PRIVATE_KEY_PATH.

Step 1: Build a Kalshi DEMO bot in Python 3.11+ (requests, cryptography,
pytest only) using only endpoints from https://docs.kalshi.com (fetch and
read the pages before coding):
- Base URL https://external-api.demo.kalshi.co/trade-api/v2 (hardcode demo;
  production must be a separate, deliberate change later).
- Signed requests: headers KALSHI-ACCESS-KEY, KALSHI-ACCESS-TIMESTAMP (ms),
  KALSHI-ACCESS-SIGNATURE = base64 signature of
  timestamp + METHOD + FULL path from the API root, e.g.
  "/trade-api/v2/portfolio/events/orders", with no query string. Support
  both key types: RSA (RSA-PSS, SHA-256, salt length = digest length) and
  Ed25519 (sign the message directly).
  Key id from KALSHI_API_KEY_ID; key file path from KALSHI_PRIVATE_KEY_PATH.
  Never read the key file contents into logs or output.
- If no credentials are set, run in DRY-RUN: read public market data, log what
  would be sent, send nothing.
- Watch one ticker from config.toml. Read the best YES ask from
  GET /markets/{ticker} (yes_ask_dollars, yes_ask_size_fp; fixed-point dollar
  strings). Rule: if the best YES ask is at or below my configured max price
  and size >= 1, propose a 1-contract limit bid at that price. (To find a
  ticker with a live ask on demo:
  GET /markets?status=open&mve_filter=exclude&limit=1000 and look for
  yes_ask_dollars between 0 and 1.)
- risk.py checks KILL file (or BOT_KILL=1) + limits before every order:
  max contracts, open exposure (sum of price*count of orders sent), daily
  loss (placeholder input defaulting to 0 until fills are wired), orders per
  minute.
- Orders via POST /portfolio/events/orders with body:
  ticker, side "bid" (bid = buy YES), count as "1.00", price as "0.3500",
  client_order_id (uuid4), time_in_force good_till_canceled,
  self_trade_prevention_type taker_at_cross.
- cancel_all.py -> DELETE /portfolio/events/orders (exit with a clear
  message if no credentials).
- Log every decision to logs/decisions.jsonl.
- Tests for risk.py (every rule), the signing message (query string stripped,
  full path), and a signature verified with the public key; use a fake HTTP
  session so tests need no network or keys.

Explain each file in plain English when you're done, and list anything
you weren't sure about.

[PASTE THE SAFETY PACK RULES FILE HERE]

How do you build it, step by step?

  1. Install Claude Code and open an empty folder. Grab the rules file from the Safety Pack and paste it at the bottom of the prompt where it says to.
  2. Run step 0 only. Claude Code will ask permission before writing .claude/settings.json; approve it. Check that the file has the deny rules and CLAUDE.md has the rules. Run /status in Claude Code to confirm the settings file loaded.
  3. Get Kalshi demo keys (optional for a first run). Without keys the bot dry-runs on public demo data and sends nothing. When you're ready, create keys at demo.kalshi.co (Account & security → API Keys). Ed25519 and RSA both work. Save the key file outside the project, e.g. ~/.config/kalshi/demo.pem.
  4. Let Claude build step 1. Ask it to fetch the Kalshi docs pages before writing code, so it uses the current V2 order endpoint instead of something from its training data.
  5. Pick a ticker. Most open demo markets are multivariate combos with no ask. Run GET https://external-api.demo.kalshi.co/trade-api/v2/markets?status=open&mve_filter=exclude&limit=1000 and choose one with yes_ask_dollars between 0 and 1, then put it in config.toml.
  6. Read every file. Ask Claude to walk you through broker.py and risk.py line by line. If you can't explain what a line does, don't run it.
  7. Run on demo and drill the kill switch. touch KILL works with or without keys (the next loop logs "kill switch on" and sends nothing). python cancel_all.py needs demo keys; without them it should just say there's nothing to cancel.
  8. Iterate in small steps. One change per prompt, run the tests after each, commit after each. Big "rewrite everything" prompts are where bots break.

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

This starter hardcodes the Kalshi demo base URL on purpose. Switching to production should be a separate, deliberate change you make yourself, with a new production key and the live gate from the Kalshi AI Trading Bot recipe.

Prefer Polymarket US? Use the paper-ledger setup in Build a Polymarket Bot with Claude Code.

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

Can Claude build a trading bot?

Yes. Claude Code can write a full bot (API client, strategy loop, risk checks, tests) from a clear prompt and the official docs. What it can't do is guarantee the strategy makes money. Use it as a fast, careful junior developer, not an oracle.

Is it safe to give Claude Code my API keys?

Don't give it the keys themselves. Load keys from environment variables, keep key files outside the project, and add permissions.deny rules so Claude Code can't read .env or .pem files. Real incidents in 2026 involved agents exposing .env files.

Claude AI trading bot vs Claude Code trading bot: what's the difference?

Claude (chat) can explain concepts and draft code you copy by hand. Claude Code works directly in your project folder, writing files and running commands, which is faster and also riskier. That's why the rules file and deny settings matter.

Which market should my first Claude trading bot use?

In the US, Kalshi's demo environment is the easiest safe start: real API, mock money, separate keys. Polymarket US works too, using a local paper ledger and its order preview endpoint.

Related recipes