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 <cursoragent@cursor.com>
This commit is contained in:
+13
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user