refactor: reorganize project structure — consolidate Docker files, clean root

- Delete temp files: _tmp_analysis.py, nul, dashboard_screenshot.png
- Move ea/ to archive/ea/ (deprecated)
- Move 12 Docker helper scripts (.bat/.sh) to docker/scripts/
- Move 5 Docker docs to docker/docs/
- Move .env.docker.example, requirements-docker.txt to docker/
- Update all scripts with cd to project root for correct path resolution
- Update all doc references to new paths
- Update .gitignore with bot.pid, bot_output.log, *.png patterns
- Update CLAUDE.md, README.md directory trees

Root reduced from ~40 files to 12 essential files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
GifariKemal
2026-02-08 14:21:11 +07:00
parent 61877480b3
commit b2dc2dacd7
22 changed files with 110 additions and 68 deletions
+259
View File
@@ -0,0 +1,259 @@
# Dashboard Integration with Existing Docker Setup
## 🎯 Overview
Dashboard dan API telah diintegrasikan ke dalam Docker setup yang **sudah ada**. Database PostgreSQL yang sudah running **TIDAK AKAN DIGANGGU**.
## ✅ Existing Setup (Tidak Berubah)
Yang sudah jalan dan **tetap aman**:
-`trading_bot_db` - PostgreSQL database
-`trading_bot_network` - Docker network
- ✅ Database schema dengan 7 tables (trades, signals, dll)
- ✅ Volume `postgres_data` untuk persistence
## 🆕 New Services Added
Layanan baru yang ditambahkan:
1. **trading-api** - FastAPI backend untuk dashboard
2. **dashboard** - Next.js web interface
3. **pgadmin** - Database management (optional)
## 🚀 Quick Start
### Option 1: Gunakan Helper Script (Recommended)
```cmd
# Tambahkan dashboard ke setup yang sudah ada
docker\scripts\docker-add-dashboard.bat
```
Script ini akan:
1. Check database yang sudah running
2. Build API & Dashboard services
3. Start kedua services baru
4. Connect ke database & network yang sudah ada
### Option 2: Manual Docker Compose
```cmd
# Build hanya services baru
docker-compose build trading-api dashboard
# Start hanya services baru
docker-compose up -d trading-api dashboard
```
## 📊 Access Points
Setelah services running:
- **Dashboard:** http://localhost:3000
- **API:** http://localhost:8000
- **API Docs:** http://localhost:8000/docs
- **Database:** localhost:5432 (sudah running)
## 🔧 Service Management
### Check Status
```cmd
# Lihat status semua services
docker\scripts\docker-status.bat
# Atau manual
docker-compose ps
```
### View Logs
```cmd
# Logs dashboard
docker-compose logs -f dashboard
# Logs API
docker-compose logs -f trading-api
# Logs database
docker-compose logs -f postgres
```
### Restart Services
```cmd
# Restart hanya dashboard
docker-compose restart dashboard
# Restart hanya API
docker-compose restart trading-api
# Restart semua (termasuk database)
docker-compose restart
```
### Remove Dashboard (Keep Database)
```cmd
# Hapus dashboard tapi tetap keep database
docker\scripts\docker-remove-dashboard.bat
# Atau manual
docker-compose stop trading-api dashboard
docker-compose rm -f trading-api dashboard
```
## 🔗 Service Architecture
```
┌─────────────────────────────────────────────┐
│ trading_bot_network │
├─────────────────────────────────────────────┤
│ │
│ 📊 Dashboard (NEW) │
│ Port: 3000 │
│ └─> http://trading-api:8000 │
│ │
│ 🔌 Trading API (NEW) │
│ Port: 8000 │
│ └─> postgres:5432 │
│ │
│ 🗄️ PostgreSQL (EXISTING - NO CHANGE) │
│ Port: 5432 │
│ Status: Already Running │
│ Volume: postgres_data │
│ │
└─────────────────────────────────────────────┘
```
## 📝 Environment Variables
Edit `.env` untuk konfigurasi:
```env
# MT5 (Required for API)
MT5_LOGIN=your_login
MT5_PASSWORD=your_password
MT5_SERVER=your_server
MT5_PATH=C:/Program Files/MetaTrader 5/terminal64.exe
# Trading
SYMBOL=XAUUSD
CAPITAL=10000
# Database (Already configured)
DB_USER=trading_bot
DB_PASSWORD=trading_bot_2026
DB_NAME=trading_db
# Ports
API_PORT=8000
DASHBOARD_PORT=3000
DB_PORT=5432
```
## 🐛 Troubleshooting
### Dashboard tidak bisa connect ke API
**Check API health:**
```cmd
curl http://localhost:8000/api/health
```
**View API logs:**
```cmd
docker-compose logs -f trading-api
```
### API tidak bisa connect ke database
**Check database:**
```cmd
docker exec trading_bot_db pg_isready -U trading_bot
```
**Check network:**
```cmd
docker network inspect trading_bot_network
```
### Port conflict
Edit `.env` untuk ganti port:
```env
API_PORT=8001
DASHBOARD_PORT=3001
```
Then restart:
```cmd
docker-compose down trading-api dashboard
docker-compose up -d trading-api dashboard
```
## 💾 Data Persistence
**Database data tetap aman:**
- Volume `postgres_data` tetap ada
- Hapus container tidak hapus data
- Data tersimpan di Docker volume
**Check volume:**
```cmd
docker volume ls | findstr postgres
docker volume inspect trading_bot_postgres_data
```
## 🔄 Updates
**Update code dan rebuild:**
```cmd
# Pull latest code
git pull
# Rebuild services baru
docker-compose build trading-api dashboard
# Restart
docker-compose up -d trading-api dashboard
```
**Database tidak perlu rebuild** karena schema sudah ada.
## ⚠️ Important Notes
1. **Database tidak boleh dihapus** - Data trades ada di sini
2. **Jangan run `docker-compose down -v`** - Ini akan hapus volumes
3. **Untuk stop semua:** `docker-compose stop` (data aman)
4. **Untuk restart:** `docker-compose restart` atau `docker-compose up -d`
## 📚 Files Structure
```
xaubot-ai/
├── docker-compose.yml # Main orchestration (UPDATED)
├── Dockerfile # API image (NEW)
├── .env # Environment config
├── .dockerignore # Build exclusions
├── docker/
│ ├── .env.docker.example # Environment template
│ ├── requirements-docker.txt # Docker-specific deps
│ ├── init-db/
│ │ └── 01-schema.sql # Database schema (EXISTING)
│ ├── scripts/ # Helper scripts
│ │ ├── docker-add-dashboard.bat
│ │ ├── docker-remove-dashboard.bat
│ │ └── docker-status.bat
│ └── docs/ # Docker documentation
└── web-dashboard/
├── Dockerfile # Dashboard image (NEW)
└── .dockerignore # Build exclusions
```
## 🎯 Summary
**Database tetap jalan** - Tidak ada perubahan
**Services baru ditambahkan** - API & Dashboard
**Data aman** - Volume persistence
**Easy management** - Helper scripts
**Independent** - Bisa start/stop tanpa ganggu database
---
**Integration completed:** Feb 6, 2026
**Status:** Dashboard integrated with existing Docker setup ✨
+413
View File
@@ -0,0 +1,413 @@
# 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:** `docker/.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\scripts\docker-start.bat` - Start all services
- `docker\scripts\docker-stop.bat` - Stop services with options
- `docker\scripts\docker-logs.bat` - View service logs
#### Linux/Mac Shell Scripts:
- `docker/scripts/docker-start.sh` - Start all services
- `docker/scripts/docker-stop.sh` - Stop services with options
- `docker/scripts/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)
```bash
# Navigate to project
cd "Smart Automatic Trading BOT + AI"
# Create environment file
copy docker\.env.docker.example .env
# Edit .env with your MT5 credentials
notepad .env
```
**Required credentials in .env:**
```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)**
```cmd
REM Start core services
docker\scripts\docker-start.bat
REM Or start with pgAdmin
docker\scripts\docker-start.bat --admin
```
**Option B: Manual docker-compose**
```cmd
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:
- **Dashboard:** http://localhost:3000
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
- **API Docs:** http://localhost:8000/docs
- **API Health:** http://localhost:8000/api/health
- **API Status:** http://localhost:8000/api/status
- **pgAdmin:** http://localhost:5050 (if started with --admin)
## 📋 Common Commands
### View Logs
```cmd
REM All services
docker\scripts\docker-logs.bat
REM Specific service
docker\scripts\docker-logs.bat trading-api
docker\scripts\docker-logs.bat dashboard
docker\scripts\docker-logs.bat postgres
```
### Check Status
```cmd
docker-compose ps
```
### Restart Services
```cmd
REM Restart all
docker-compose restart
REM Restart specific
docker-compose restart trading-api
docker-compose restart dashboard
```
### Stop Services
```cmd
REM Stop (keeps data)
docker\scripts\docker-stop.bat
REM Stop and remove containers (keeps data)
docker\scripts\docker-stop.bat --remove
REM Stop and remove everything including data (⚠️ DANGER!)
docker\scripts\docker-stop.bat --clean
```
### Update Code and Rebuild
```cmd
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`:
```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:**
```cmd
curl http://localhost:8000/api/health
```
**View API logs:**
```cmd
docker\scripts\docker-logs.bat trading-api
```
### Port Already in Use
**Find what's using the port:**
```cmd
netstat -ano | findstr :3000
netstat -ano | findstr :8000
```
**Change port in .env:**
```env
DASHBOARD_PORT=3001
API_PORT=8001
```
**Restart services:**
```cmd
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:
```cmd
docker\scripts\docker-logs.bat trading-api
```
### Database Connection Issues
**Check database health:**
```cmd
docker-compose ps postgres
```
**Test connection:**
```cmd
docker exec -it trading_bot_db pg_isready -U trading_bot
```
**View database logs:**
```cmd
docker\scripts\docker-logs.bat postgres
```
## 📊 Monitoring
### View Real-time Logs
```cmd
REM Follow all logs
docker-compose logs -f
REM Follow specific service
docker-compose logs -f trading-api
```
### Check Resource Usage
```cmd
docker stats
```
### Service Health
```cmd
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)
├── .dockerignore # Files to exclude from build
├── docker/
│ ├── .env.docker.example # Environment template
│ ├── requirements-docker.txt # Docker-specific Python deps
│ ├── init-db/01-schema.sql # Database schema
│ ├── scripts/ # Helper scripts
│ │ ├── docker-start.bat/.sh
│ │ ├── docker-stop.bat/.sh
│ │ ├── docker-logs.bat/.sh
│ │ ├── docker-status.bat
│ │ ├── docker-add-dashboard.bat
│ │ ├── docker-remove-dashboard.bat
│ │ ├── start-all.bat
│ │ ├── start-api.bat
│ │ └── start-dashboard.bat
│ └── docs/ # Docker documentation
│ ├── DOCKER.md
│ ├── DOCKER-INTEGRATION.md
│ ├── DOCKER-SETUP-SUMMARY.md
│ ├── QUICK-START.md
│ └── SIMPLE-START.md
└── 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
- **Full Documentation:** [DOCKER.md](DOCKER.md)
- **Styling Guide:** [web-dashboard/STYLING-GUIDE.md](web-dashboard/STYLING-GUIDE.md)
- **Docker Docs:** https://docs.docker.com
- **Docker Compose:** https://docs.docker.com/compose
## 🆘 Support
If you encounter issues:
1. Check the logs: `docker\scripts\docker-logs.bat`
2. Verify services: `docker-compose ps`
3. Review troubleshooting section in [DOCKER.md](DOCKER.md)
4. Check service health: `curl http://localhost:8000/api/health`
---
**Setup completed:** Feb 6, 2026
**Ready to deploy!** 🚀
+437
View File
@@ -0,0 +1,437 @@
# XAUBot AI - Docker Setup Guide
Complete guide to running the XAUBot AI trading system with Docker.
## 📋 Prerequisites
- Docker Engine 20.10+
- Docker Compose 2.0+
- 4GB+ RAM available
- MetaTrader 5 account credentials
## 🏗️ Architecture
The Docker setup includes 4 services:
```
┌─────────────────────────────────────────────────┐
│ Host Machine │
├─────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Dashboard │─────▶│ Trading API │ │
│ │ Next.js │ │ FastAPI │ │
│ │ Port: 3000 │ │ Port: 8000 │ │
│ └──────────────┘ └──────┬───────┘ │
│ │ │
│ ┌──────▼───────┐ │
│ │ PostgreSQL │ │
│ │ Port: 5432 │ │
│ └──────────────┘ │
│ │
│ ┌──────────────┐ (Optional - Profile: admin) │
│ │ pgAdmin │ │
│ │ Port: 5050 │ │
│ └──────────────┘ │
└─────────────────────────────────────────────────┘
```
### Services
1. **postgres** - PostgreSQL 16 database for trade logging
2. **trading-api** - Python FastAPI backend serving trading data
3. **dashboard** - Next.js web interface for monitoring
4. **pgadmin** - Database management UI (optional, admin profile)
## 🚀 Quick Start
### 1. Clone & Setup
```bash
cd "Smart Automatic Trading BOT + AI"
# Copy environment template
cp docker/.env.docker.example .env
```
### 2. Configure Environment
Edit `.env` file with your credentials:
```bash
# Required
MT5_LOGIN=your_login
MT5_PASSWORD=your_password
MT5_SERVER=your_server
MT5_PATH=/path/to/mt5
# Optional - adjust ports if needed
API_PORT=8000
DASHBOARD_PORT=3000
DB_PORT=5432
```
### 3. Start Services
**Option A: All services (without pgAdmin)**
```bash
docker-compose up -d
```
**Option B: All services including pgAdmin**
```bash
docker-compose --profile admin up -d
```
**Option C: Specific services only**
```bash
# Just database and API
docker-compose up -d postgres trading-api
# Add dashboard
docker-compose up -d dashboard
```
### 4. Access Services
- **Dashboard**: http://localhost:3000
- **Trading API**: http://localhost:8000
- **API Docs**: http://localhost:8000/docs
- **pgAdmin**: http://localhost:5050 (if using admin profile)
- **PostgreSQL**: localhost:5432
## 📊 Service Management
### View Logs
```bash
# All services
docker-compose logs -f
# Specific service
docker-compose logs -f dashboard
docker-compose logs -f trading-api
docker-compose logs -f postgres
# Last 50 lines
docker-compose logs --tail=50 trading-api
```
### Check Status
```bash
# List running containers
docker-compose ps
# Check health
docker-compose ps --format json | jq '.[].Health'
# Detailed status
docker inspect trading_bot_api
```
### Restart Services
```bash
# Restart all
docker-compose restart
# Restart specific service
docker-compose restart trading-api
docker-compose restart dashboard
```
### Stop Services
```bash
# Stop all (keeps data)
docker-compose stop
# Stop and remove containers (keeps data)
docker-compose down
# Stop and remove everything including volumes (⚠️ deletes data!)
docker-compose down -v
```
## 🔧 Development & Debugging
### Access Container Shell
```bash
# Trading API container
docker exec -it trading_bot_api bash
# Dashboard container
docker exec -it trading_bot_dashboard sh
# Database
docker exec -it trading_bot_db psql -U trading_bot -d trading_db
```
### Rebuild After Code Changes
```bash
# Rebuild all
docker-compose build
# Rebuild specific service
docker-compose build trading-api
docker-compose build dashboard
# Rebuild and restart
docker-compose up -d --build
```
### View Resource Usage
```bash
# CPU, Memory, Network
docker stats
# Specific container
docker stats trading_bot_api
```
## 🗄️ Database Management
### Connect to PostgreSQL
```bash
# Via Docker
docker exec -it trading_bot_db psql -U trading_bot -d trading_db
# Via host (if port exposed)
psql -h localhost -p 5432 -U trading_bot -d trading_db
```
### Backup Database
```bash
# Create backup
docker exec trading_bot_db pg_dump -U trading_bot trading_db > backup_$(date +%Y%m%d).sql
# Restore backup
docker exec -i trading_bot_db psql -U trading_bot -d trading_db < backup_20260206.sql
```
### Using pgAdmin
1. Start with admin profile:
```bash
docker-compose --profile admin up -d
```
2. Open http://localhost:5050
3. Login:
- Email: admin@trading.local
- Password: admin123
4. Add Server:
- Host: postgres
- Port: 5432
- Database: trading_db
- Username: trading_bot
- Password: trading_bot_2026
## 🔍 Troubleshooting
### Container Won't Start
```bash
# Check logs
docker-compose logs trading-api
# Check events
docker events --filter container=trading_bot_api
# Inspect container
docker inspect trading_bot_api
```
### Port Already in Use
```bash
# 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
docker-compose down
docker-compose up -d
```
### API Can't Connect to MT5
1. Check MT5 credentials in `.env`
2. Ensure MT5 terminal is running (if running on host)
3. Check container logs:
```bash
docker-compose logs trading-api | grep MT5
```
### Dashboard Shows Connection Error
1. Check if API is healthy:
```bash
curl http://localhost:8000/api/health
```
2. Check API logs:
```bash
docker-compose logs trading-api
```
3. Verify API_URL in dashboard:
```bash
docker exec -it trading_bot_dashboard env | grep API
```
### Database Connection Issues
```bash
# Check if postgres is healthy
docker-compose ps postgres
# Test connection
docker exec -it trading_bot_db pg_isready -U trading_bot
# Check logs
docker-compose logs postgres
```
## 🔐 Security Best Practices
1. **Change Default Passwords**
```bash
# In .env
DB_PASSWORD=strong_password_here
PGADMIN_PASSWORD=another_strong_password
```
2. **Don't Expose Unnecessary Ports**
```yaml
# In docker-compose.yml, comment out if not needed:
# ports:
# - "5432:5432" # Only if you need external DB access
```
3. **Use Secrets for Production**
```bash
# Use Docker secrets instead of .env
docker secret create mt5_password password.txt
```
4. **Restrict Network Access**
```bash
# Only expose dashboard port
docker-compose up -d postgres trading-api
# Then separately: docker-compose up -d dashboard
```
## 📈 Performance Tuning
### Allocate More Resources
```yaml
# In docker-compose.yml
services:
trading-api:
deploy:
resources:
limits:
cpus: '2.0'
memory: 2G
reservations:
cpus: '1.0'
memory: 1G
```
### Optimize Database
```bash
# Connect to DB
docker exec -it trading_bot_db psql -U trading_bot -d trading_db
# Run vacuum
VACUUM ANALYZE;
# Check table sizes
SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
```
## 🔄 Updates & Maintenance
### Update Images
```bash
# Pull latest base images
docker-compose pull
# Rebuild
docker-compose build --no-cache
# Restart
docker-compose up -d
```
### Clean Up
```bash
# Remove unused images
docker image prune -a
# Remove unused volumes (⚠️ careful!)
docker volume prune
# Remove everything unused
docker system prune -a --volumes
```
## 📝 Environment Variables Reference
| Variable | Default | Description |
|----------|---------|-------------|
| `MT5_LOGIN` | - | MT5 account login |
| `MT5_PASSWORD` | - | MT5 account password |
| `MT5_SERVER` | - | MT5 server name |
| `MT5_PATH` | - | Path to MT5 terminal |
| `SYMBOL` | XAUUSD | Trading symbol |
| `CAPITAL` | 10000 | Trading capital |
| `API_PORT` | 8000 | API port on host |
| `DASHBOARD_PORT` | 3000 | Dashboard port on host |
| `DB_PORT` | 5432 | Database port on host |
| `DB_USER` | trading_bot | Database username |
| `DB_PASSWORD` | trading_bot_2026 | Database password |
| `DB_NAME` | trading_db | Database name |
| `TELEGRAM_BOT_TOKEN` | - | Telegram bot token (optional) |
| `TELEGRAM_CHAT_ID` | - | Telegram chat ID (optional) |
## 📚 Additional Resources
- **Docker Docs**: https://docs.docker.com
- **Docker Compose**: https://docs.docker.com/compose
- **FastAPI**: https://fastapi.tiangolo.com
- **Next.js**: https://nextjs.org
## 🆘 Getting Help
If you encounter issues:
1. Check logs: `docker-compose logs -f`
2. Verify services: `docker-compose ps`
3. Check health: `curl http://localhost:8000/api/health`
4. Review this guide's troubleshooting section
5. Open an issue on GitHub
---
**Last Updated:** Feb 6, 2026
+161
View File
@@ -0,0 +1,161 @@
# Quick Start - Tambah Dashboard ke Docker Existing
## Status Saat Ini
**Docker Compose sudah ada**
**Service `postgres` sudah running** (container: `trading_bot_db`)
**Service `trading-api` dan `dashboard` sudah didefinisikan** tapi belum di-build
## 🚀 Cara Menjalankan
### 1. Setup Environment (Kalau Belum)
```cmd
cd "C:\Users\Administrator\Videos\Smart Automatic Trading BOT + AI"
REM Copy environment template kalau belum ada
copy docker\.env.docker.example .env
REM Edit dengan MT5 credentials Anda
notepad .env
```
Pastikan isi `.env`:
```env
MT5_LOGIN=your_login
MT5_PASSWORD=your_password
MT5_SERVER=your_server
MT5_PATH=C:/Program Files/MetaTrader 5/terminal64.exe
SYMBOL=XAUUSD
CAPITAL=10000
```
### 2. Build Services Baru
```cmd
REM Build trading-api dan dashboard
docker-compose build trading-api dashboard
```
Ini akan:
- Build Dockerfile untuk Python API
- Build Dockerfile untuk Next.js Dashboard
- Tidak ganggu database yang sudah running
### 3. Start Services Baru
```cmd
REM Start trading-api dan dashboard
docker-compose up -d trading-api dashboard
```
### 4. Check Status
```cmd
docker-compose ps
```
Output akan menunjukkan:
```
NAME STATUS PORTS
trading_bot_db Up (healthy) 0.0.0.0:5432->5432/tcp
trading_bot_api Up (healthy) 0.0.0.0:8000->8000/tcp
trading_bot_dashboard Up (healthy) 0.0.0.0:3000->3000/tcp
```
### 5. Akses Dashboard
Buka browser:
- **Dashboard:** http://localhost:3000
- **API:** http://localhost:8000
- **API Docs:** http://localhost:8000/docs
## 📋 Commands Penting
```cmd
# Lihat logs
docker-compose logs -f dashboard
docker-compose logs -f trading-api
# Restart service
docker-compose restart trading-api
docker-compose restart dashboard
# Stop service
docker-compose stop trading-api dashboard
# Start lagi
docker-compose up -d trading-api dashboard
# Rebuild setelah update code
docker-compose build trading-api dashboard
docker-compose up -d trading-api dashboard
```
## 🔍 Troubleshooting
### Build Error
```cmd
# Clean build
docker-compose build --no-cache trading-api dashboard
```
### Service Tidak Start
```cmd
# Check logs
docker-compose logs trading-api
docker-compose logs dashboard
# Check health
curl http://localhost:8000/api/health
curl http://localhost:3000
```
### Port Conflict
Edit `.env`:
```env
API_PORT=8001
DASHBOARD_PORT=3001
```
Lalu restart:
```cmd
docker-compose down trading-api dashboard
docker-compose up -d trading-api dashboard
```
## ⚡ One-Liner (All in One)
```cmd
cd "C:\Users\Administrator\Videos\Smart Automatic Trading BOT + AI" && docker-compose build trading-api dashboard && docker-compose up -d trading-api dashboard && docker-compose ps
```
## 📊 Arsitektur
```
Docker Compose Project: "smart-automatic-trading-bot-ai"
├── postgres (RUNNING) ✅
│ └── trading_bot_db
├── trading-api (BUILD & START) ⚡
│ └── trading_bot_api
└── dashboard (BUILD & START) ⚡
└── trading_bot_dashboard
```
## ✅ Checklist
- [ ] Copy `docker/.env.docker.example` ke `.env`
- [ ] Edit `.env` dengan MT5 credentials
- [ ] Run: `docker-compose build trading-api dashboard`
- [ ] Run: `docker-compose up -d trading-api dashboard`
- [ ] Check: `docker-compose ps`
- [ ] Open: http://localhost:3000
- [ ] Test API: http://localhost:8000/api/health
---
**That's it!** Simple kan? 🎉
+170
View File
@@ -0,0 +1,170 @@
# Simple Start Guide - XAUBot AI Dashboard
## 🎯 Cara Tercepat (1 Command)
```cmd
docker\scripts\start-all.bat
```
Script ini akan:
1. ✅ Check database Docker container
2. 🚀 Start Trading API di http://localhost:8000
3. 🚀 Start Dashboard di http://localhost:3000
Dua window akan terbuka otomatis!
## 📋 Manual Start (Jika Perlu)
### Option 1: Start Semua Sekaligus
```cmd
docker\scripts\start-all.bat
```
### Option 2: Start Satu-satu
**Terminal 1: API**
```cmd
docker\scripts\start-api.bat
```
**Terminal 2: Dashboard**
```cmd
docker\scripts\start-dashboard.bat
```
## ✅ Pre-requisites
### 1. Database (Docker)
Database harus sudah running:
```cmd
# Check status
docker ps | findstr trading_bot_db
# Start jika belum running
docker-compose up -d postgres
```
### 2. Python Environment
- Python 3.11+ installed
- Virtual environment akan dibuat otomatis
### 3. Node.js
- Node.js 18+ installed
- npm dependencies akan diinstall otomatis
## 🌐 Access Points
Setelah start:
- **Dashboard:** http://localhost:3000
- **API:** http://localhost:8000
- **API Docs:** http://localhost:8000/docs
- **Health Check:** http://localhost:8000/api/health
- **Status:** http://localhost:8000/api/status
## 🛑 Stop Services
Close kedua command windows atau tekan `Ctrl+C` di masing-masing window.
## 🔍 Troubleshooting
### API Error: "Module not found"
Install dependencies:
```cmd
pip install -r requirements.txt
```
### Dashboard Error: "Module not found"
Install dependencies:
```cmd
cd web-dashboard
npm install
```
### Port Already in Use
**Change API Port:**
Edit `web-dashboard/api/main.py` line terakhir:
```python
uvicorn.run(app, host="0.0.0.0", port=8001) # Change 8000 to 8001
```
**Change Dashboard Port:**
Edit `web-dashboard/.env.local`:
```
NEXT_PUBLIC_API_URL=http://localhost:8001
```
Then start dashboard on different port:
```cmd
cd web-dashboard
set PORT=3001 && npm run dev
```
### Database Not Running
Start database:
```cmd
docker-compose up -d postgres
# Check status
docker ps
```
## 📊 Architecture
```
┌─────────────────────────────────────┐
│ Windows Host Machine │
├─────────────────────────────────────┤
│ │
│ 📊 Dashboard (Port 3000) │
│ npm run dev │
│ ↓ HTTP │
│ 🔌 API (Port 8000) │
│ uvicorn main:app │
│ ↓ PostgreSQL │
│ 🗄️ Database (Docker) │
│ trading_bot_db │
│ │
└─────────────────────────────────────┘
```
## 🎨 Features
Dashboard akan menampilkan:
- ⏰ Real-time XAUUSD price
- 💰 Account balance & equity
- 📈 Price history chart
- 🎯 Trading signals (SMC + ML)
- 🌊 Market regime
- ⚠️ Risk status
- 📋 Open positions
- 📝 Activity logs
## 💡 Tips
1. **Auto-start Database:**
Tambahkan Docker Desktop ke Windows startup
2. **Keep API Running:**
Minimize command windows, jangan close
3. **Monitor Logs:**
Lihat output di command windows untuk debug
4. **Quick Restart:**
Close windows dan run `docker\scripts\start-all.bat` lagi
## 📝 Files
```
docker\scripts\start-all.bat # Start API + Dashboard
docker\scripts\start-api.bat # Start API only
docker\scripts\start-dashboard.bat # Start Dashboard only
```
---
**Super Simple!** Tinggal double-click `docker\scripts\start-all.bat` 🎉