Sell residual options at latest bid via IOC limit, not market.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 14:25:03 +08:00
parent 62c91d4bd0
commit 640ecc9530
7 changed files with 89 additions and 13 deletions
+13 -4
View File
@@ -1193,7 +1193,7 @@ class OkxLiveExecutor(Matcher):
)
def try_close_one_residual(self, row: dict) -> dict | None:
"""LIVE:权利金达标后交易所市价卖出归档期权。"""
"""LIVE:权利金达标后按最新买一 IOC 限价卖出归档期权(不扫市价)"""
err = self._guard_live()
if err:
logger.warning("residual premium close blocked: %s", err)
@@ -1218,18 +1218,27 @@ class OkxLiveExecutor(Matcher):
"residual premium close skip %s: bad contracts", row.get("group_id")
)
return None
# 下单前再刷一次买一,按最新盘口挂 IOC
oq2 = self._quote_held_option(option_inst_id)
bid_px = float(oq2.bid) if oq2 is not None and oq2.bid is not None else float(close_bid)
if bid_px <= 0:
logger.debug(
"residual premium close skip %s: bid vanished", row.get("group_id")
)
return None
client = self._client()
try:
opt_live = client.place_market(
opt_live = client.place_ioc(
inst_id=option_inst_id,
side="sell",
sz=str(max(1, int(round(opt_contracts)))),
px=bid_px,
td_mode="cash",
reduce_only=True,
)
except Exception as e:
logger.warning(
"residual premium close exchange sell failed %s: %s",
"residual premium close bid-ioc sell failed %s: %s",
row.get("group_id"),
e,
)
@@ -1252,7 +1261,7 @@ class OkxLiveExecutor(Matcher):
notional=of_notional,
slip=0.0,
now_ms=now_ms,
note="LIVE residual mid-close by premium recovery",
note=f"LIVE residual mid-close at bid IOC px={bid_px}",
exec_mode="LIVE",
)