Support dual breakout targets for options-options hedges.

Replace single S* with up/down targets across UI, preview, persist, monitor, and alerts so ranging breakouts can close the winner either way.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-14 14:32:06 +08:00
parent f6ef06f659
commit 8ecc70a61c
13 changed files with 233 additions and 53 deletions
+31 -4
View File
@@ -269,7 +269,21 @@ def _persist_oo(cfg: dict[str, Any], result: dict[str, Any], body: dict[str, Any
"plan_type": "options_options",
"status": "active",
"underlying": str(body.get("underlying") or "ETH").upper(),
"target_price": float(body.get("target_price") or 0),
"target_price": float(
body.get("target_price_up")
or body.get("target_price")
or 0
),
"target_price_up": float(
body.get("target_price_up")
or body.get("target_price")
or 0
),
"target_price_down": float(
body.get("target_price_down")
or body.get("target_price")
or 0
),
"sizing_mode_at_open": load_position_sizing_mode(),
"premium_total": premium,
"opened_at": result.get("opened_at"),
@@ -610,8 +624,20 @@ def _preview_po(body: dict[str, Any]) -> dict[str, Any]:
def _preview_oo(body: dict[str, Any]) -> dict[str, Any]:
target = float(body["target_price"])
index_px = float(body.get("index_px") or target)
up = body.get("target_price_up")
down = body.get("target_price_down")
legacy = body.get("target_price")
if up in (None, "") and legacy not in (None, ""):
up = legacy
if down in (None, "") and legacy not in (None, ""):
down = legacy
if up in (None, "") or down in (None, ""):
raise ValueError("请填写上破与下破目标价")
up_f = float(up)
down_f = float(down)
if up_f <= down_f:
raise ValueError("上破目标价必须大于下破目标价")
index_px = float(body.get("index_px") or ((up_f + down_f) / 2))
leg_a = body.get("leg_a") or {}
leg_b = body.get("leg_b") or {}
for name, leg in (("leg_a", leg_a), ("leg_b", leg_b)):
@@ -626,7 +652,8 @@ def _preview_oo(body: dict[str, Any]) -> dict[str, Any]:
if leg.get("premium_paid") is None:
raise ValueError(f"缺少 {name} 权利金")
return build_options_options_preview(
target_price=target,
target_price_up=up_f,
target_price_down=down_f,
index_px=index_px,
leg_a=leg_a,
leg_b=leg_b,