Require real ask depth for options and hedge opens.

Block mark-as-ask opens, show reference mark when no depth, cap sheets to ask size; leave close paths unchanged. Document in docs/更新文档.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-16 12:48:53 +08:00
parent 195eeae295
commit 4686cf049a
10 changed files with 339 additions and 21 deletions
+53
View File
@@ -89,6 +89,8 @@ class TestHedgePlanOrderPath(unittest.TestCase):
return_value={
"ok": True,
"ask": 12.5,
"ask_sz": 10,
"can_open": True,
"ct_mult": 0.01,
"tick_sz": "0.1",
"strike": 1800,
@@ -134,6 +136,8 @@ class TestHedgePlanOrderPath(unittest.TestCase):
return_value={
"ok": True,
"ask": 10,
"ask_sz": 5,
"can_open": True,
"ct_mult": 0.01,
"tick_sz": "0.1",
"strike": 1800,
@@ -157,6 +161,55 @@ class TestHedgePlanOrderPath(unittest.TestCase):
self.assertTrue(out["ok"])
self.assertEqual(len(out["results"]), 2)
def test_buy_rejects_without_ask_depth(self):
from lib.hedge_plan.hedge_plan_orders_lib import _buy_option
quote = MagicMock(
return_value={
"ok": True,
"ask": None,
"ask_sz": None,
"mark": 11.2,
"ref_ask": 11.2,
"can_open": False,
"open_block_msg": "暂无卖一深度,无法买入",
"ct_mult": 0.01,
}
)
cfg = {
"exchange_options": object(),
"quote_option_contract": quote,
"place_option_limit_order": MagicMock(),
}
out = _buy_option(cfg, inst_id="ETH-USD_UM-260717-1900-C", sheets=1, dry_run=True)
self.assertFalse(out["ok"])
self.assertIn("卖一", out["msg"])
cfg["place_option_limit_order"].assert_not_called()
def test_buy_caps_sheets_to_ask_depth(self):
from lib.hedge_plan.hedge_plan_orders_lib import _buy_option
quote = MagicMock(
return_value={
"ok": True,
"ask": 10,
"ask_sz": 2,
"can_open": True,
"ct_mult": 0.01,
"tick_sz": "0.1",
"meta": {"optType": "C"},
}
)
cfg = {
"exchange_options": object(),
"quote_option_contract": quote,
"place_option_limit_order": MagicMock(),
"td_mode_for_option_buy": lambda x: "isolated",
}
out = _buy_option(cfg, inst_id="X", sheets=9, dry_run=True)
self.assertTrue(out["ok"])
self.assertEqual(out["sheets"], 2)
if __name__ == "__main__":
unittest.main()
+22
View File
@@ -0,0 +1,22 @@
"""期权买入流动性门禁:真实卖一价+深度."""
from lib.exchange.okx_options_lib import (
cap_option_buy_sheets_to_ask_depth,
option_buy_liquidity_ok,
)
def test_option_buy_liquidity_ok_requires_ask_and_depth():
assert option_buy_liquidity_ok(10, 1)[0] is True
assert option_buy_liquidity_ok(10, 0)[0] is False
assert option_buy_liquidity_ok(10, None)[0] is False
assert option_buy_liquidity_ok(None, 5)[0] is False
assert option_buy_liquidity_ok(0, 5)[0] is False
def test_cap_option_buy_sheets_to_ask_depth():
capped, msg = cap_option_buy_sheets_to_ask_depth(9, 2.8, min_sz=1)
assert capped == 2
assert msg == ""
capped, msg = cap_option_buy_sheets_to_ask_depth(1, 0.4, min_sz=1)
assert capped is None
assert "深度不足" in msg