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
+19 -2
View File
@@ -690,7 +690,24 @@ def execute_options_options_start(
results: list[dict[str, Any]] = []
leg_a = body.get("leg_a") or {}
leg_b = body.get("leg_b") or {}
a_res = _buy_option(cfg, inst_id=str(leg_a.get("inst_id") or ""), sheets=float(leg_a.get("sheets") or 1), dry_run=dry_run)
inst_a = str(leg_a.get("inst_id") or "")
inst_b = str(leg_b.get("inst_id") or "")
from lib.options.options_position_limit_lib import option_position_limit_block_msg
pos_limit_msg = option_position_limit_block_msg(
cfg.get("exchange_options"),
opening_inst_ids=[inst_a, inst_b],
fetch_positions=cfg.get("fetch_option_positions"),
)
if pos_limit_msg:
return {
"ok": False,
"msg": pos_limit_msg,
"path": path,
"results": [],
"refresh": refresh,
}
a_res = _buy_option(cfg, inst_id=inst_a, sheets=float(leg_a.get("sheets") or 1), dry_run=dry_run)
results.append({"step": "options_buy_limit", "leg": "a", **a_res})
if not a_res.get("ok"):
return {
@@ -700,7 +717,7 @@ def execute_options_options_start(
"results": results,
"refresh": refresh,
}
b_res = _buy_option(cfg, inst_id=str(leg_b.get("inst_id") or ""), sheets=float(leg_b.get("sheets") or 1), dry_run=dry_run)
b_res = _buy_option(cfg, inst_id=inst_b, sheets=float(leg_b.get("sheets") or 1), dry_run=dry_run)
results.append({"step": "options_buy_limit", "leg": "b", **b_res})
if not b_res.get("ok"):
if not dry_run and partial_auto_close_enabled():