Use bid1-only option closes with hard-disabled market exits.

Manual close checks liquidity only; target auto still requires 2x recycle hold once, then reuses the shared bid1 executor. Add /options/guide doc and update hedge-plan refs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 21:49:06 +08:00
parent ab8b2a74e2
commit 1909eea654
17 changed files with 2136 additions and 2210 deletions
+22 -1
View File
@@ -3,7 +3,12 @@ from __future__ import annotations
import unittest
from lib.options.options_close_gate_lib import clear_close_gate, update_close_gate
from lib.options.options_close_gate_lib import (
clear_close_gate,
is_close_gate_passed,
mark_close_gate_passed,
update_close_gate,
)
class OptionsCloseGateTests(unittest.TestCase):
@@ -38,6 +43,22 @@ class OptionsCloseGateTests(unittest.TestCase):
self.assertFalse(g_again["ready"])
self.assertAlmostEqual(g_again["held_seconds"], 0.0)
def test_passed_latches_after_ready(self):
update_close_gate("ETH-Y", recycle_usdc=20.0, premium_paid=10.0, now=1000.0)
g_ready = update_close_gate("ETH-Y", recycle_usdc=21.0, premium_paid=10.0, now=1120.0)
self.assertTrue(g_ready["ready"])
self.assertTrue(g_ready["passed"])
self.assertTrue(is_close_gate_passed("ETH-Y"))
# 后续回收跌破 2×:计时重置,但 passed 仍保留供续批只验流动性
g_drop = update_close_gate("ETH-Y", recycle_usdc=5.0, premium_paid=10.0, now=1130.0)
self.assertFalse(g_drop["recycle_ok"])
self.assertTrue(g_drop["passed"])
self.assertFalse(g_drop["auto_close_blocked"])
def test_mark_passed_manual(self):
mark_close_gate_passed("ETH-Z")
self.assertTrue(is_close_gate_passed("ETH-Z"))
if __name__ == "__main__":
unittest.main()
+12
View File
@@ -185,11 +185,13 @@ def test_format_quote_liquidity():
def test_estimate_close_by_bids_full_depth():
from lib.options.options_pricing_lib import estimate_close_by_bids
# 多档估算需显式 max_levels;默认只估买一
out = estimate_close_by_bids(
[{"px": 12.3, "sz": 2}, {"px": 12.1, "sz": 3}],
4,
ct_mult=0.01,
premium_paid=0.4,
max_levels=5,
)
assert out["covered_sheets"] == 4
assert out["uncovered_sheets"] == 0
@@ -199,6 +201,16 @@ def test_estimate_close_by_bids_full_depth():
assert out["estimated_pnl_ratio_pct"] == 22.0
assert [x["sheets"] for x in out["levels"]] == [2, 2]
bid1 = estimate_close_by_bids(
[{"px": 12.3, "sz": 2}, {"px": 12.1, "sz": 3}],
4,
ct_mult=0.01,
premium_paid=0.4,
)
assert bid1["covered_sheets"] == 2
assert bid1["uncovered_sheets"] == 2
assert [x["sheets"] for x in bid1["levels"]] == [2]
def test_estimate_close_by_bids_partial_depth():
from lib.options.options_pricing_lib import estimate_close_by_bids