Fix roll margin validation and SHFE close offset for night positions.

Use CTP account margin for roll cap checks and prefer close-today on SHFE when yesterday close is rejected.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-03 09:22:17 +08:00
parent 50bb04e2bb
commit 1cd3039605
3 changed files with 87 additions and 24 deletions
+12 -3
View File
@@ -1015,10 +1015,19 @@ class CtpBridge:
return Offset.CLOSE
vol = int(getattr(pos, "volume", 0) or 0)
yd = int(getattr(pos, "yd_volume", 0) or 0)
today = max(0, vol - yd)
if today >= lots:
td = max(0, vol - yd)
if td >= lots:
return Offset.CLOSETODAY
return Offset.CLOSEYESTERDAY
if yd >= lots:
# 夜盘仓在 vnpy 常记在 yd,日盘平昨易报「平昨仓位不足」→ 上期所/能源优先平今
if ex_u in ("SHFE", "INE"):
return Offset.CLOSETODAY
return Offset.CLOSEYESTERDAY
if td + yd >= lots:
return Offset.CLOSETODAY
if ex_u in ("SHFE", "INE", "CZCE"):
return Offset.CLOSETODAY
return Offset.CLOSE
def _aggressive_limit_price(
self,