Autonomous trading bot deployment options.
Best for: Cross-platform deployment, easy updates, isolated environment
# 1. Build and run once
./run_docker.sh build
./run_docker.sh once
# 2. Start with daily scheduler (9:35 AM ET)
./run_docker.sh schedule
# 3. View logs
./run_docker.sh logs
# 4. Stop scheduler
./run_docker.sh stop# Start scheduler (runs daily at 9:35 AM ET)
docker compose up -d
# View logs
docker compose logs -f
# Stop scheduler
docker compose down
# Rebuild after code changes
docker compose build- ✅ Cross-platform (Linux, macOS, Windows)
- ✅ Isolated environment (no conflicts)
- ✅ Easy updates (rebuild image)
- ✅ Resource limits (CPU, memory)
- ✅ Automatic restarts on failure
Best for: Linux servers, system-level integration, native performance
# 1. Install service and timer
cd /home/tristan/Repos/TradeAgent
sudo ./deployment/install_systemd.sh
# 2. Verify installation
sudo systemctl status tradeagent.timer# View timer status
sudo systemctl status tradeagent.timer
# View next scheduled run
systemctl list-timers tradeagent.timer
# View logs
sudo journalctl -u tradeagent -f
# Run immediately
sudo systemctl start tradeagent.service
# Stop timer
sudo systemctl stop tradeagent.timer
# Disable timer
sudo systemctl disable tradeagent.timer- ✅ Native Linux integration
- ✅ System-level logging (journalctl)
- ✅ Automatic start on boot
- ✅ Better performance (no containerization overhead)
- ✅ Integrates with system monitoring
Best for: Quick setup, minimal dependencies
# 1. Open crontab
crontab -e
# 2. Add this line (runs at 9:35 AM ET on weekdays)
35 9 * * 1-5 cd /home/tristan/Repos/TradeAgent && /home/tristan/Repos/TradeAgent/venv_linux/bin/python -m src.main >> /home/tristan/Repos/TradeAgent/logs/cron.log 2>&1# View crontab
crontab -l
# View logs
tail -f /home/tristan/Repos/TradeAgent/logs/cron.log
# Remove cron job
crontab -e # Delete the line- ✅ Simplest setup
- ✅ No additional dependencies
- ✅ Works everywhere
- ❌ No automatic restarts
- ❌ Basic logging only
| Feature | Docker | SystemD | Cron |
|---|---|---|---|
| Ease of Setup | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| Cross-Platform | ✅ Yes | ❌ Linux only | ✅ Yes |
| Auto Restart | ✅ Yes | ✅ Yes | ❌ No |
| Resource Limits | ✅ Yes | ✅ Yes | ❌ No |
| Logging | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐ |
| Updates | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ |
| Performance | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
Recommendation:
- Development: Docker (easy testing, isolated)
- Production Linux: SystemD (native, reliable)
- Quick Testing: Cron (fastest setup)
Problem: Container exits immediately
# Check logs
docker compose logs tradeagent
# Run interactively
docker compose run --rm tradeagent bashProblem: Permission denied
# Fix permissions
sudo chown -R $USER:$USER .Problem: Service fails to start
# Check status
sudo systemctl status tradeagent.service
# View detailed logs
sudo journalctl -u tradeagent -n 100 --no-pagerProblem: Timer not running
# Verify timer is enabled
systemctl is-enabled tradeagent.timer
# Check next run time
systemctl list-timers tradeagent.timerProblem: Missing API keys
# Check .env file exists
cat .env
# Verify all required keys are set
grep -E "ALPACA|SUPABASE|OPENROUTER" .envProblem: Python dependencies
# Reinstall dependencies
pip install -r requirements.txt
# Or rebuild Docker image
docker compose build --no-cache# Container stats
docker stats tradeagent-bot
# Health check
docker inspect tradeagent-bot | grep Health
# Follow logs
docker compose logs -f --tail=100# Service status
sudo systemctl status tradeagent
# Recent logs
sudo journalctl -u tradeagent -n 50
# Follow logs live
sudo journalctl -u tradeagent -f# View cron log
tail -f logs/cron.log
# Check if cron is running
ps aux | grep cronBefore deploying to production:
- Set all environment variables in
.env - Test bot manually:
python -m src.main - Verify Supabase connection
- Verify Alpaca API works (paper trading)
- Check logs directory is writable
- Set correct timezone (ET for market hours)
- Configure resource limits (memory, CPU)
- Setup monitoring/alerts
- Test scheduler (run once before enabling daily)
- Backup
.envfile securely
# 1. Pull latest code
git pull origin main
# 2. Rebuild image
docker compose build
# 3. Restart containers
docker compose down && docker compose up -d# 1. Pull latest code
git pull origin main
# 2. Restart service (if running)
sudo systemctl restart tradeagent.timer
# No rebuild needed!# 1. Pull latest code
git pull origin main
# No restart needed - runs at next scheduled time- Never commit
.env→ Contains API keys - Use paper trading first → Test with fake money
- Limit API permissions → Read-only for market data
- Monitor resource usage → Prevent runaway processes
- Backup database → Export Supabase data regularly
- Review logs daily → Check for errors/anomalies
Last Updated: 2025-12-05