A production-grade Go application that identifies and executes triangular arbitrage opportunities on the CoinEx cryptocurrency exchange in real time.
┌──────────────┐
│ CoinEx │
│ WebSocket │
└──────┬───────┘
│ order book updates
┌──────▼───────┐
│ Market │
│ Manager │
└──────┬───────┘
│
┌───────────────▼───────────────┐
│ Arbitrage Engine │
│ (scan → detect → execute) │
└───────────────┬───────────────┘
│ FOK orders
┌───────────────▼───────────────┐
│ CoinEx REST API Client │
└───────────────────────────────┘
The bot maintains a real-time order book for every traded market via WebSocket, continuously scans for three-leg arbitrage cycles (e.g., USDT → BTC → USDT), and executes Fill-or-Kill orders when the estimated profit exceeds a configurable threshold.
.
├── cmd/bot/main.go # Application entry point
├── internal/
│ ├── config/ # Configuration loading and validation
│ ├── execution/ # Arbitrage detection and execution engine
│ ├── exchange/ # CoinEx API client (REST + auth)
│ ├── logging/ # Structured logging infrastructure
│ ├── market/ # Market data processing
│ └── network/ # HTTP client, WebSocket, rate limiting
├── pkg/
│ ├── common/ # Shared utilities
│ └── models/ # Core data types (OrderBook, Metrics, etc.)
├── .github/workflows/ci.yml # GitHub Actions CI pipeline
├── .golangci-lint.yml # Linter configuration
├── Makefile # Build, test, lint targets
└── go.mod
- Go 1.24 or later
- CoinEx API key and secret (set via environment variables)
The bot reads configuration from config.json (see config.example.json for a template) and environment variables:
| Variable | Description |
|---|---|
COINEX_API_KEY |
CoinEx API key |
COINEX_SECRET_ID |
CoinEx API secret |
# Install dependencies
make deps
# Build
make build
# Run
make run
# Or build and run in one step
make runmake build-all-platforms # builds for linux/amd64 and darwin/arm64make test # run all tests with race detector
make cover # run with coverage report (HTML)
go test -race ./... # run with race detectorThis project uses GitHub Actions for continuous integration. On every push and pull request to main:
- Lint — runs
golangci-lintwith the project configuration - Test — runs the full test suite with race detection and coverage
- Build — compiles the binary and runs
go vet
The bot exposes a health check endpoint at GET :8080/healthz that returns 200 OK when the process is running.
GNU Affero General Public License v3.0 (AGPL-3.0)
See LICENSE for the full text.
If you use, modify, or deploy this software — especially as a network service — you must release your changes under the same license. This ensures that everyone benefits from improvements made to the code.