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