Align emergency option close to OKX: use bid only, never mark.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 17:15:38 +08:00
parent 2b7c504134
commit 021b0d0a22
4 changed files with 139 additions and 143 deletions
+2 -2
View File
@@ -367,7 +367,7 @@ class Matcher:
"""
全平一组。默认校验期权买一深度 + 买一/标记偏差(默认≤30%)。
reason=expiry:对齐实盘,期权按标的结算价的内在价值入账(不吃盘口)。
bypass_liquidity=True(紧急):绕过深度闸门,价取 max(买一, 标记, 内在价值)
bypass_liquidity=True(紧急):绕过深度/偏差闸门,成交价仍按买一(对齐 OKX 市价卖,不用标记)
成交顺序:先平期权 → 再瞬时平永续;永续盘口失败则回滚期权入账。
"""
s = get_settings()
@@ -462,7 +462,7 @@ class Matcher:
if resolved is None:
return CloseResult(
ok=False,
detail="紧急全平失败:无买一/标记/内在价值",
detail="紧急全平失败:无买一(对齐 OKX,不能用标记价平仓)",
)
close_bid = resolved
of = option_fill(
+8 -12
View File
@@ -68,21 +68,17 @@ def resolve_option_close_bid(
bypass_liquidity: bool,
) -> float | None:
"""
非到期平仓用买一价;多头卖出不得低于内在价值SIM)。
紧急 bypassmax(买一, 标记, 内在价值)
非到期平仓SIM)。
- 常规:买一,且多头卖出不低于内在价值。
- 紧急 bypass:对齐 OKX 市价卖,**只按买一**(不用标记/内在价值抬价;
标记无法在交易所成交)。bypass 只绕过深度/偏差闸门。
到期请用 option_expiry_settle,不要走本函数。
"""
candidates: list[float] = []
if bid is not None and bid >= 0:
candidates.append(float(bid))
if bypass_liquidity and mark is not None and mark >= 0:
candidates.append(float(mark))
if intrinsic is not None and intrinsic >= 0:
candidates.append(float(intrinsic))
if not candidates:
return None
_ = mark # 保留参数兼容调用方;紧急不再用标记定价
if bypass_liquidity:
return max(candidates)
if bid is None or bid < 0:
return None
return float(bid)
if bid is None:
return None
if intrinsic is not None and intrinsic >= 0:
+6 -6
View File
@@ -214,14 +214,14 @@ def test_option_intrinsic_and_close_bid_floor() -> None:
assert settled.notional == 44.0
assert abs(settled.fee - 44.0 * 0.0005) < 1e-12
# 紧急垃圾买一 0.2,内在价值 22 → 抬到 22
# 紧急:对齐 OKX 市价卖,只按买一(垃圾买一不抬到内在价值/标记)
assert (
resolve_option_close_bid(
bid=0.2, mark=0.2, intrinsic=22.0, bypass_liquidity=True
bid=0.2, mark=22.0, intrinsic=22.0, bypass_liquidity=True
)
== 22.0
== 0.2
)
# 常规也有内在价值地板
# 常规内在价值地板
assert (
resolve_option_close_bid(
bid=0.2, mark=0.2, intrinsic=22.0, bypass_liquidity=False
@@ -235,10 +235,10 @@ def test_option_intrinsic_and_close_bid_floor() -> None:
)
== 25.0
)
# bypass 无买一,用标记与内在价值
# 紧急无买一 → 无法定价(不能用标记)
assert (
resolve_option_close_bid(
bid=None, mark=3.0, intrinsic=22.0, bypass_liquidity=True
)
== 22.0
is None
)