From b4624c77de2ea615a65c04a39d657a38ff2a7c95 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Wed, 1 Apr 2026 17:04:38 +0900 Subject: feat(cli): implement backtest, strategy, portfolio, and data commands --- cli/src/trading_cli/commands/strategy.py | 68 +++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) (limited to 'cli/src/trading_cli/commands/strategy.py') diff --git a/cli/src/trading_cli/commands/strategy.py b/cli/src/trading_cli/commands/strategy.py index 68ffeee..ea3f034 100644 --- a/cli/src/trading_cli/commands/strategy.py +++ b/cli/src/trading_cli/commands/strategy.py @@ -1,4 +1,26 @@ +import sys +from pathlib import Path + import click +from rich.console import Console +from rich.table import Table + +# Add strategy-engine to sys.path +_ROOT = Path(__file__).resolve().parents[5] +sys.path.insert(0, str(_ROOT / "services" / "strategy-engine" / "src")) +sys.path.insert(0, str(_ROOT / "services" / "strategy-engine")) + + +def _load_all_strategies(): + """Load all strategies from the strategies directory.""" + try: + from strategy_engine.plugin_loader import load_strategies + except ImportError as e: + click.echo(f"Error: Could not import plugin_loader: {e}", err=True) + sys.exit(1) + + strategies_dir = _ROOT / "services" / "strategy-engine" / "strategies" + return load_strategies(strategies_dir) @click.group() @@ -10,11 +32,53 @@ def strategy(): @strategy.command("list") def list_(): """List all available trading strategies.""" - click.echo("Fetching available strategies...") + strategies = _load_all_strategies() + + if not strategies: + click.echo("No strategies found.") + return + + console = Console() + table = Table(title="Available Strategies", show_header=True, header_style="bold cyan") + table.add_column("Name", style="bold") + table.add_column("Warmup Period", justify="right") + + for s in strategies: + table.add_row(s.name, str(s.warmup_period)) + + console.print(table) @strategy.command() @click.option("--name", required=True, help="Strategy name") def info(name): """Show detailed information about a strategy.""" - click.echo(f"Fetching details for strategy: {name}...") + strategies = _load_all_strategies() + + matched = [s for s in strategies if s.name == name] + if not matched: + available = [s.name for s in strategies] + click.echo(f"Error: Strategy '{name}' not found. Available: {available}", err=True) + sys.exit(1) + + strat = matched[0] + config_dir = _ROOT / "services" / "strategy-engine" / "strategies" / "config" + config_file = config_dir / f"{name}_strategy.yaml" + if not config_file.exists(): + # Try without _strategy suffix + config_file = config_dir / f"{name}.yaml" + + console = Console() + table = Table(title=f"Strategy: {strat.name}", show_header=True, header_style="bold cyan") + table.add_column("Property", style="bold") + table.add_column("Value") + + table.add_row("Name", strat.name) + table.add_row("Warmup Period", str(strat.warmup_period)) + table.add_row("Class", type(strat).__name__) + if config_file.exists(): + table.add_row("Config File", str(config_file)) + else: + table.add_row("Config File", "(none)") + + console.print(table) -- cgit v1.2.3