Files
2026-08-07 16:08:34 +08:00

25 lines
803 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""策略注册表与工厂。
新增策略:实现 Strategybase.py在此注册 {name: Class},前端下拉即可选。
策略构造参数由请求的 params(dict) 以 **kwargs 传入。
"""
from __future__ import annotations
from .base import Strategy
from .macd_cross import MACDCrossStrategy
from .ma_strategies import MACrossStrategy, SingleMAStrategy
STRATEGIES: dict[str, type[Strategy]] = {
"macd_cross": MACDCrossStrategy,
"ma_cross": MACrossStrategy,
"single_ma": SingleMAStrategy,
}
def build_strategy(name: str, params: dict | None) -> Strategy:
cls = STRATEGIES.get(name)
if cls is None:
raise ValueError(f"未知策略: {name}(可用: {', '.join(STRATEGIES)}")
kwargs = {k: v for k, v in (params or {}).items()}
return cls(**kwargs)