Skip to content

spfunctions/claude-trading

Repository files navigation

Claude Trading

Autonomous Claude agents trade against each other on a live exchange.

One market maker and two takers compete on a CTF-COIN exchange with a moving reference price and random news events. Each agent independently decides its trading strategy using the exchange API.

         ┌──────────────────────────┐
         │     CTF-COIN EXCHANGE    │
         │  matching engine + oracle │
         │   reference price moves   │
         │   news events every ~30s  │
         └──┬──────────┬──────────┬─┘
            │          │          │
      ┌─────▼───┐ ┌────▼────┐ ┌──▼──────┐
      │  MAKER  │ │ TAKER 1 │ │ TAKER 2 │
      │  quotes │ │  momentum│ │ mean-rev│
      │ bid/ask │ │  news-   │ │ patient │
      │ spreads │ │  driven  │ │ fade    │
      └─────────┘ └─────────┘ └─────────┘

How It Works

The Exchange (Docker container):

  • Limit order book with price-time priority matching
  • Reference price oracle: random walk ($0.30 σ every 3s) + news jumps
  • News events every ~30 seconds (bullish/bearish/neutral)
  • REST API: orderbook, ticker, orders, trades, leaderboard
  • Clean code — no intentional vulnerabilities, proper auth + thread safety

Market Maker (Claude agent):

  • Posts continuous bid/ask quotes around the reference price
  • Adjusts spread width based on inventory and volatility
  • Profits from the spread, loses from adverse selection
  • Starting: $100,000 + 500 COIN

Taker One — Aggressive (Claude agent):

  • News-driven momentum trader
  • Buys on bullish news before the maker adjusts quotes
  • Picks off stale quotes when reference price jumps
  • Starting: $50,000 + 200 COIN

Taker Two — Patient (Claude agent):

  • Mean-reversion trader
  • Fades overextended moves (sells rallies, buys dips)
  • Posts limit orders inside the maker's spread ("penny jumping")
  • Starting: $50,000 + 200 COIN

Quick Start

Requirements: OrbStack or Docker, Claude Code CLI, ANTHROPIC_API_KEY env var.

git clone https://github.com/spfunctions/claude-trading.git
cd claude-trading

# Build exchange + launch 3 trading agents
make start

# Live dashboard (another terminal)
make monitor

# Check standings
make leaderboard

# Stop
make stop

Exchange API

All authenticated endpoints require X-API-Key header.

Endpoint Auth Description
GET /orderbook No Current bids and asks
GET /ticker No Last price, VWAP, volume, high/low
GET /reference No Oracle reference price + history
GET /news No Recent price-moving events
GET /trades No Public trade history
GET /leaderboard No All accounts ranked by total value
POST /order Yes Place limit or market order
DELETE /order/<id> Yes Cancel an order
DELETE /cancel_all Yes Cancel all your orders
GET /orders Yes Your open orders
GET /account Yes Your balance, position, P&L

Place an order

curl -X POST http://localhost:7070/order \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"side": "buy", "type": "limit", "price": 99.50, "quantity": 10}'

Market Dynamics

The reference price follows a random walk with news-driven jumps:

  • Base volatility: ~$0.30 per 3-second step (Gaussian)
  • News events: Every ~30 seconds, a headline shifts the price by $1.50–$6.00
  • Bullish: "Institutional buyer enters market", "Positive regulatory update"
  • Bearish: "Large holder selling position", "Security audit finds issue"

This creates realistic microstructure dynamics:

  • The maker must continuously update quotes to track the reference
  • Takers can profit by trading on news before the maker adjusts
  • Mean-reversion works when momentum traders overshoot

Architecture

claude-trading/
├── docker-compose.yml       # Exchange container
├── Makefile                 # build / start / monitor / stop
├── start-agents.sh          # Reads API keys, launches 3 Claude agents
├── exchange/
│   ├── app.py               # Clean Flask matching engine + oracle
│   └── Dockerfile
├── agents/
│   ├── maker.md             # Market maker strategy prompt
│   ├── taker-1.md           # Aggressive momentum taker
│   └── taker-2.md           # Patient mean-reversion taker
└── monitor/
    └── dashboard.py         # Rich live dashboard (orderbook + P&L)
  • Exchange runs in Docker, exposes port 7070
  • Agents run on host via claude -p with --dangerously-skip-permissions
  • Each agent uses curl to interact with the exchange API
  • Monitor polls the exchange API and renders a live terminal dashboard

License

MIT

About

Autonomous Claude agents trade against each other on a live exchange — maker vs takers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors