This guide covers various deployment options for ForexSmartBot, from local development to production environments.
- Local Development
- VPS Deployment
- Docker Deployment
- Cloud Deployment
- Production Considerations
- Monitoring & Maintenance
- Security
- Backup & Recovery
- Python 3.11 or higher
- 4 GB RAM (8 GB recommended)
- 1 GB free disk space
- Git
-
Clone repository:
git clone https://github.com/voxhash/ForexSmartBot.git cd ForexSmartBot -
Create virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt pip install -r requirements-dev.txt
-
Run application:
python app.py
- Hot Reload: Automatic reload on code changes
- Debug Mode: Enhanced error reporting
- Test Mode: Isolated testing environment
- Logging: Detailed development logs
- VPS with Ubuntu 20.04+ or CentOS 8+
- 2 GB RAM minimum (4 GB recommended)
- 10 GB free disk space
- Root or sudo access
- Static IP address
-
Update system:
sudo apt update && sudo apt upgrade -y -
Install Python 3.11:
sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt install python3.11 python3.11-venv python3.11-dev
-
Install system dependencies:
sudo apt install build-essential libssl-dev libffi-dev sudo apt install python3-pip git curl wget
-
Create user:
sudo adduser forexsmartbot sudo usermod -aG sudo forexsmartbot
-
Switch to user:
sudo su - forexsmartbot
-
Clone repository:
git clone https://github.com/voxhash/ForexSmartBot.git cd ForexSmartBot -
Create virtual environment:
python3.11 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Create data directory:
mkdir -p ~/.forexsmartbot chmod 755 ~/.forexsmartbot
-
Create systemd service:
sudo nano /etc/systemd/system/forexsmartbot.service
-
Service file content:
[Unit] Description=ForexSmartBot Trading Bot After=network.target [Service] Type=simple User=forexsmartbot WorkingDirectory=/home/forexsmartbot/ForexSmartBot Environment=PATH=/home/forexsmartbot/ForexSmartBot/venv/bin ExecStart=/home/forexsmartbot/ForexSmartBot/venv/bin/python app.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
-
Enable and start service:
sudo systemctl daemon-reload sudo systemctl enable forexsmartbot sudo systemctl start forexsmartbot -
Check status:
sudo systemctl status forexsmartbot
-
Install X11 forwarding:
sudo apt install xvfb
-
Create display script:
nano ~/start_forexsmartbot.sh -
Script content:
#!/bin/bash export DISPLAY=:99 Xvfb :99 -screen 0 1024x768x24 & source ~/ForexSmartBot/venv/bin/activate cd ~/ForexSmartBot python app.py
-
Make executable:
chmod +x ~/start_forexsmartbot.sh
- Docker 20.10+
- Docker Compose 2.0+
- 4 GB RAM
- 10 GB free disk space
Create Dockerfile:
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
libffi-dev \
libx11-6 \
libxext6 \
libxrender1 \
libxtst6 \
libxi6 \
libxrandr2 \
libxss1 \
libgconf-2-4 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxfixes3 \
libxinerama1 \
libxrandr2 \
libxss1 \
libxtst6 \
libasound2 \
libatk-bridge2.0-0 \
libdrm2 \
libgtk-3-0 \
libgbm1 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create data directory
RUN mkdir -p /app/data
# Set environment variables
ENV PYTHONPATH=/app
ENV DISPLAY=:99
# Expose port (if needed)
EXPOSE 8080
# Create non-root user
RUN useradd -m -u 1000 forexsmartbot
RUN chown -R forexsmartbot:forexsmartbot /app
USER forexsmartbot
# Start command
CMD ["python", "app.py"]Create docker-compose.yml:
version: '3.8'
services:
forexsmartbot:
build: .
container_name: forexsmartbot
restart: unless-stopped
volumes:
- ./data:/app/data
- ~/.forexsmartbot:/home/forexsmartbot/.forexsmartbot
environment:
- PYTHONPATH=/app
- DISPLAY=:99
ports:
- "8080:8080"
depends_on:
- xvfb
networks:
- forexsmartbot-network
xvfb:
image: selenium/standalone-chrome:latest
container_name: forexsmartbot-xvfb
restart: unless-stopped
environment:
- DISPLAY=:99
ports:
- "4444:4444"
networks:
- forexsmartbot-network
networks:
forexsmartbot-network:
driver: bridge
volumes:
forexsmartbot-data:
driver: local-
Build image:
docker build -t forexsmartbot . -
Run with Docker Compose:
docker-compose up -d
-
Check logs:
docker-compose logs -f forexsmartbot
-
Stop services:
docker-compose down
-
Launch EC2 instance:
- Instance type: t3.medium or larger
- OS: Ubuntu 20.04 LTS
- Storage: 20 GB GP3
- Security group: Allow SSH (22) and HTTP (80/443)
-
Connect to instance:
ssh -i your-key.pem ubuntu@your-instance-ip
-
Follow VPS deployment steps
-
Configure load balancer (if needed):
- Create Application Load Balancer
- Configure target groups
- Set up health checks
-
Create Compute Engine instance:
- Machine type: e2-medium or larger
- OS: Ubuntu 20.04 LTS
- Boot disk: 20 GB SSD
-
Connect to instance:
gcloud compute ssh your-instance-name --zone=your-zone
-
Follow VPS deployment steps
-
Create Virtual Machine:
- Size: Standard_B2s or larger
- OS: Ubuntu 20.04 LTS
- Disk: 20 GB SSD
-
Connect to instance:
ssh azureuser@your-instance-ip
-
Follow VPS deployment steps
-
Create Droplet:
- Size: 2 GB RAM or larger
- OS: Ubuntu 20.04 LTS
- Storage: 20 GB SSD
-
Connect to instance:
ssh root@your-droplet-ip
-
Follow VPS deployment steps
-
Resource allocation:
- CPU: 2+ cores recommended
- RAM: 4+ GB recommended
- Storage: SSD recommended
- Network: Stable connection
-
Application optimization:
- Use production Python interpreter
- Enable JIT compilation
- Optimize data processing
- Cache frequently used data
-
Database optimization:
- Use connection pooling
- Optimize queries
- Regular maintenance
- Backup strategies
-
Horizontal scaling:
- Load balancer
- Multiple instances
- Shared storage
- Session management
-
Vertical scaling:
- Increase resources
- Optimize code
- Better algorithms
- Caching strategies
-
Redundancy:
- Multiple instances
- Load balancer
- Database replication
- Backup systems
-
Monitoring:
- Health checks
- Performance metrics
- Error tracking
- Alerting
-
Configure logging:
import logging from logging.handlers import RotatingFileHandler # Create logger logger = logging.getLogger('forexsmartbot') logger.setLevel(logging.INFO) # Create file handler handler = RotatingFileHandler( 'logs/forexsmartbot.log', maxBytes=10*1024*1024, # 10MB backupCount=5 ) # Create formatter formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) handler.setFormatter(formatter) # Add handler to logger logger.addHandler(handler)
-
Log rotation:
# Configure logrotate sudo nano /etc/logrotate.d/forexsmartbot -
Log content:
/home/forexsmartbot/ForexSmartBot/logs/*.log { daily missingok rotate 30 compress delaycompress notifempty create 644 forexsmartbot forexsmartbot }
-
System monitoring:
# Install monitoring tools sudo apt install htop iotop nethogs -
Application monitoring:
import psutil import time def monitor_system(): while True: # CPU usage cpu_percent = psutil.cpu_percent() # Memory usage memory = psutil.virtual_memory() memory_percent = memory.percent # Disk usage disk = psutil.disk_usage('/') disk_percent = disk.percent # Log metrics logger.info(f"CPU: {cpu_percent}%, Memory: {memory_percent}%, Disk: {disk_percent}%") time.sleep(60) # Check every minute
-
Health checks:
def health_check(): try: # Check database connection # Check broker connection # Check data provider # Check risk engine return True except Exception as e: logger.error(f"Health check failed: {e}") return False
-
Regular updates:
# Update system sudo apt update && sudo apt upgrade -y # Update application cd ~/ForexSmartBot git pull origin main source venv/bin/activate pip install -r requirements.txt
-
Database maintenance:
# SQLite maintenance sqlite3 ~/.forexsmartbot/trades.db "VACUUM;" sqlite3 ~/.forexsmartbot/trades.db "ANALYZE;"
-
Log cleanup:
# Clean old logs find ~/.forexsmartbot/logs -name "*.log" -mtime +30 -delete
-
SSH security:
# Disable root login sudo nano /etc/ssh/sshd_config # Set: PermitRootLogin no # Use key-based authentication # Set: PasswordAuthentication no # Restart SSH sudo systemctl restart ssh
-
Firewall configuration:
# Install UFW sudo apt install ufw # Configure firewall sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow ssh sudo ufw allow 80 sudo ufw allow 443 sudo ufw enable
-
User permissions:
# Create dedicated user sudo adduser forexsmartbot sudo usermod -aG sudo forexsmartbot # Set proper permissions sudo chown -R forexsmartbot:forexsmartbot /home/forexsmartbot/ForexSmartBot sudo chmod -R 755 /home/forexsmartbot/ForexSmartBot
-
Encryption:
# Encrypt sensitive data sudo apt install ecryptfs-utils sudo ecryptfs-setup-private -
Backup encryption:
# Encrypt backups tar -czf - ~/.forexsmartbot | gpg --symmetric --cipher-algo AES256 -o backup.tar.gz.gpg
-
API key protection:
# Store API keys in environment variables echo 'export FOREXSMARTBOT_API_KEY="your_api_key"' >> ~/.bashrc source ~/.bashrc
-
VPN setup:
# Install OpenVPN sudo apt install openvpn # Configure VPN client sudo openvpn --config client.ovpn
-
SSL/TLS:
# Install Let's Encrypt sudo apt install certbot # Generate certificate sudo certbot certonly --standalone -d your-domain.com
-
Application backup:
# Create backup script nano ~/backup_forexsmartbot.sh
-
Backup script content:
#!/bin/bash BACKUP_DIR="/backup/forexsmartbot" DATE=$(date +%Y%m%d_%H%M%S) # Create backup directory mkdir -p $BACKUP_DIR # Backup application tar -czf $BACKUP_DIR/forexsmartbot_$DATE.tar.gz ~/ForexSmartBot # Backup data tar -czf $BACKUP_DIR/data_$DATE.tar.gz ~/.forexsmartbot # Backup database cp ~/.forexsmartbot/trades.db $BACKUP_DIR/trades_$DATE.db # Clean old backups (keep 30 days) find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete find $BACKUP_DIR -name "*.db" -mtime +30 -delete
-
Make executable:
chmod +x ~/backup_forexsmartbot.sh -
Schedule backup:
# Add to crontab crontab -e # Add: 0 2 * * * /home/forexsmartbot/backup_forexsmartbot.sh
-
Application recovery:
# Stop service sudo systemctl stop forexsmartbot # Restore application tar -xzf /backup/forexsmartbot/forexsmartbot_YYYYMMDD_HHMMSS.tar.gz -C ~/ # Restore data tar -xzf /backup/forexsmartbot/data_YYYYMMDD_HHMMSS.tar.gz -C ~/ # Start service sudo systemctl start forexsmartbot
-
Database recovery:
# Stop service sudo systemctl stop forexsmartbot # Restore database cp /backup/forexsmartbot/trades_YYYYMMDD_HHMMSS.db ~/.forexsmartbot/trades.db # Start service sudo systemctl start forexsmartbot
-
Complete system recovery:
- Provision new server
- Install operating system
- Install dependencies
- Restore application
- Restore data
- Configure services
- Test functionality
-
Partial recovery:
- Identify affected components
- Restore specific components
- Verify functionality
- Update configurations
-
Service won't start:
# Check logs sudo journalctl -u forexsmartbot -f # Check permissions ls -la ~/ForexSmartBot # Check dependencies source ~/ForexSmartBot/venv/bin/activate pip list
-
Memory issues:
# Check memory usage free -h htop # Check swap swapon -s
-
Disk space issues:
# Check disk usage df -h du -sh ~/.forexsmartbot # Clean up logs find ~/.forexsmartbot/logs -name "*.log" -mtime +7 -delete
-
Slow performance:
- Check CPU usage
- Check memory usage
- Check disk I/O
- Check network latency
-
High memory usage:
- Check for memory leaks
- Optimize data processing
- Use appropriate data types
- Clear unused variables
-
Database issues:
- Check database size
- Optimize queries
- Rebuild indexes
- Vacuum database
- Documentation: Check comprehensive documentation
- Logs: Review application and system logs
- Community: Ask questions in GitHub discussions
- Issues: Report bugs on GitHub issues
- System monitoring: htop, iotop, nethogs
- Application monitoring: Custom logging and metrics
- Database monitoring: SQLite-specific tools
- Network monitoring: netstat, ss, tcpdump
Note: This deployment guide provides general instructions. Always adapt the steps to your specific environment and requirements. Test thoroughly in a non-production environment before deploying to production.