Fix position flicker, drop futures cooloff, prioritize startup display.
Preserve trading state when CTP memory is empty, bootstrap equity/positions on page load, stabilize risk status from DB monitors, and remove app-layer manual close cooling periods. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -226,6 +226,7 @@ class CtpTradingState:
|
||||
*,
|
||||
trades: Optional[list[dict[str, Any]]] = None,
|
||||
ths_for_vnpy_sym: Optional[Callable[[str, str], str]] = None,
|
||||
preserve_positions_if_margin: float = 0.0,
|
||||
) -> None:
|
||||
"""全量校准:以 vnpy 内存为准重建订单/持仓簿。"""
|
||||
self.begin_sync()
|
||||
@@ -256,6 +257,9 @@ class CtpTradingState:
|
||||
new_positions[pk] = reconcile_position_avg(
|
||||
old, row, tick, trades=trades, ths_sym=ths,
|
||||
)
|
||||
if not new_positions and self._positions and preserve_positions_if_margin > 0:
|
||||
with self._lock:
|
||||
new_positions = {k: dict(v) for k, v in self._positions.items()}
|
||||
with self._lock:
|
||||
self._orders = new_orders
|
||||
self._positions = new_positions
|
||||
|
||||
Reference in New Issue
Block a user