Preflight options position limit for dual-leg OO hedges.

Reject OO start when max active is under 2 free slots so limit=1 cannot open a half straddle.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 08:17:17 +08:00
parent 94c65cbd6e
commit f9c2a63cbc
5 changed files with 94 additions and 10 deletions
+30
View File
@@ -56,6 +56,36 @@ class OptionsPositionLimitTests(unittest.TestCase):
)
self.assertIsNone(msg)
def test_oo_needs_two_slots_when_max_one(self):
msg = option_position_limit_block_msg(
object(),
opening_inst_ids=["ETH-C", "ETH-P"],
max_active=1,
fetch_positions=lambda _ex: [],
)
self.assertIsNotNone(msg)
self.assertIn("期期", msg or "")
def test_oo_ok_when_max_two_empty(self):
msg = option_position_limit_block_msg(
object(),
opening_inst_ids=["ETH-C", "ETH-P"],
max_active=2,
fetch_positions=lambda _ex: [],
)
self.assertIsNone(msg)
def test_oo_block_when_one_slot_left(self):
rows = [{"instId": "OTHER", "pos": "1"}]
msg = option_position_limit_block_msg(
object(),
opening_inst_ids=["ETH-C", "ETH-P"],
max_active=2,
fetch_positions=lambda _ex: rows,
)
self.assertIsNotNone(msg)
self.assertIn("期期", msg or "")
def test_fail_closed_when_fetch_none(self):
msg = option_position_limit_block_msg(
object(),