Fix CTP exchange routing for non-SHFE contracts and duplicate trade closes.
Resolve CZCE/DCE symbols to the correct exchange for orders, dedupe stop-loss closes and trade logs, and rely on CTP sync for authoritative records. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+19
-1
@@ -556,7 +556,21 @@ class CtpBridge:
|
||||
return Offset.CLOSE
|
||||
pos = self._find_position(sym, ex_u, hold_direction)
|
||||
if not pos:
|
||||
# 找不到持仓明细时,日盘新开仓优先平今(避免 SHFE「平昨仓位不足」)
|
||||
for p in self._collect_positions():
|
||||
ps = (p.get("symbol") or "").lower()
|
||||
if ps != sym.lower():
|
||||
continue
|
||||
if (p.get("direction") or "long") != hold_direction:
|
||||
continue
|
||||
td = int(p.get("td_volume") or 0)
|
||||
yd = int(p.get("yd_volume") or 0)
|
||||
if td >= lots:
|
||||
return Offset.CLOSETODAY
|
||||
if yd >= lots:
|
||||
return Offset.CLOSEYESTERDAY
|
||||
if td + yd >= lots:
|
||||
return Offset.CLOSETODAY
|
||||
break
|
||||
if ex_u in ("SHFE", "INE", "CZCE"):
|
||||
return Offset.CLOSETODAY
|
||||
return Offset.CLOSE
|
||||
@@ -1112,6 +1126,8 @@ class CtpBridge:
|
||||
sym, ex_name, d, vol, price, pos=pos,
|
||||
)
|
||||
open_time = self._lookup_position_open_time(sym, d) or None
|
||||
yd = int(getattr(pos, "yd_volume", 0) or 0)
|
||||
td = max(0, vol - yd)
|
||||
out.append({
|
||||
"symbol": sym,
|
||||
"exchange": ex_name,
|
||||
@@ -1122,6 +1138,8 @@ class CtpBridge:
|
||||
"frozen": int(getattr(pos, "frozen", 0) or 0),
|
||||
"margin": margin,
|
||||
"open_time": open_time,
|
||||
"yd_volume": yd,
|
||||
"td_volume": td,
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
Reference in New Issue
Block a user