From eb4414f7412648eaa0d19e003d4540c735dfb03b Mon Sep 17 00:00:00 2001 From: dekun Date: Fri, 26 Jun 2026 00:58:16 +0800 Subject: [PATCH] Fix trade sync when get_all_trades returns a list. Handle both dict and list from vnpy so records page CTP sync no longer warns. Co-authored-by: Cursor --- vnpy_bridge.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vnpy_bridge.py b/vnpy_bridge.py index dde7012..4d0ca8d 100644 --- a/vnpy_bridge.py +++ b/vnpy_bridge.py @@ -1099,6 +1099,17 @@ class CtpBridge: """不再 monkey-patch CTP 成交回调(易与并发查询冲突导致 vnctptd 段错误)。""" return + @staticmethod + def _engine_collection_items(raw: Any) -> list[Any]: + """vnpy 不同版本可能返回 dict 或 list。""" + if raw is None: + return [] + if isinstance(raw, dict): + return list(raw.values()) + if isinstance(raw, (list, tuple)): + return list(raw) + return [raw] + def _collect_engine_trades(self) -> list[dict[str, Any]]: if not self._engine: return [] @@ -1107,8 +1118,8 @@ class CtpBridge: try: trades = self._engine.get_all_trades() except Exception: - trades = {} - for trade in (trades or {}).values(): + trades = None + for trade in self._engine_collection_items(trades): row = self._trade_row_from_vnpy(trade) if not row: continue