#!/bin/bash # ═══════════════════════════════════════════════════════════════════════════════ # GENESIS Docker Entrypoint # Validates credentials → sets up cron → starts autonomous engine # ═══════════════════════════════════════════════════════════════════════════════ set -e PYTHON="/opt/hermes-agent/.venv-hermes/bin/python3" AGENT="/opt/hermes-agent" echo "" echo " ██████ ███████ ███ ██ ███████ ███████ ██ ███████" echo " ██ ██ ████ ██ ██ ██ ██ ██" echo " ██ ███ █████ ██ ██ ██ █████ ███████ ██ ███████" echo " ██ ██ ██ ██ ██ ██ ██ ██ ██ ██" echo " ██████ ███████ ██ ████ ███████ ███████ ██ ███████" echo "" echo " Autonomous MT5 Trading System — Docker Mode" echo " Powered by Mt5Bridge" echo "─────────────────────────────────────────────────────" # ── Load .env ───────────────────────────────────────────────────────────────── if [ -f /opt/hermes-agent/.env ]; then cp /opt/hermes-agent/.env /tmp/.env.fixed sed -i 's/\r$//' /tmp/.env.fixed set -a source /tmp/.env.fixed set +a else echo "" echo " ╔═══════════════════════════════════════════════════╗" echo " ║ NO .env FILE FOUND ║" echo " ║ ║" echo " ║ Mount your credentials file: ║" echo " ║ docker run -v \$(pwd)/.env:/opt/hermes-agent/.env ║" echo " ║ ║" echo " ║ Or generate it first: ║" echo " ║ bash setup.sh ║" echo " ╚═══════════════════════════════════════════════════╝" echo "" exit 1 fi # ── Validate required credentials ───────────────────────────────────────────── echo "" MISSING=0 PLACEHOLDER_PATTERN="YOUR_|CHANGE_ME|example|placeholder|sk-your" check_var() { local var_name="$1" local var_val="${!var_name}" if [ -z "$var_val" ] || echo "$var_val" | grep -qiE "$PLACEHOLDER_PATTERN"; then echo " ✗ $var_name — not configured" MISSING=$((MISSING + 1)) else local masked="${var_val:0:8}••••" echo " ✓ $var_name = $masked" fi } echo " Credential check:" check_var MT5_BRIDGE_URL check_var MT5_BRIDGE_KEY check_var OPENAI_API_KEY check_var TELEGRAM_BOT_TOKEN check_var TELEGRAM_CHAT_ID if [ "$MISSING" -gt 0 ]; then echo "" echo " ╔═══════════════════════════════════════════════════════╗" echo " ║ $MISSING required credential(s) missing. ║" echo " ║ ║" echo " ║ Edit your .env file and restart: ║" echo " ║ docker compose restart ║" echo " ╚═══════════════════════════════════════════════════════╝" echo "" exit 1 fi # ── Verify Mt5Bridge connectivity ───────────────────────────────────────────── echo "" echo " Verifying Mt5Bridge connection..." BRIDGE_URL="${MT5_BRIDGE_URL:-http://localhost:13485}" BRIDGE_KEY="${MT5_BRIDGE_KEY:-}" ACCT_JSON=$(curl -s \ -H "X-API-Key: $BRIDGE_KEY" \ "$BRIDGE_URL/account" \ --max-time 10 2>/dev/null || echo '{}') BALANCE=$(echo "$ACCT_JSON" | $PYTHON -c " import sys, json try: d = json.load(sys.stdin) items = d.get('data', []) if items and len(items) > 0: a = items[0] b = a.get('balance', 0) c = a.get('currency', 'USD') print(f' ✓ Connected | Balance: {b:,.2f} {c}') elif d.get('balance') is not None: b = d.get('balance', 0) c = d.get('currency', 'USD') print(f' ✓ Connected | Balance: {b:,.2f} {c}') else: err = d.get('message', d.get('error', 'no data')) if err: print(f' ✗ API error: {err}') else: print(' ✗ No account data returned') except Exception as e: print(' ✗ Could not parse API response') " 2>/dev/null || echo " ✗ Connection failed") echo "$BALANCE" if echo "$BALANCE" | grep -q "✗"; then echo "" echo " WARNING: Mt5Bridge connection failed." echo " Check MT5_BRIDGE_URL and MT5_BRIDGE_KEY in .env" echo " Starting anyway — strategies will retry each cycle." echo "" fi # ── Export env for cron ──────────────────────────────────────────────────────── printenv | grep -E "^(MT5_|TELEGRAM_|OPENAI_|HERMES_|TWELVE_|FRED_|MAX_|SYMBOL_|HTTPS_PROXY)" > /etc/environment # ── Install cron jobs ────────────────────────────────────────────────────────── echo "" echo " Installing cron jobs..." cat > /etc/cron.d/genesis << CRONEOF SHELL=/bin/bash PATH=/opt/hermes-agent/.venv-hermes/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin BASH_ENV=/etc/environment # GENESIS autonomous strategy scan — every 5 minutes */5 * * * * root cd $AGENT && $PYTHON $AGENT/core/genesis_autonomous.py >> /var/log/hermes/autonomous.log 2>&1 # Hermes LLM macro cycle — every hour 0 * * * * root cd $AGENT && $PYTHON $AGENT/core/trading_cycle.py >> /var/log/hermes/trading_cycle.log 2>&1 # Brain feed Telegram report — every hour at :30 30 * * * * root cd $AGENT && $PYTHON $AGENT/core/genesis_brain_feed.py >> /var/log/hermes/autonomous.log 2>&1 # Market open alert — weekdays 07:00 UTC 0 7 * * 1-5 root cd $AGENT && $PYTHON $AGENT/core/genesis_market_open.py >> /var/log/hermes/autonomous.log 2>&1 # Daily P&L report — 06:00 UTC 0 6 * * * root cd $AGENT && $PYTHON $AGENT/core/genesis_daily_report.py >> /var/log/hermes/autonomous.log 2>&1 # Heartbeat — every 10 minutes */10 * * * * root cd $AGENT && $PYTHON $AGENT/core/heartbeat.py >> /var/log/hermes/autonomous.log 2>&1 CRONEOF chmod 644 /etc/cron.d/genesis echo " ✓ 6 cron jobs installed" # ── Start Telegram Bots ────────────────────────────────────────────────────── echo "" echo " Starting Telegram bots..." for bot in ares apollo athena zeus; do BOT_SCRIPT="$AGENT/strategies/${bot}/${bot}_telegram_bot.py" if [ -f "$BOT_SCRIPT" ]; then nohup $PYTHON "$BOT_SCRIPT" >> /var/log/hermes/${bot}_bot.log 2>&1 & elif [ "$bot" = "zeus" ] && [ -f "$AGENT/strategies/zeus/zeus_tool.py" ]; then nohup $PYTHON "$AGENT/strategies/zeus/zeus_tool.py" bot >> /var/log/hermes/zeus_bot.log 2>&1 & else echo " ✗ ${bot}_telegram_bot not found" continue fi echo " ✓ ${bot}_telegram_bot started (PID $!)" done # ── Ready ───────────────────────────────────────────────────────────────────── echo "" echo "─────────────────────────────────────────────────────" echo " ✓ GENESIS is running" echo "" echo " Telegram commands:" echo " /ares_help /apollo_help /athena_help" echo "" echo " CLI commands:" echo " docker exec -it genesis ares analyze EURUSD" echo " docker exec -it genesis zeus analyze GBPUSD" echo " docker exec -it genesis genesis-scan EURUSD" echo " docker exec -it genesis tail -f /var/log/hermes/autonomous.log" echo "─────────────────────────────────────────────────────" echo "" # ── Start cron + tail logs ──────────────────────────────────────────────────── service cron start touch /var/log/hermes/autonomous.log /var/log/hermes/trading_cycle.log tail -f /var/log/hermes/autonomous.log /var/log/hermes/trading_cycle.log