Files
xau-ai-trading-bot/DOCKER-SETUP-SUMMARY.md
T
buckybonez 82eca84230 feat: apply #28B smart breakeven + #31B H1 EMA20 filter, add backtests #26-#32
Live trading optimizations (cumulative: $2,807 net, 81.8% WR, Sharpe 3.97):
- #28B: Smart breakeven locks profit at entry + 0.5x ATR instead of fixed $2
- #31B: H1 Price vs EMA20 filter — BUY only when H1 bullish, SELL only when bearish

Backtests #26-#32 (7 scripts testing sell improvement, regime-aware entry,
confluence scoring, dynamic RR, multi-TF H1, and ML exit optimizer).
Winners: #28B (+$229), #31B (+$343). Failed: #26, #27, #29, #30, #32.

Also includes: web dashboard redesign, Docker setup, startup scripts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 10:33:24 +07:00

11 KiB

XAUBot AI - Docker Integration Summary

Completed Tasks

1. Created Dockerfile for Next.js Dashboard

  • Multi-stage build for optimization
  • Standalone output for minimal image size
  • Production-ready configuration
  • Non-root user for security

Location: web-dashboard/Dockerfile

2. Created Dockerfile for Python Trading API

  • Python 3.11-slim base image
  • FastAPI server with health checks
  • Proper dependency management
  • Volume mounts for data/logs/models

Location: Dockerfile (root directory)

3. Updated Docker Compose Configuration

  • 4 services: postgres, trading-api, dashboard, pgadmin
  • Proper service dependencies and health checks
  • Custom bridge network for inter-service communication
  • Environment variable support via .env file
  • Volume persistence for database and pgadmin

Location: docker-compose.yml

4. Created Environment Configuration

  • Template with all required variables
  • Clear documentation for each setting
  • Default values for non-sensitive configs

Location: .env.docker.example

5. Created Docker Ignore Files

  • Excludes unnecessary files from images
  • Reduces build context size
  • Improves build performance

Locations:

  • web-dashboard/.dockerignore
  • .dockerignore (root)

6. Created Helper Scripts

Windows Batch Scripts:

  • docker-start.bat - Start all services
  • docker-stop.bat - Stop services with options
  • docker-logs.bat - View service logs

Linux/Mac Shell Scripts:

  • docker-start.sh - Start all services
  • docker-stop.sh - Stop services with options
  • docker-logs.sh - View service logs

7. Updated Next.js Configuration

  • Enabled standalone output for Docker
  • Optimized for production builds

Location: web-dashboard/next.config.ts

8. Created Comprehensive Documentation

  • Complete Docker setup guide
  • Architecture diagram
  • Service management commands
  • Troubleshooting section
  • Security best practices
  • Performance tuning tips

Location: DOCKER.md

9. Updated Main README

  • Added Docker deployment section as recommended method
  • Clear quick start instructions
  • Links to full documentation

Location: README.md

🏗️ Architecture

┌──────────────────────────────────────────────────────┐
│                    Docker Network                     │
│              (trading_bot_network)                    │
├──────────────────────────────────────────────────────┤
│                                                       │
│  ┌─────────────────┐         ┌──────────────────┐  │
│  │   Dashboard      │────────▶│   Trading API    │  │
│  │   (Next.js)      │  HTTP   │   (FastAPI)      │  │
│  │   Port: 3000     │         │   Port: 8000     │  │
│  └─────────────────┘         └────────┬─────────┘  │
│                                        │             │
│                                        │ PostgreSQL  │
│                                        │ Protocol    │
│                                        │             │
│                               ┌────────▼─────────┐  │
│                               │   PostgreSQL     │  │
│                               │   Database       │  │
│                               │   Port: 5432     │  │
│                               └──────────────────┘  │
│                                                       │
│  ┌─────────────────┐ (Optional - Admin Profile)     │
│  │    pgAdmin       │                                │
│  │   Port: 5050     │                                │
│  └─────────────────┘                                │
└──────────────────────────────────────────────────────┘
         ↕ Exposed Ports
    localhost:3000 (Dashboard)
    localhost:8000 (API)
    localhost:5432 (Database)
    localhost:5050 (pgAdmin)

🚀 Quick Start Guide

1. Initial Setup (One-time)

# Navigate to project
cd "Smart Automatic Trading BOT + AI"

# Create environment file
copy .env.docker.example .env

# Edit .env with your MT5 credentials
notepad .env

Required credentials in .env:

MT5_LOGIN=your_login
MT5_PASSWORD=your_password
MT5_SERVER=your_server
MT5_PATH=/path/to/mt5/terminal

2. Start Services (Windows)

Option A: Using helper script (Recommended)

REM Start core services
docker-start.bat

REM Or start with pgAdmin
docker-start.bat --admin

Option B: Manual docker-compose

REM Build and start
docker-compose up -d

REM With pgAdmin
docker-compose --profile admin up -d

3. Access the Dashboard

Open your browser and go to:

You'll see:

  • Real-time price updates
  • Account balance and equity
  • Trading signals (SMC + ML)
  • Market regime
  • Open positions
  • Risk status
  • Activity logs

4. Check Other Services

📋 Common Commands

View Logs

REM All services
docker-logs.bat

REM Specific service
docker-logs.bat trading-api
docker-logs.bat dashboard
docker-logs.bat postgres

Check Status

docker-compose ps

Restart Services

REM Restart all
docker-compose restart

REM Restart specific
docker-compose restart trading-api
docker-compose restart dashboard

Stop Services

REM Stop (keeps data)
docker-stop.bat

REM Stop and remove containers (keeps data)
docker-stop.bat --remove

REM Stop and remove everything including data (⚠️ DANGER!)
docker-stop.bat --clean

Update Code and Rebuild

REM Pull latest code
git pull

REM Rebuild and restart
docker-compose build
docker-compose up -d

🔧 Configuration

Port Configuration

Default ports can be changed in .env:

API_PORT=8000          # Trading API
DASHBOARD_PORT=3000    # Web Dashboard
DB_PORT=5432          # PostgreSQL
PGADMIN_PORT=5050     # pgAdmin

Environment Variables

All configuration is in .env:

Category Variables
MT5 MT5_LOGIN, MT5_PASSWORD, MT5_SERVER, MT5_PATH
Trading SYMBOL, CAPITAL
Database DB_USER, DB_PASSWORD, DB_NAME
Telegram TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID
Ports API_PORT, DASHBOARD_PORT, DB_PORT, PGADMIN_PORT

🐛 Troubleshooting

Dashboard Shows "Connection Error"

Check if API is running:

curl http://localhost:8000/api/health

View API logs:

docker-logs.bat trading-api

Port Already in Use

Find what's using the port:

netstat -ano | findstr :3000
netstat -ano | findstr :8000

Change port in .env:

DASHBOARD_PORT=3001
API_PORT=8001

Restart services:

docker-compose down
docker-compose up -d

Can't Connect to MT5

  1. Check credentials in .env
  2. Ensure MT5 terminal is accessible
  3. View API logs for connection errors:
    docker-logs.bat trading-api
    

Database Connection Issues

Check database health:

docker-compose ps postgres

Test connection:

docker exec -it trading_bot_db pg_isready -U trading_bot

View database logs:

docker-logs.bat postgres

📊 Monitoring

View Real-time Logs

REM Follow all logs
docker-compose logs -f

REM Follow specific service
docker-compose logs -f trading-api

Check Resource Usage

docker stats

Service Health

REM All services
docker-compose ps

REM Detailed info
docker inspect trading_bot_api
docker inspect trading_bot_dashboard

🔐 Security Notes

  1. Never commit .env file - It contains sensitive credentials
  2. Change default passwords - Especially for database and pgAdmin
  3. Use strong passwords - For all services
  4. Limit port exposure - Only expose ports you need
  5. Keep Docker updated - Regular security updates

📁 File Structure

xaubot-ai/
├── Dockerfile                    # Python API Docker image
├── docker-compose.yml            # Service orchestration
├── .env                         # Environment variables (DO NOT COMMIT)
├── .env.docker.example          # Environment template
├── .dockerignore               # Files to exclude from build
├── docker-start.bat            # Windows start script
├── docker-stop.bat             # Windows stop script
├── docker-logs.bat             # Windows logs script
├── docker-start.sh             # Linux/Mac start script
├── docker-stop.sh              # Linux/Mac stop script
├── docker-logs.sh              # Linux/Mac logs script
├── DOCKER.md                   # Full Docker documentation
└── web-dashboard/
    ├── Dockerfile              # Next.js dashboard image
    ├── .dockerignore          # Dashboard build exclusions
    └── next.config.ts         # Next.js config (standalone output)

🎯 Benefits of Docker Setup

Easy Setup - One command to start everything Consistent Environment - Same setup on any machine Isolated Services - No conflicts with other software Easy Updates - Rebuild and restart to update Production Ready - Same setup for dev and production Automatic Restarts - Services auto-restart on crash Health Monitoring - Built-in health checks Volume Persistence - Data survives container restarts

📚 Additional Resources

🆘 Support

If you encounter issues:

  1. Check the logs: docker-logs.bat
  2. Verify services: docker-compose ps
  3. Review troubleshooting section in DOCKER.md
  4. Check service health: curl http://localhost:8000/api/health

Setup completed: Feb 6, 2026 Ready to deploy! 🚀