1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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()
def strategy():
"""Strategy management commands."""
pass
@strategy.command("list")
def list_():
"""List all available trading 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."""
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)
|