Add options index target monitors that auto limit-close on hit.

Position and order forms can arm a target; right-side and hub panels show active monitors; expiry remains the stop with no separate SL.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 15:27:46 +08:00
parent 8d2da921ee
commit d6823a2903
13 changed files with 1011 additions and 18 deletions
+19
View File
@@ -30,6 +30,24 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
if raw is None:
return {"ok": False, "enabled": True, "msg": "获取期权持仓失败"}
positions = build_display_option_positions(cfg, ex, raw)
target_monitors: list[dict[str, Any]] = []
try:
conn = cfg["get_db"]()
try:
from lib.options.options_target_lib import list_active_targets, targets_by_inst
target_monitors = list_active_targets(conn)
tgt_map = targets_by_inst(conn)
for p in positions:
mon = tgt_map.get(str(p.get("inst_id") or ""))
if mon:
p["target_index"] = mon.get("target_index")
p["target_monitor_id"] = mon.get("id")
p["target_monitor"] = mon
finally:
conn.close()
except Exception:
target_monitors = []
upl_total = 0.0
has_upl = False
for p in positions:
@@ -45,6 +63,7 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
"enabled": True,
"positions": positions,
"position_count": len(positions),
"target_monitors": target_monitors,
"upl_total_usdc": round(upl_total, 4) if has_upl else None,
"balances": bal,
"funding_usdc": bal.get("funding_usdc"),