fix: 持仓手数均价分列、止损止盈显示金额、CTP开仓时间含OpenTime
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+21
-6
@@ -732,11 +732,22 @@ class CtpBridge:
|
||||
return (self._position_open_times.get(self._position_margin_key(sym, direction)) or "").strip()
|
||||
|
||||
@staticmethod
|
||||
def _parse_ctp_open_datetime(date_raw: str, time_raw: str = "") -> str:
|
||||
"""CTP OpenDate + OpenTime → YYYY-MM-DD HH:MM[:SS]。"""
|
||||
d = (date_raw or "").strip()
|
||||
if len(d) >= 8 and d[:8].isdigit():
|
||||
date_part = f"{d[:4]}-{d[4:6]}-{d[6:8]}"
|
||||
else:
|
||||
return ""
|
||||
t = (time_raw or "").strip().replace(":", "")
|
||||
if len(t) >= 6 and t[:6].isdigit():
|
||||
return f"{date_part} {t[0:2]}:{t[2:4]}:{t[4:6]}"
|
||||
if len(t) >= 4 and t.isdigit():
|
||||
return f"{date_part} {t[0:2]}:{t[2:4]}"
|
||||
return date_part
|
||||
|
||||
def _parse_ctp_open_date(raw: str) -> str:
|
||||
s = (raw or "").strip()
|
||||
if len(s) >= 8 and s[:8].isdigit():
|
||||
return f"{s[:4]}-{s[4:6]}-{s[6:8]} 09:00:00"
|
||||
return ""
|
||||
return CtpBridge._parse_ctp_open_datetime(raw, "")
|
||||
|
||||
def _install_position_margin_hook(self) -> None:
|
||||
"""拦截 CTP 持仓回报,缓存柜台 UseMargin。"""
|
||||
@@ -769,8 +780,12 @@ class CtpBridge:
|
||||
bridge._position_margins[k] = (
|
||||
bridge._position_margins.get(k, 0.0) + margin
|
||||
)
|
||||
open_date = bridge._parse_ctp_open_date(
|
||||
str(data.get("OpenDate") or data.get("open_date") or "")
|
||||
open_date = bridge._parse_ctp_open_datetime(
|
||||
str(data.get("OpenDate") or data.get("open_date") or ""),
|
||||
str(
|
||||
data.get("OpenTime") or data.get("open_time")
|
||||
or data.get("TradeTime") or ""
|
||||
),
|
||||
)
|
||||
if sym and open_date:
|
||||
k = bridge._position_margin_key(sym, d)
|
||||
|
||||
Reference in New Issue
Block a user