An autonomous ETH/USD grid trading system built with two AI agents and a deterministic grid bot.
Classic grid strategy: buy limit orders staged below current price, sell placed one spacing above when a buy fills. USD profit recycled on each round trip.
Strategist Agent → GridConfig → Grid Bot → ProposedOrder → Executor Agent → Kraken
Strategist — runs at startup and every 4 hours. Analyzes price, volatility, and balance to set/update grid configuration. Detects drift and recentres automatically.
Grid Bot — polls every 10s. Detects fills, proposes response orders, seeds missing buy levels.
Executor — evaluates each proposed order: spread, candles, orderbook, sentiment. Places or pauses.
# Install dependencies
npm install
# Copy and configure environment
cp .env.example .env
# Edit .env with your Kraken API keys and Anthropic key
# Run (validate mode — no real orders)
npm start
# Run live
# Set VALIDATE_ORDERS=false in .env, then:
npm start
# Monitor dashboard (separate terminal)
npm run monitornpm start # resume from saved state, skip strategist
npm start -- --reset # cancel all orders + wipe state + fresh strategist
npm start -- --reset-buys # cancel bot's open buy orders only
npm start -- --reset-sells # cancel bot's open sell orders only| Variable | Default | Description |
|---|---|---|
KRAKEN_API_KEY |
— | Kraken API key |
KRAKEN_API_SECRET |
— | Kraken API secret |
ANTHROPIC_API_KEY |
— | Anthropic API key (supports OAuth access tokens) |
VALIDATE_ORDERS |
true |
false to place real orders |
TRADING_BUDGET_USD |
4000 |
Max USD the strategist can deploy |
- Strategist fetches current price, 14-day ATR, and available balance
- Sets grid range at ~1x ATR above and below current price
- Sizes orders at 90% of budget split across all levels
- Saves config to
data/state.json
- Grid bot places buy orders below current price only (closest-first)
- Levels within 0.5x spacing of current price are skipped (too close to market)
- Sell orders are never placed speculatively — only reactively on fills
- Buy fills → sell placed one spacing above
- Sell fills → buy placed one spacing below
- Filled buy levels automatically refilled with new buy on next tick
- If price drifts > 2x spacing from grid centre → cancel all + reseed around new price
- If minor drift → adjust bounds only
- Strategist sees previous config history for continuity across restarts
- Grid pauses on: 3+ fills in same direction in 60s, bad spread (>$2), config errors
- Stale pauses cleared automatically on restart
- Auth errors pause grid instead of hammering Kraken
- Only bot-placed orders are ever cancelled — existing account orders untouched
src/
├── index.ts # entry point, CLI flags, startup logic
├── grid.ts # grid bot: polling, fill detection, seeding
├── state.ts # shared state + persistence
├── kraken.ts # ccxt singleton
├── tokens.ts # token/cost tracking
├── logger.ts # JSON event log + status.json writer
├── monitor.ts # terminal dashboard (npm run monitor)
├── types.ts # TypeScript types
├── agents/
│ ├── strategist.ts # Strategist agent + system prompt
│ └── executor.ts # Executor agent + system prompt
└── tools/
├── cancel_orders.ts # cancel all tracked orders + reset bootstrap
├── get_balance.ts # ETH/USD balance (budget capped)
├── get_candles.ts # OHLCV candles
├── get_grid_state.ts # current state dump
├── get_orderbook.ts # depth + spread
├── get_price.ts # ETH/USD mid price
├── get_sentiment.ts # Fear & Greed index
├── get_volatility.ts # ATR + std dev
├── pause_grid.ts # pause with reason
├── place_order.ts # limit order (validate or live)
├── propose_grid_config.ts # save new grid config
└── update_grid_config.ts # modify running grid
data/
└── state.json # persisted state (gitignored)
logs/
├── status.json # live status, updated every tick (gitignored)
├── YYYY-MM-DD.jsonl # event log (gitignored)
├── YYYY-MM-DD-executor.log # executor reasoning audit (gitignored)
└── config-history.jsonl # all grid configs ever set (gitignored)
npm run monitorKRAKEN GRID AGENT 2026-03-06 14:00:00
----------------------------------------------------------
ETH/USD $2,001.70 ▼ -2.31
Grid $1916 ────────────●─────────── $2184
----------------------------------------------------------
OPEN ORDERS
SELL 0.22 @ $2050.00 $48.30 away ░░░░░░░░░░░░░░░░
BUY 0.22 @ $1983.00 $18.70 away ████████████░░░░
BUY 0.22 @ $1949.50 $52.20 away ████████░░░░░░░░
BUY 0.22 @ $1916.00 $85.70 away ████░░░░░░░░░░░░
----------------------------------------------------------
FILLS TODAY 1 P&L TODAY +$0.00
STATUS RUNNING
----------------------------------------------------------
API COST $0.1376 total (19 calls)
strategist 3 calls 16789 tokens $0.0205
executor 16 calls 62840 tokens $0.1171
----------------------------------------------------------
Last tick: 3s ago
@mariozechner/pi-agent-core— agent loop + tool calling@mariozechner/pi-ai— LLM provider abstractionccxt— Kraken connectivityclaude-sonnet-4-20250514— model for both agents- TypeScript +
tsx— no compile step needed
See ROADMAP.md for planned features including:
- Batch market data fetching
- Telegram notifications
- P&L tracking per round trip
- Risk modes (conservative / normal / aggressive)
- ETH accumulation mode
- Localhost status dashboard
- Market analyst agent (regime detection, BTC correlation)