Fix strategy-logic P0s from audit: monitor false-flat, fill-confirmed open/close, mode gates.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 09:56:18 +08:00
parent fa7ff739a0
commit 4b4dca9e3c
15 changed files with 820 additions and 167 deletions
+21 -4
View File
@@ -50,12 +50,28 @@ class TestHedgePlanOrderPath(unittest.TestCase):
"tp": 1900,
"sl": 1700,
"contracts": 1,
"opt_inst_id": "X",
"opt_inst_id": "ETH-USD-260731-1800-P",
"opt_type": "P",
"sheets": 1,
"exchange_symbol": "ETH/USDT:USDT",
},
)
self.assertIsNone(ok)
bad_type = validate_start_body(
"perp_options",
{
"direction": "long",
"entry": 1800,
"tp": 1900,
"sl": 1700,
"contracts": 1,
"opt_inst_id": "ETH-USD-260731-1800-C",
"opt_type": "C",
"sheets": 1,
"exchange_symbol": "ETH/USDT:USDT",
},
)
self.assertIsNotNone(bad_type)
def test_gate_can_start_when_live(self):
g = gate_status(
@@ -196,7 +212,7 @@ class TestHedgePlanOrderPath(unittest.TestCase):
self.assertIn("卖一", out["msg"])
cfg["place_option_limit_order"].assert_not_called()
def test_buy_caps_sheets_to_ask_depth(self):
def test_buy_rejects_when_ask_depth_below_request(self):
from lib.hedge_plan.hedge_plan_orders_lib import _buy_option
quote = MagicMock(
@@ -217,8 +233,9 @@ class TestHedgePlanOrderPath(unittest.TestCase):
"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)
self.assertFalse(out["ok"])
self.assertIn("不足请求", out["msg"])
cfg["place_option_limit_order"].assert_not_called()
if __name__ == "__main__":