"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(runner): route A-shares by market for sources without a Wave-1 branch
chiww63ec69ac3996
diff --git a/agent/backtest/runner.py b/agent/backtest/runner.pyindex 9ee68e82d..6155f6e70 100644--- a/agent/backtest/runner.py+++ b/agent/backtest/runner.py@@ -1389,13 +1389,22 @@ def _create_market_engine(source: str, config: dict, codes: List[str]):market = _detect_submarket(codes)return GlobalEquityEngine(config, market=market)else:- # Sources without a dedicated branch (local, stooq, ...): follow the- # instrument market rather than the loader name, so e.g. a local- # AAPL.US dataset gets US-equity execution rules instead of crypto.+ # Sources without a dedicated branch (local, stooq, tencent, ...):+ # follow the instrument market rather than the loader name, so e.g. a+ # local AAPL.US dataset gets US-equity execution rules instead of crypto.if markets & {"us_equity", "hk_equity", "ca_equity", "uk_equity"}:from backtest.engines.global_equity import GlobalEquityEnginemarket = _detect_submarket(codes)return GlobalEquityEngine(config, market=market)+ # A-shares need the same treatment. Every branchless source that serves+ # them -- local, tencent, eastmoney, baostock, mootdx, sina -- used to+ # land here and fall through to the crypto default, which applies none+ # of the A-share rules (stamp tax, T+1, price limits, 100-share lots)+ # and does charge an 8-hourly perpetual funding fee against the+ # position. The run still succeeds, which is what makes it dangerous.+ if "a_share" in markets:+ from backtest.engines.china_a import ChinaAEngine+ return ChinaAEngine(config)from backtest.engines.crypto import CryptoEnginereturn CryptoEngine(config)diff --git a/agent/tests/test_local_source_routing.py b/agent/tests/test_local_source_routing.pyindex 9c01fdec7..52c409c43 100644--- a/agent/tests/test_local_source_routing.py+++ b/agent/tests/test_local_source_routing.py@@ -15,6 +15,7 @@ import pandas as pdimport pytestfrom backtest.benchmark import resolve_benchmark+from backtest.engines.china_a import ChinaAEnginefrom backtest.engines.crypto import CryptoEnginefrom backtest.engines.global_equity import GlobalEquityEnginefrom backtest.runner import _create_market_engine@@ -38,6 +39,39 @@ class TestLocalSourceEngineRouting:engine = _create_market_engine("local", {"initial_cash": 100_000}, ["BTC-USDT"])assert isinstance(engine, CryptoEngine)+ def test_local_a_share_routes_to_china_a_engine(self) -> None:+ engine = _create_market_engine("local", {"initial_cash": 100_000}, ["000001.SZ"])+ assert isinstance(engine, ChinaAEngine)++ # Sources with no Wave-1 branch in ``_create_market_engine``. Each is a+ # registered A-share source that a caller can name explicitly -- the+ # data-routing skill lists baostock/tencent/mootdx/eastmoney as A-share+ # sources, and ``skills/mootdx/SKILL.md`` documents+ # ``run(strategy=..., source="mootdx")``. Naming any of them used to route+ # A-shares to CryptoEngine: no stamp tax, no T+1, no price limits, no+ # 100-share lots, and an 8-hourly perpetual funding fee charged against+ # the position. ``"auto"`` is branchless here too -- the runner resolves it+ # through ``_detect_primary_source`` before calling, but this function must+ # not depend on that.+ @pytest.mark.parametrize(+ "source",+ ["local", "tencent", "eastmoney", "baostock", "mootdx", "sina", "stooq",+ "yahoo", "auto"],+ )+ def test_branchless_sources_route_a_share_to_china_a_engine(+ self, source: str,+ ) -> None:+ engine = _create_market_engine(source, {"initial_cash": 100_000}, ["600519.SH"])+ assert isinstance(engine, ChinaAEngine)++ @pytest.mark.parametrize("source", ["tushare", "akshare"])+ def test_branching_sources_keep_routing_a_share_to_china_a_engine(+ self, source: str,+ ) -> None:+ """The sources that already worked must keep working."""+ engine = _create_market_engine(source, {"initial_cash": 100_000}, ["600519.SH"])+ assert isinstance(engine, ChinaAEngine)+class _FakeLoader:"""Loader stub returning a fixed close series for any requested code."""