Backfill OO expiry settle display via public ETHUSDT and intrinsic overlay.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-11 16:58:02 +08:00
parent 3264dd4381
commit 77d2effb6d
5 changed files with 375 additions and 17 deletions
+33 -3
View File
@@ -2,22 +2,28 @@
from __future__ import annotations
from app.api.trades import _infer_settle_index
from app.api.trades import _infer_settle_index, _overlay_expiry_zero_fills
def test_otm_call_zero_fill_does_not_become_strike() -> None:
def test_otm_call_zero_fill_does_not_become_strike(monkeypatch) -> None:
g = {
"hedge_mode": "option_option",
"option_side": "call",
"option2_side": "put",
"option_inst_id": "ETH-USD-260811-1920-C", # OKX 样式:不走公开回退
"strike": 1920.0,
"strike2": 1890.0,
"settle_index_px": None,
"close_reason": "expiry",
"close_at_ms": 1,
}
fills = [
{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0},
{"leg": "option2", "action": "close", "fill_px": 0.0, "slip": 0},
]
monkeypatch.setattr(
"app.api.public_index.maybe_public_settle_index", lambda _g: None
)
assert _infer_settle_index(g, fills) is None
@@ -34,7 +40,6 @@ def test_itm_put_fill_infers_settle_near_1875() -> None:
{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0},
{"leg": "option2", "action": "close", "fill_px": 45.0, "slip": 0},
]
# put intrinsic 45 → settle = 1920 - 45 = 1875
assert _infer_settle_index(g, fills) == 1875.0
@@ -46,3 +51,28 @@ def test_stored_settle_wins() -> None:
}
fills = [{"leg": "option", "action": "close", "fill_px": 0.0, "slip": 0}]
assert _infer_settle_index(g, fills) == 1875.2
def test_public_fallback_and_overlay(monkeypatch) -> None:
g = {
"hedge_mode": "option_option",
"option_side": "call",
"option2_side": "put",
"option_inst_id": "ETH-USD_UM-260811-1940-C",
"strike": 1940.0,
"strike2": 1920.0,
"settle_index_px": None,
"close_reason": "expiry",
"close_at_ms": 1786435200000,
}
fills = [
{"leg": "option", "action": "close", "fill_px": 0.0, "qty_eth": 7, "slip": 0},
{"leg": "option2", "action": "close", "fill_px": 0.0, "qty_eth": 7, "slip": 0},
]
monkeypatch.setattr(
"app.api.public_index.maybe_public_settle_index", lambda _g: 1877.8
)
assert _infer_settle_index(g, fills) == 1877.8
view = _overlay_expiry_zero_fills(g, fills, 1877.8)
assert view[0]["fill_px"] == 0.0 # call OTM
assert abs(view[1]["fill_px"] - (1920 - 1877.8)) < 1e-9