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 段错误)。"""
|
"""不再 monkey-patch CTP 成交回调(易与并发查询冲突导致 vnctptd 段错误)。"""
|
||||||
return
|
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]]:
|
def _collect_engine_trades(self) -> list[dict[str, Any]]:
|
||||||
if not self._engine:
|
if not self._engine:
|
||||||
return []
|
return []
|
||||||
@@ -1107,8 +1118,8 @@ class CtpBridge:
|
|||||||
try:
|
try:
|
||||||
trades = self._engine.get_all_trades()
|
trades = self._engine.get_all_trades()
|
||||||
except Exception:
|
except Exception:
|
||||||
trades = {}
|
trades = None
|
||||||
for trade in (trades or {}).values():
|
for trade in self._engine_collection_items(trades):
|
||||||
row = self._trade_row_from_vnpy(trade)
|
row = self._trade_row_from_vnpy(trade)
|
||||||
if not row:
|
if not row:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user