A modern, enterprise-grade trading bot implementing Smart DCA (Dollar Cost Averaging) strategy with multi-user support, comprehensive risk management, and real-time monitoring.
- Docker & Docker Compose v2
- Make (optional, for convenient commands)
- Go 1.25+ (for local development)
- Node.js 24+ (for frontend development)
# Clone and setup environment
git clone git@github.com:askuksov/trader.git
cd trader
# Setup development environment
make setup
# Configure environment variables
vim deployments/.env
# Optional: Create local overrides
cp deployments/.env deployments/.env.local
vim deployments/.env.local# Start all services
make up
# Check service health
make health- Frontend Dashboard: http://localhost:3000
- Backend API: http://localhost:8080
- API Documentation: http://localhost:8080/docs (coming soon)
- Grafana Monitoring: http://localhost:3001 (admin/admin)
- Prometheus Metrics: http://localhost:9090
- ML Service: http://localhost:5000
- Adminer (Database UI): http://localhost:8081
- Mailpit (Email Testing): http://localhost:8025
- Backend: Go 1.25 API server with JWT authentication
- Frontend: React 18 dashboard with real-time monitoring
- ML Service: Python Flask service for price predictions (stub)
- MySQL 8: Primary database for positions and user data
- Redis: Caching and session storage
- Prometheus: Metrics collection
- Grafana: Monitoring dashboards
- Adminer: Database management interface
- Mailpit: Email testing tool for development
- π Multi-user system with role-based access control
- π€ Smart DCA Strategy - never sell at a loss
- π Encrypted API key management (AES-256-GCM)
- π Real-time monitoring with Prometheus & Grafana
- π¨ Emergency stop system with granular controls
- π State recovery - recover positions after crashes <30s
- π± Notifications via Telegram and Email
- π¦ HitBTC Integration (MVP), Binance support planned
# Start/stop services
make up # Start all services
make down # Stop all services
make restart # Restart all services
# Logs and monitoring
make logs # All service logs
make logs-backend # Backend logs only
make logs-db # Database logs
make health # Health check all services
# Development
make build # Rebuild Docker images
make clean # Clean up Docker resources
make reset # Full reset (clean + up)
# Database operations (Goose integration pending)
make db-migrate # Run migrations (will use Goose)
make db-backup # Create backup
make db-restore BACKUP_FILE=backup.sql # Restore backup
# Code quality
make test # Run all tests
make lint # Run linters
make format # Format code
# Development tools
make open-adminer # Open database admin UI
make open-mailpit # Open email testing UI-
Backend Development:
- Hot reload enabled with Air
- Files in
backend/are watched for changes - Access: http://localhost:8080
- Database management: http://localhost:8081
-
Frontend Development:
- React development server with hot reload
- Files in
frontend/are watched for changes - Proxy configured to backend API
- Access: http://localhost:3000
-
Database Changes:
- Initial Schema: Loaded via
scripts/init-db.sql - Migrations: Will be handled by Goose tool
- Management: Use Adminer at http://localhost:8081
- Initial Schema: Loaded via
-
Email Testing:
- Mailpit: Captures all outgoing emails at http://localhost:8025
- SMTP: Pre-configured to use Mailpit (localhost:1025)
trader/
βββ backend/ # Go API server
β βββ cmd/ # Application entrypoints
β βββ internal/ # Private application code
β βββ pkg/ # Public packages
β βββ Dockerfile
βββ frontend/ # React dashboard
β βββ src/ # React source code
β βββ public/ # Static assets
β βββ Dockerfile
βββ ml-service/ # ML predictions service
β βββ app/ # Python Flask app
β βββ Dockerfile
βββ deployments/ # Docker configurations
β βββ docker-compose.dev.yml
β βββ docker-compose.prod.yml
β βββ .env # Base environment configuration
β βββ .env.local # Local development overrides (optional)
β βββ .env.example # Configuration template
βββ monitoring/ # Prometheus & Grafana
β βββ prometheus/
β βββ grafana/
βββ scripts/ # Utility scripts
βββ docs/ # Documentation (organized by topic)
β βββ 01_Product_Requirements/
β βββ 02_Technical_Design/
β βββ 03_DevOps_MVP/
β βββ 04_Golang_MVP/
β βββ 05_Development_Milestones/
βββ Makefile # Development commands
The project uses a flexible configuration system with two files:
.env(required) - Base configuration for all environments.env.local(optional) - Local overrides that take precedence
# Base configuration (.env)
MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=trader
MYSQL_USER=dca_user
MYSQL_PASSWORD=password
# Backend
API_ENCRYPTION_KEY=your-32-character-encryption-key
JWT_SECRET=your-jwt-secret-key
# Exchange APIs
HITBTC_API_URL=https://api.hitbtc.com/api/3
HITBTC_WS_URL=wss://api.hitbtc.com/api/3/ws
# Email (Development - uses Mailpit)
SMTP_HOST=mailpit
SMTP_PORT=1025
# Notifications
TELEGRAM_BOT_TOKEN=your-telegram-bot-tokenCreate .env.local to override any variables for your local environment:
# Example local overrides
LOG_LEVEL=debug
API_ENCRYPTION_KEY=my-local-development-key
TELEGRAM_BOT_TOKEN=my-personal-bot-token- Grafana: admin/admin
- MySQL: root/rootpassword, dca_user/password
- Redis: password: redispassword
- Adminer: Use MySQL credentials above
- Initial Schema: Loaded automatically via
init-db.sql - Management UI: Adminer at http://localhost:8081
- Backup/Restore: Available via Makefile commands
The backend developer will integrate the Goose migration tool:
make db-migrate- Run pending migrationsmake db-seed- Seed database with test data- Migration files will be in
backend/internal/database/migrations/
# Via Adminer (Web UI)
make open-adminer
# Server: mysql, Username: dca_user, Password: password, Database: trader
# Via Command Line
make shell-db
# Via Redis CLI
make shell-redis- Web UI: http://localhost:8025
- SMTP: localhost:1025 (automatically configured)
- Features: View sent emails, test email templates
- No authentication required for development
All emails sent by the application are captured by Mailpit for testing.
# Emergency stop all positions
curl -X POST http://localhost:8080/api/v1/emergency/stop-all
# Stop by user
curl -X POST http://localhost:8080/api/v1/emergency/stop-user/123
# Graceful stop
make down# Backup database
make db-backup
# Backup configuration
cp deployments/.env backups/env_$(date +%Y%m%d_%H%M%S).backup- Initial Buy: $150 (50% of deposit)
- DCA Levels:
- Level 1: -3% β +$45 (15% of deposit)
- Level 2: -7% β +$60 (20% of deposit)
- Level 3: -12% β +$45 (15% of deposit)
- Take Profit Levels (from average price):
- TP1: +8% β Sell 25% of position
- TP2: +15% β Sell 35% of position
- TP3: +25% β Sell 40% of position
- Reserve: $30 (10% for extreme drops)
- β Never sell at a loss - only LONG positions
- β Adaptive averaging - larger volumes on bigger drops
- β Partial profits - gradual profit taking
- β Liquidity reserve - funds for extreme market conditions
- JWT-based authentication with access/refresh tokens
- Role-based access control (Super Admin, Admin, Trader, Viewer)
- Granular permissions per resource and action
- API key encryption with AES-256-GCM
- All API keys encrypted at rest
- Password hashing with bcrypt
- User data isolation
- Audit logging for all critical operations
- Trading position performance
- DCA strategy effectiveness
- API key utilization
- System health and performance
- User activity and authentication
Access Grafana at http://localhost:3001 with admin/admin:
- Trading Bot Overview: System health and service status
- DCA Performance: Strategy effectiveness metrics
- User Analytics: Multi-user activity monitoring
# All tests
make test
# Backend only
cd backend && go test ./...
# Frontend only
cd frontend && npm test
# Integration tests
make test-integrationTests use a separate test database automatically created during test runs.
# Build production images
make prod-build
# Deploy production environment
make prod-up- Use proper secrets management (not .env.local files)
- Configure SSL/TLS certificates
- Set up proper monitoring and alerting
- Configure backup strategies
- Use production-grade database setup
- Configure real SMTP server (not Mailpit)
Documentation is organized by topic in the docs/ folder:
-
Services won't start:
make down && make clean && make up
-
Database connection issues:
make logs-db # Check MySQL logs for errors # Use Adminer to verify connectivity
-
Configuration issues:
# Check base configuration vim deployments/.env # Check local overrides vim deployments/.env.local
-
Permission errors:
chmod +x scripts/*.sh -
Port conflicts:
- Check if ports 3000, 3001, 5000, 6379, 8080, 8081, 8025, 9090 are available
- Modify port mappings in docker-compose.dev.yml if needed
-
Docker Compose version issues:
# Check version docker compose version # If you have old docker-compose: docker-compose --version
# Comprehensive health check
make health
# Individual service status
make status
# Service logs
make logs-backend
make logs-frontend
make logs-db
make logs-mailpit# Database management
make open-adminer
# Email testing
make open-mailpit
# Container shells
make shell-backend
make shell-db
make shell-redis# Validate complete setup
make validate
# Check Docker Compose compatibility
docker compose version- Follow the development workflow above
- Ensure all tests pass:
make test - Run linters:
make lint - Format code:
make format - Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
For more detailed information, see the documentation in the docs/ directory.