fix(shadow): ShadowBroker补LiveEngine 0.9.2协议方法(supports_account_sync/cleanup等5个);VPS实况=影子进程启动即崩进崩溃循环(引擎_start_background_jobs无条件调supports_account_sync);加协议完整性防回归测试 [vps]
CI/CD / test (push) Successful in 15s
CI/CD / nas-deploy (push) Successful in 30s
CI/CD / nas-verify (push) Successful in 12s

This commit is contained in:
2026-08-14 20:04:59 +08:00
parent c16c78aaf8
commit ea736acb29
2 changed files with 36 additions and 0 deletions
+17
View File
@@ -68,6 +68,23 @@ class ShadowBroker: # noqa: R0903 - 仅实现 BrokerBase 协议(bullet_trade du
def heartbeat(self) -> None:
return None
# ===== LiveEngine 0.9.2 兼容查询(本地柜台无外部账户/委托可同步) =====
# 引擎 _start_background_jobs 无条件调 supports_account_sync(),缺方法=启动即崩
def supports_account_sync(self) -> bool:
return False
def supports_orders_sync(self) -> bool:
return False
def sync_account(self) -> None:
return None
def sync_orders(self) -> list:
return []
def cleanup(self) -> None: # 引擎关闭时无条件调
return None
def before_open(self) -> None:
"""每个交易日开盘前:清 T+1 买入记录(昨日买的今天可卖)。"""
self._today_bought = {}
+19
View File
@@ -133,3 +133,22 @@ def test_cancel_always_false_and_open_orders_empty():
_buy(b, "600519.SH", 100, px=100.0)
assert asyncio.run(b.cancel_order("whatever")) is False
assert b.get_open_orders() == [] # 即时成交,无挂单
def test_live_engine_protocol_compat():
"""LiveEngine 0.9.2 duck-typed 协议完整性(2026-08-14 VPS 实况教训:
缺 supports_account_sync → 引擎 _start_background_jobs 启动即崩,影子进程崩溃循环)。"""
from sanguo_trader.shadow.broker import ShadowBroker
b = ShadowBroker()
for attr in (
"connect", "disconnect", "is_connected", "heartbeat",
"before_open", "after_close", "cleanup",
"supports_account_sync", "supports_orders_sync",
"sync_account", "sync_orders",
"get_account_info", "get_positions", "get_open_orders",
):
assert hasattr(b, attr), f"LiveEngine 需要 broker.{attr}, ShadowBroker 缺失"
assert b.supports_account_sync() is False # 本地柜台,引擎跳过账户同步
assert b.supports_orders_sync() is False
assert b.sync_orders() == []
b.cleanup() # 不抛异常