Coinbase Trading Bot

Production-Grade Infrastructure for Agentic Quantitative Trading

An asynchronous, event-driven framework designed to bridge the gap between Large Language Model reasoning and professional market execution. It provides hardened infrastructure—WebSocket management, order lifecycle persistence, and multi-stage risk validation—allowing developers to focus entirely on the strategy layer.


System Architecture

Built on an Async Event Bus architecture. All components are decoupled nodes that communicate via typed, immutable events, ensuring non-blocking execution and high throughput.

Coinbase WebSocket MarketData PriceUpdate Strategy PriceBuffer + Claude AI + News OrderRequest OrderManager calls check() RiskManager Kill Switch · Order Size · Daily Drawdown Abort Validated RiskViolation KillSwitchActivated Coinbase API OrderFilled OrderFailed PositionTracker P&L · daily_summary PositionChanged SQLite · orders · positions · daily_summary · predictions LEGEND Event Validated Rejected External 7 event types: PriceUpdate · OrderRequest · OrderFilled · OrderFailed · RiskViolation · PositionChanged · KillSwitchActivated

Core Components

Component Responsibility
Market Data Real-time Coinbase WebSocket (Ticker Channel) persistence.
Order Manager Full lifecycle tracking with fee accounting and 5-stage fill verification.
Position Tracker Real-time realized P&L and daily summaries via SQLite.
Strategy Select Dynamic switching between PriceOnly and News-Aware (Grok + Claude) modes.

Intelligence Layer

The system treats trading as a multi-modal cognitive process rather than a set of rigid indicators.

  • Claude Opus 4.6 Integration — High-context price target forecasting using structured JSON outputs.
  • Grok xAI News Service — Ingests real-time crypto news and sentiment to inform high-conviction trades.
  • Vectorized History — Maintains an in-memory PriceBuffer for technical analysis snapshots.

Risk Management & Transparency

Defense is the only way to survive. A three-stage validation pipeline functions as a persistent circuit breaker.

Kill Switch
An emergency halt that persists across system restarts via SQLite.
Order Guardrails
Strict MAX_ORDER_SIZE_USD limits per transaction.
Daily Drawdown Protection
Automatic halt if cumulative losses exceed MAX_DAILY_LOSS_USD.

The Dashboard

The included Next.js Dashboard provides institutional-level visibility.

Equity Curves
Real-time portfolio performance and drawdown stats.
Prediction Logs
Expandable logs showing news headlines and AI reasoning for every trade.
Execution History
Full order logs with actual fill prices and exchange fees.
Risk Status
Kill switch state, daily drawdown, and guardrail violations.

Developer Setup

Prerequisites

Quick Start

# Clone and install in editable mode
git clone <repo-url> coinbase_trading_bot
cd coinbase_trading_bot
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

# Configure environment
cp .env.example .env

# Verify plumbing with the Interactive Smoke Test
python scripts/smoke_test.py

Reliability Testing

80+ unit and integration tests using mocked Coinbase responses.

pytest --cov=src

Disclaimers

For Research and Educational Purposes Only.
Digital asset trading involves significant risk. This software is provided "as-is" without warranties. Always validate your strategies via the smoke_test.py script and paper trading before deploying capital.