Build a prediction market trading agent with Claude Code and MCP
· Lucyd
You can trade prediction markets from Claude by asking in plain language. The next step is an agent: Claude follows a written strategy, checks the market every round, places orders within limits you set, and writes down what it did. No trading code, no exchange SDK.
This guide builds one with Claude Code and the Lucyd MCP server, on Bitcoin Up or Down markets that run from 5 minutes to a day. Lucyd is on the Sepolia testnet with test USDC, so the agent can trade for real without risking real money.
How it fits together
- Claude Code is the agent: it reads the strategy, decides and calls tools.
- The Lucyd MCP server gives it the tools: markets, order books, positions, orders, payouts. It runs on your computer and signs orders with a wallet key that never leaves it.
- A strategy file in plain English says what to trade, when and how much.
- A schedule runs the agent every round.
Step 1. Connect Claude Code to Lucyd
Start read-only: the hosted server needs no install and no key, and it is enough to explore markets and order books.
claude mcp add --transport http lucyd https://mcp.lucyd.trade/mcp
Ask Claude "What are the open 15-minute Bitcoin markets and their prices?" to check it works.
To trade, run the local server with a key of a separate wallet that holds only what the agent may lose. It needs Node.js 18 or newer:
claude mcp add lucyd -e LUCYD_PRIVATE_KEY=0xYOUR_AGENT_KEY -e LUCYD_MAX_ORDER_USD=20 -- npx -y @lucyd/mcp
LUCYD_MAX_ORDER_USD caps every buy order, whatever the model decides. Then ask Claude once to "approve trading and turn on auto redeem": two on-chain approvals let the wallet trade and get winnings paid out automatically. They need a little Sepolia ETH for gas; trading itself needs none. The MCP page has setup for Claude Desktop, Cursor and other clients.
Step 2. The tools the agent gets
| Tool | What it does |
|---|---|
list_markets, get_market | Open rounds, strike, end time, rules |
get_order_book | Bids, asks, best bid and ask of Up and Down |
list_trades, top_traders | Recent trades and the leaderboard |
get_positions, get_trader_stats, get_pnl_history | What the wallet holds and how it is doing |
place_order, cancel_orders, close_position, get_open_orders | Trading |
get_wallet, redeem, set_auto_redeem | Balances and payouts |
Step 3. Write the strategy
Put the rules in a file next to where you run Claude Code, for example strategy.md. Be specific: numbers, not adjectives. An example for 15-minute rounds:
# Strategy: 15-minute Bitcoin Up or Down
Every run:
1. Find the open 15m round. Skip it if less than 3 minutes are left.
2. Read the strike and the Up and Down order books.
3. Get the current BTC price from https://api.coinbase.com/v2/prices/BTC-USD/spot and compare it with the strike.
4. If BTC is more than 0.15% above the strike and Up's best ask is below 0.70, buy Up for 10 USDC.
If BTC is more than 0.15% below the strike and Down's best ask is below 0.70, buy Down for 10 USDC.
Otherwise do nothing.
5. Never hold more than 20 USDC in one round. Never place more than 6 orders a day.
6. Append one line to trades.log: time, round, action, price, reason.
Why 0.15%: in our data the median 15-minute move is about 0.07% (statistics of 8,000 rounds), so a price that far from the strike with minutes left is a real lead, and the rule only buys it while it is still cheap.
Step 4. Run it every round
Inside Claude Code, the /loop command repeats a prompt on an interval:
/loop 15m Follow strategy.md for the current 15-minute Bitcoin round.
For an agent that runs without an open terminal, call Claude Code headless from a scheduler such as cron, once per round:
*/15 * * * * cd ~/agent && claude -p "Follow strategy.md for the current 15-minute Bitcoin round." >> run.log 2>&1
Give the headless run permission only for the Lucyd tools it needs, and nothing else on the machine.
Step 5. Review and improve
Ask the agent to report on itself: "Show my positions and profit for today, and compare each trade in trades.log with the result of its round." Trader stats and P&L history come from the same tools. Change one rule at a time and let it run for a few hundred rounds before judging: short rounds are close to a coin flip, and a few dozen results prove nothing.
Keep it safe
- A separate wallet with a small balance is the hard limit. Nothing the model does can lose more.
LUCYD_MAX_ORDER_USDcaps each buy order in the server itself.LUCYD_READ_ONLY=trueturns off every trading tool: use it for a dry run in which the agent only logs what it would do.- Do not paste the key into the chat. It lives in the server's environment only.
- Keep rules testable. "Buy when it looks bullish" gives a different agent every day; "buy when BTC is 0.15% above the strike" gives the same one.
Agents or code?
An agent is the fastest way to try an idea: rules in English, running in minutes. For a strategy that needs to react in milliseconds, write a bot against the API instead: build a 5-minute trading bot. Both trade the same order book, with no trading fees.
FAQ
Can Claude trade on prediction markets? Yes. Through an MCP server, Claude Code, Claude Desktop and other MCP clients can read markets and place orders signed by a wallet key on your machine.
Is there an MCP server for prediction markets? Lucyd has one for its Bitcoin Up or Down markets: npx -y @lucyd/mcp to trade, or the hosted read-only server at https://mcp.lucyd.trade/mcp.
Does the agent need real money? No. Lucyd runs on the Sepolia testnet with test USDC.
Can the agent lose more than I give it? No. It trades only from its own wallet, and every buy order is capped by LUCYD_MAX_ORDER_USD.