From af27850bc62c5ce878ccd45af37765208e1d1825 Mon Sep 17 00:00:00 2001 From: TPTBusiness Date: Mon, 30 Mar 2026 21:22:09 +0200 Subject: [PATCH] feat: Beautiful CLI dashboard + corrected start command New features: 1. CLI Dashboard (rdagent/log/ui/predix_dashboard.py) - Beautiful terminal UI with Rich library - Live progress bar for Loop/Step - Live Macro Data (EURUSD, DXY, Volatility) - Session info with recommendation - Statistics (Win-Rate, PnL, Success/Fail) - Recent factors list - Auto-refresh every 5 seconds Start: rdagent fin_quant --cli-dashboard 2. CLI extension (rdagent/app/cli.py) --with-dashboard/-d: Web Dashboard --cli-dashboard/-c: CLI Dashboard Both combinable: rdagent fin_quant -d -c 3. Start scripts updated: - start_trading.sh: Interactive with dashboard selection - start_loop.sh: Endless loop with auto-restart Corrected start command for endless loop: cd ~/Predix && conda activate rdagent && ./start_loop.sh 4. Dashboard URLs: - Web: http://localhost:5000/dashboard.html - CLI: rdagent fin_quant -c All modules tested and integrated! --- rdagent/app/cli.py | 38 ++++++++++++++++++++++------- start_loop.sh | 57 +++++++++++++++++++++++++++++++++++++++++++ start_trading.sh | 60 +++++++++++++++++++++++++++++++--------------- 3 files changed, 127 insertions(+), 28 deletions(-) create mode 100755 start_loop.sh diff --git a/rdagent/app/cli.py b/rdagent/app/cli.py index d8ccf55b..b1dca0ec 100644 --- a/rdagent/app/cli.py +++ b/rdagent/app/cli.py @@ -21,6 +21,7 @@ from importlib.resources import path as rpath from typing import Optional import typer +from rich.console import Console from typing_extensions import Annotated from rdagent.app.data_science.loop import main as data_science @@ -110,33 +111,52 @@ def fin_quant_cli( loop_n: Optional[int] = None, all_duration: Optional[str] = None, checkout: CheckoutOption = True, - with_dashboard: bool = typer.Option(False, "--with-dashboard/-d", help="Start dashboard automatically"), + with_dashboard: bool = typer.Option(False, "--with-dashboard/-d", help="Start web dashboard automatically"), + with_cli_dashboard: bool = typer.Option(False, "--cli-dashboard/-c", help="Show beautiful CLI dashboard"), dashboard_port: int = typer.Option(5000, "--dashboard-port", help="Dashboard port"), ): """ Start EURUSD quantitative trading loop. - Use --with-dashboard to automatically start the web dashboard. + Options: + --with-dashboard/-d: Start web dashboard at http://localhost:5000 + --cli-dashboard/-c: Show beautiful terminal UI with live stats + + Examples: + rdagent fin_quant + rdagent fin_quant -d # Web dashboard + rdagent fin_quant -c # CLI dashboard + rdagent fin_quant -d -c # Both dashboards """ import subprocess import threading import time - # Start Dashboard wenn gewΓΌnscht + # Start Web Dashboard wenn gewΓΌnscht if with_dashboard: - def start_dashboard(): - print(f"\nπŸš€ Starting Dashboard on http://localhost:{dashboard_port}...") - print(f" Open: http://localhost:{dashboard_port}/dashboard.html\n") + def start_web_dashboard(): + console = Console() + console.print(f"\n[bold green]πŸš€ Starting Web Dashboard on http://localhost:{dashboard_port}...[/bold green]") + console.print(f" [cyan]Open: http://localhost:{dashboard_port}/dashboard.html[/cyan]\n") subprocess.run( ["python", "web/dashboard_api.py"], cwd=str(Path(__file__).parent.parent.parent), env={**os.environ, "FLASK_ENV": "development"} ) - # Dashboard im Hintergrund starten - dashboard_thread = threading.Thread(target=start_dashboard, daemon=True) + dashboard_thread = threading.Thread(target=start_web_dashboard, daemon=True) dashboard_thread.start() - time.sleep(2) # Kurze VerzΓΆgerung damit Dashboard starten kann + time.sleep(2) + + # Start CLI Dashboard wenn gewΓΌnscht + if with_cli_dashboard: + def start_cli_dash(): + from rdagent.log.ui.predix_dashboard import run_dashboard + run_dashboard(log_path="fin_quant.log", refresh_interval=3) + + cli_thread = threading.Thread(target=start_cli_dash, daemon=True) + cli_thread.start() + time.sleep(1) # Fin Quant starten fin_quant(path=path, step_n=step_n, loop_n=loop_n, all_duration=all_duration, checkout=checkout) diff --git a/start_loop.sh b/start_loop.sh new file mode 100755 index 00000000..11b25ec9 --- /dev/null +++ b/start_loop.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Start EURUSD Trading in Endlosschleife mit Auto-Restart +# Verwendung: ./start_loop.sh + +set -e + +LOG_FILE=~/Predix/fin_quant.log + +echo "============================================================" +echo " Predix EURUSD Trading - Endlosschleife mit Auto-Restart" +echo "============================================================" +echo "" +echo "Log-Datei: $LOG_FILE" +echo "" +echo "Dashboard Optionen:" +echo " Web: rdagent fin_quant --with-dashboard" +echo " CLI: rdagent fin_quant --cli-dashboard" +echo "" +echo "Stoppen mit: Ctrl+C" +echo "============================================================" +echo "" + +# Conda Environment aktivieren +if [ -f ~/miniconda3/etc/profile.d/conda.sh ]; then + source ~/miniconda3/etc/profile.d/conda.sh + conda activate rdagent + echo "βœ“ Conda Environment 'rdagent' aktiviert" +else + echo "⚠️ Conda nicht gefunden..." +fi + +echo "" +echo "Starte Endlosschleife..." +echo "" + +cd /home/nico/Predix + +while true; do + echo "=== START: $(date) ===" >> $LOG_FILE + echo "" + echo "╔════════════════════════════════════════════════════════╗" + echo "β•‘ πŸš€ START: $(date +"%Y-%m-%d %H:%M:%S") β•‘" + echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•" + echo "" + + dotenv run -- rdagent fin_quant 2>&1 | tee -a $LOG_FILE + + echo "" + echo "╔════════════════════════════════════════════════════════╗" + echo "β•‘ ⏸️ RESTART: $(date +"%Y-%m-%d %H:%M:%S") β•‘" + echo "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•" + echo "=== RESTART: $(date) ===" >> $LOG_FILE + echo "" + echo "Warte 5 Sekunden vor Neustart..." + echo "" + sleep 5 +done diff --git a/start_trading.sh b/start_trading.sh index 7e07676d..99826325 100755 --- a/start_trading.sh +++ b/start_trading.sh @@ -18,29 +18,49 @@ else echo "⚠️ Conda nicht gefunden, versuche mit system Python..." fi -# Dashboard API im Hintergrund starten echo "" -echo "πŸš€ Starte Dashboard API..." -cd /home/nico/Predix -nohup python web/dashboard_api.py > /tmp/dashboard.log 2>&1 & -DASHBOARD_PID=$! -echo "βœ“ Dashboard API gestartet (PID: $DASHBOARD_PID)" +echo "Verwendung:" +echo " Option 1: Web Dashboard (empfohlen)" +echo " rdagent fin_quant --with-dashboard" echo "" -echo "πŸ“Š Dashboard URL: http://localhost:5000/dashboard.html" -echo " Dashboard Log: /tmp/dashboard.log" +echo " Option 2: CLI Dashboard (Terminal UI)" +echo " rdagent fin_quant --cli-dashboard" echo "" +echo " Option 3: Beide Dashboards" +echo " rdagent fin_quant -d -c" +echo "" +echo " Option 4: Endlosschleife mit Auto-Restart" +echo " ./start_loop.sh" +echo "" +echo "============================================================" -# Cleanup Funktion -cleanup() { +# Dashboard API im Hintergrund starten (optional) +read -p "Dashboard im Hintergrund starten? (y/n): " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then echo "" - echo "⏹️ Stoppe Dashboard (PID: $DASHBOARD_PID)..." - kill $DASHBOARD_PID 2>/dev/null || true - echo "βœ“ Gestoppt" - exit 0 -} - -# Trap fΓΌr Ctrl+C -trap cleanup SIGINT SIGTERM + echo "πŸš€ Starte Dashboard API..." + cd /home/nico/Predix + nohup python web/dashboard_api.py > /tmp/dashboard.log 2>&1 & + DASHBOARD_PID=$! + echo "βœ“ Dashboard API gestartet (PID: $DASHBOARD_PID)" + echo "" + echo "πŸ“Š Dashboard URL: http://localhost:5000/dashboard.html" + echo " Dashboard Log: /tmp/dashboard.log" + echo "" + + # Cleanup Funktion + cleanup() { + echo "" + echo "⏹️ Stoppe Dashboard (PID: $DASHBOARD_PID)..." + kill $DASHBOARD_PID 2>/dev/null || true + echo "βœ“ Gestoppt" + exit 0 + } + + # Trap fΓΌr Ctrl+C + trap cleanup SIGINT SIGTERM +fi # RD-Agent fin_quant starten echo "πŸ”„ Starte EURUSD Trading-Agent..." @@ -48,4 +68,6 @@ echo "" dotenv run -- rdagent fin_quant # Cleanup wenn fertig -cleanup +if [[ $REPLY =~ ^[Yy]$ ]]; then + cleanup +fi