A modular triangular arbitrage trading bot built in Go with clean architecture principles, supporting local development with Docker and deployment to AWS ECS Fargate.
- 🏗️ Clean, modular architecture with dependency injection
 - ⚡ High-performance Echo HTTP framework with middleware
 - 🐳 Docker support for local development
 - ☁️ AWS ECS Fargate deployment with Terraform
 - 📊 NewRelic integration with automatic request tracing
 - 🔄 Triangular arbitrage detection and execution
 - 🧪 Dry-run mode for safe testing
 - 📡 Real-time market data via Binance WebSocket
 
delta-bot/
├── cmd/
│   └── main.go              # Application entry point
├── internal/
│   ├── config/              # Configuration management
│   ├── logger/              # Logging and NewRelic integration
│   ├── server/              # Echo HTTP server implementation
│   ├── middleware/          # HTTP middleware (NewRelic, logging, etc.)
│   ├── handlers/            # HTTP request handlers
│   ├── routes/              # Route definitions and setup
│   ├── exchange/            # Exchange integrations (Binance)
│   ├── arb/                 # Arbitrage detection logic
│   └── executor/            # Trade execution engine
├── deployments/
│   └── terraform/           # Infrastructure as Code
├── docker/
│   ├── Dockerfile
│   └── docker-compose.yml
└── Makefile                 # Development commands
- Go 1.21+
 - Docker and Docker Compose
 - Make
 
- 
Clone and setup:
git clone <repository-url> cd delta-bot make deps
 - 
Create environment file:
cp .env.example .env # Edit .env with your configuration - 
Configure environment variables:
# Server Configuration PORT=8080 LOG_LEVEL=INFO # NewRelic Configuration NEW_RELIC_LICENSE_KEY=your_license_key_here NEW_RELIC_APP_NAME=delta-bot # Trading Configuration DRY_RUN=true BINANCE_API_KEY=your_binance_api_key BINANCE_SECRET_KEY=your_binance_secret_key # Arbitrage Configuration MIN_PROFIT_THRESHOLD=0.5 MAX_TRADE_AMOUNT=1000
 - 
Run the application:
# Run locally make run # Or run with Docker make docker-run
 - 
Test the health endpoint:
make health # or curl http://localhost:8080/health 
make help          # Show available commands
make deps          # Download dependencies
make build         # Build the application
make run           # Build and run
make dev           # Run with live reload (requires air)
make test          # Run tests
make test-coverage # Run tests with coverage
make lint          # Run linter
make fmt           # Format code
make clean         # Clean build artifacts
# Docker commands
make docker-build          # Build Docker image
make docker-run            # Run with docker-compose
make docker-run-detached   # Run in background
make docker-down           # Stop containers
make docker-logs           # View container logs
make docker-restart        # Restart containers
make docker-clean          # Clean up images and containers
# Terraform commands
make tf-init       # Initialize Terraform
make tf-plan       # Plan infrastructure changes
make tf-apply      # Deploy to AWS
make tf-destroy    # Destroy AWS infrastructure
make tf-output     # Show deployment outputsGET /healthResponse:
{
  "status": "healthy",
  "timestamp": "2024-01-01T12:00:00Z"
}The application uses environment variables for configuration with sensible defaults:
| Variable | Default | Description | 
|---|---|---|
PORT | 
8080 | 
HTTP server port | 
LOG_LEVEL | 
INFO | 
Logging level | 
NEW_RELIC_LICENSE_KEY | 
`` | NewRelic license key | 
NEW_RELIC_APP_NAME | 
delta-bot | 
NewRelic application name | 
DRY_RUN | 
true | 
Enable dry-run mode | 
MIN_PROFIT_THRESHOLD | 
0.5 | 
Minimum profit threshold (%) | 
MAX_TRADE_AMOUNT | 
1000 | 
Maximum trade amount | 
The application follows clean architecture principles with clear separation of concerns:
- Echo Framework: High-performance HTTP router with middleware support
 - Middleware: NewRelic tracing, request logging, CORS, recovery
 - Handlers: Business logic separated from HTTP concerns
 - Routes: Centralized route configuration
 
- Config: Environment-based configuration management
 - Logger: Structured logging with NewRelic integration
 - Server: Echo server wrapper with graceful shutdown
 
- Recovery: Panic recovery and error handling
 - CORS: Cross-origin request support
 - NewRelic: Automatic request tracing and performance monitoring
 - Request Logging: Structured HTTP request/response logging
 
- Step 1: Basic HTTP server with health endpoint and NewRelic integration
 - Step 2: Docker containerization for local development
 - Step 3: Terraform infrastructure for AWS ECS Fargate
 - Step 4: Enhanced NewRelic logging and custom events
 - Step 5: Core bot structure (exchange, arbitrage, executor packages)
 - Step 6: Simulation mode with mock data
 - Step 7: Real-time market data integration
 - Step 8: Live trade execution engine
 - Step 9: Environment-driven configuration flags
 - Step 10: Production monitoring and alerting
 
The application includes a complete Docker setup for local development:
🚀 Development (Recommended):
# Build and run with basic NewRelic APM
make docker-run
# Run in background
make docker-run-detached
# View logs
make docker-logs
# Stop containers
make docker-down📊 Production/Staging (Full Monitoring):
# Requires NEW_RELIC_LICENSE_KEY in .env
make docker-run-monitoring      # Includes NewRelic sidecars + log forwarding
make docker-logs-monitoring     # View all logs
make docker-down-monitoring     # Stop all monitoring💡 How it works: Single docker-compose.yml with profiles - sidecars only start when using the monitoring profile.
Deploy to AWS ECS Fargate with complete infrastructure automation:
# Quick deployment (after AWS CLI setup)
make tf-init      # Initialize Terraform
make tf-plan      # Review infrastructure changes  
make tf-apply     # Deploy to AWS# Testing environment first (always dry_run=true for safety)
make tf-init-test    # Initialize testing backend
make tf-apply-test   # Deploy to testing (shadow trades only)
# Production environment (configurable dry_run)
make tf-init-prod    # Initialize production backend  
make tf-apply-prod   # Deploy to production📖 Deployment guides:
- DEPLOYMENT.md - Complete single-environment setup
 - terraform/MULTI_ENVIRONMENT_SETUP.md - Multi-environment configuration
 
Features: AWS CLI setup, Terraform installation, credentials, Docker ECR, infrastructure deployment, monitoring
🏗️ Infrastructure includes:
- VPC with public subnets across multiple AZs
 - Application Load Balancer with health checks
 - ECS Fargate cluster with auto-scaling
 - CloudWatch logging and monitoring alarms
 - SSM Parameter Store for secure secrets
 - ECR repository for Docker images
 
- Multi-stage build: Optimized image size with Go build stage
 - Health checks: Built-in health monitoring
 - Environment variables: Full configuration via .env file
 - Development ready: Hot reload support and logging
 - Production ready: Minimal Alpine-based final image
 - NewRelic sidecars: Infrastructure monitoring and log forwarding
 
The application includes comprehensive NewRelic monitoring via sidecar containers:
- NewRelic Infrastructure Agent: System-level monitoring (CPU, memory, disk, network)
 - Fluent Bit Log Forwarder: Structured log forwarding to NewRelic Logs
 - Application Performance Monitoring: Built-in Go agent integration
 
# Development with basic monitoring
make docker-run
# Production-like monitoring with all sidecars
make docker-run-monitoring
# Background with full monitoring
make docker-run-monitoring-detached
# View all monitoring logs
make docker-logs-monitoring# Set your NewRelic license key
export NEW_RELIC_LICENSE_KEY=your_license_key_here
# Run with monitoring
make docker-run-monitoring- ✅ Application metrics: Request latency, throughput, errors
 - ✅ Infrastructure metrics: CPU, memory, disk, network usage
 - ✅ Container metrics: Docker container performance
 - ✅ Structured logs: Application logs with context and metadata
 - ✅ Custom events: Trading events, arbitrage opportunities
 - ✅ Health checks: Application and infrastructure health
 
MIT License - see LICENSE file for details.