Fix roll average entry: CTP trade-weighted avg, sync after fill, live entry for preview.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-2
@@ -326,7 +326,14 @@ class CtpBridge:
|
||||
pos = event.data
|
||||
row = self._position_row_from_vnpy(pos)
|
||||
if row:
|
||||
trading_state.upsert_position(row, notify=False)
|
||||
sym = row.get("symbol") or ""
|
||||
ex = row.get("exchange") or ""
|
||||
ths = CtpBridge._vnpy_sym_to_ths(sym, ex) or sym
|
||||
with _ctp_td_lock:
|
||||
trades = self.list_trades()
|
||||
trading_state.upsert_position(
|
||||
row, notify=False, trades=trades, ths_sym=ths,
|
||||
)
|
||||
sym = getattr(pos, "symbol", "") or ""
|
||||
d = "long" if _is_long_direction(getattr(pos, "direction", None)) else "short"
|
||||
vol = int(getattr(pos, "volume", 0) or 0)
|
||||
@@ -482,7 +489,13 @@ class CtpBridge:
|
||||
with _ctp_td_lock:
|
||||
orders = self.list_active_orders()
|
||||
positions = self._collect_positions()
|
||||
trading_state.calibrate_from_lists(orders, positions)
|
||||
trades = self.list_trades()
|
||||
trading_state.calibrate_from_lists(
|
||||
orders,
|
||||
positions,
|
||||
trades=trades,
|
||||
ths_for_vnpy_sym=lambda s, e: CtpBridge._vnpy_sym_to_ths(s, e) or s,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.debug("calibrate trading state: %s", exc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user