A production-ready cryptocurrency trading bot built with Go and React, featuring paper trading and comprehensive risk management.
- Paper Trading: Test strategies with simulated execution before risking real money
- Single Exchange Integration: Coinbase Advanced Trade API with comprehensive error handling
- Mean Reversion Strategy: RSI + Bollinger Bands + SMA indicators
- Risk Management: Kill switch, position limits, daily loss limits, stop-loss
- Real-Time Dashboard: React + TypeScript UI with live monitoring
- Event-Driven Architecture: NATS message bus for decoupled components
- Production-Ready: Structured logging, fault tolerance, health checks
┌──────────────┐
│ Dashboard │ (React + TypeScript)
└──────┬───────┘
│ HTTP/WebSocket
┌──────▼────────────────┐
│ API Gateway (Gin) │
└──────┬────────────────┘
│
┌───▼────┐
│ NATS │ (Message Bus)
└───┬────┘
│
┌───┴────────────────────────────────┐
│ │
┌──▼──────────────┐ ┌───────────▼────────┐
│ Market Data Svc │ │ Strategy Engine │
└─────────────────┘ └────────┬───────────┘
│
┌───────────▼──────────┐
│ Risk Manager │
└───────────┬──────────┘
│
┌───────────▼──────────┐
│ Order Manager │
└───────────┬──────────┘
│
┌───────────▼──────────┐
│ Exchange Connector │
└───────────┬──────────┘
│
┌───────────▼──────────┐
│ PostgreSQL │
└──────────────────────┘
Backend:
- Go 1.21+
- PostgreSQL 15+
- NATS 2.10+
- Gin (HTTP framework)
- sqlc (type-safe SQL)
Frontend:
- React 18
- TypeScript 5
- TradingView Lightweight Charts
- TailwindCSS
- Docker & Docker Compose
- Go 1.21+
- Node.js 18+
- Make
docker-compose up -d
cd backend
go run ./cmd/migrate up
In separate terminals:
# Terminal 1 - Market Data Service
cd backend && go run ./cmd/market-data
# Terminal 2 - Trading Bot
cd backend && go run ./cmd/trading-bot
# Terminal 3 - API Gateway
cd backend && go run ./cmd/api-gateway
cd frontend
npm install
npm run dev
Copy .env.example
to .env
and configure:
# Database
DATABASE_URL=postgresql://trading:trading@localhost:5432/trading_bot?sslmode=disable
# NATS
NATS_URL=nats://localhost:4222
# Coinbase API
COINBASE_API_KEY=your_api_key
COINBASE_API_SECRET=your_api_secret
COINBASE_API_PASSPHRASE=your_passphrase
COINBASE_USE_SANDBOX=true
# Risk Management
RISK_MAX_POSITION_SIZE_USD=100
RISK_MAX_OPEN_POSITIONS=1
RISK_DAILY_LOSS_LIMIT_PERCENT=2.0
RISK_STOP_LOSS_PERCENT=2.0
RISK_MAX_HOLD_TIME_HOURS=24
# Trading Mode
TRADING_MODE=paper # paper or live
.
├── backend/ # Go backend services
│ ├── cmd/
│ │ ├── api-gateway/ # HTTP API server
│ │ ├── market-data/ # Price data ingestion
│ │ ├── trading-bot/ # Main trading bot service
│ │ └── migrate/ # Database migration tool
│ ├── internal/
│ │ ├── exchange/ # Exchange connector implementations
│ │ ├── strategy/ # Trading strategies
│ │ ├── risk/ # Risk management logic
│ │ ├── order/ # Order management
│ │ ├── marketdata/ # Market data service
│ │ ├── models/ # Domain models
│ │ ├── config/ # Configuration
│ │ ├── events/ # NATS event system
│ │ └── logger/ # Logging utilities
│ ├── migrations/ # Database migrations
│ ├── go.mod # Go dependencies
│ └── Makefile # Backend build commands
├── frontend/ # React TypeScript dashboard
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── api/ # API client
│ │ ├── hooks/ # Custom React hooks
│ │ └── types/ # TypeScript types
│ ├── package.json # Frontend dependencies
│ └── vite.config.ts # Vite configuration
├── docker-compose.yml # Infrastructure setup
├── scripts/ # Utility scripts
└── README.md # This file
cd backend
sqlc generate
cd backend
go build -o ../bin/migrate ./cmd/migrate
go build -o ../bin/market-data ./cmd/market-data
go build -o ../bin/trading-bot ./cmd/trading-bot
go build -o ../bin/api-gateway ./cmd/api-gateway
- Prominent red button in UI
- API endpoint:
POST /api/v1/system/kill-switch
- Immediately halts all trading and cancels orders
- Requires manual re-enable
- Maximum position size (default: $100)
- Maximum open positions (default: 1)
- Daily loss limit (default: 2%)
- Per-trade stop-loss (default: 2%)
- Maximum hold time (default: 24 hours)
- Identical code path to live trading
- Simulated execution with realistic slippage
- No real money at risk
- Always start here before going live
- Logs: Structured JSON logs to stdout
- Health Checks:
/health
endpoint on each service - Dashboard: Real-time monitoring at http://localhost:3000
See DEPLOYMENT.md for production deployment guide.
MIT License - See LICENSE file for details
This software is for educational purposes. Cryptocurrency trading carries significant financial risk. Always:
- Start with paper trading
- Never invest more than you can afford to lose
- Thoroughly test strategies before live trading
- Monitor positions actively
- Understand the code before running it
The authors are not responsible for any financial losses incurred.