feat(strategy): 策略库灌入vnpy内置8策略模板(DoubleMa/AtrRsi/BollChannel/DualThrust/KingKeltner/MultiSignal/MultiTimeframe/TurtleSignal); registry自研目录优先加载(编辑副本即刻生效,pip兜底); 分类器识别vnpy_ctastrategy import风格 [vps]
CI/CD / test (push) Successful in 10s
CI/CD / nas-deploy (push) Failing after 12s
CI/CD / nas-verify (push) Has been skipped

This commit is contained in:
2026-08-13 18:24:40 +08:00
parent 08aec403f7
commit d8c156e6de
11 changed files with 1289 additions and 8 deletions
+20 -1
View File
@@ -1,7 +1,7 @@
"""Tests for sanguo_api.strategy_registry (Task S1.3)."""
from sanguo_api.strategy_registry import (
list_strategies, strategy_params, STRATEGY_NAMES,
list_strategy_files, read_strategy_file,
list_strategy_files, read_strategy_file, get_strategy_class,
)
@@ -57,3 +57,22 @@ def test_read_strategy_file_returns_code():
content = read_strategy_file(f["name"])
assert "code" in content and isinstance(content["code"], str)
assert content["class_name"] == f["class_name"]
def test_vnpy_builtin_copies_classified_cta():
"""灌入的 vnpy 内置模板(from vnpy_ctastrategy import ...)必须判成 cta。"""
data = list_strategy_files()
cta_files = {f["name"]: f for f in data["files"] if f["dir"] == "sanguo_trader/strategy/"}
assert "double_ma_strategy.py" in cta_files, "内置策略模板未灌入 sanguo_trader/strategy"
assert cta_files["double_ma_strategy.py"]["type"] == "cta"
assert cta_files["double_ma_strategy.py"]["class_name"] == "DoubleMaStrategy"
def test_get_strategy_class_self_owned_priority_or_fallback():
"""有 vnpy_ctastrategy 环境:自研目录类可加载;无:优雅返 None/降级不崩。"""
cls = get_strategy_class("DoubleMaStrategy")
# 本机 dev 无 vnpy_ctastrategy 时 pip 侧也拿不到 → None 不崩即可;
# 容器内应返回 sanguo_trader.strategy.double_ma_strategy 的类(自研优先)
if cls is not None:
assert cls.__name__ == "DoubleMaStrategy"
assert cls.__module__.startswith("sanguo_trader.strategy")