fix: 箱体/收敛突破标记价反向越界时自动撤销监控

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-29 10:54:36 +08:00
parent 5b3448b52b
commit a0d57fc65e
12 changed files with 204 additions and 45 deletions
+35 -11
View File
@@ -168,6 +168,8 @@ from key_monitor_lib import (
KEY_MONITOR_RS_TYPES,
auto_amp_ok,
auto_confirm_ok,
box_breakout_invalidate_by_mark,
box_breakout_invalidate_edge_label,
claim_rs_level_notify,
detect_rs_box_break,
format_auto_amp_line,
@@ -6036,6 +6038,21 @@ def check_key_monitors():
direction = (r["direction"] or "long").lower()
if direction == KEY_DIRECTION_WATCH:
continue
if typ in KEY_MONITOR_AUTO_TYPES:
mark = get_symbol_mark_price(sym)
if mark is not None and box_breakout_invalidate_by_mark(direction, mark, up, low):
edge = float(low) if direction == "long" else float(up)
edge_label = box_breakout_invalidate_edge_label(direction)
msg = (
f"# ⚠️ {sym} 关键位监控失效\n"
f"**账户:{_wechat_account_label()}**\n"
f"- 类型:{typ}{_wechat_direction_text(direction)}\n"
f"- 标记价 {format_price_for_symbol(sym, mark)} 已突破反向{edge_label} "
f"{format_price_for_symbol(sym, edge)}(设置失效)\n"
)
send_wechat_msg(msg)
_finalize_key_monitor_one_shot(conn, r, msg, "box_opposite_break")
continue
try:
checks = _key_hard_checks(sym, direction, up, low, typ)
except Exception:
@@ -7197,6 +7214,7 @@ def api_price_snapshot():
fib_gate_ok = True
fb_gate_ok = True
te_gate_ok = True
box_gate_ok = True
if is_fib:
direction = (r["direction"] or "long").lower()
inval = fib_invalidate_by_mark(direction, price, r["upper"], r["lower"])
@@ -7253,16 +7271,22 @@ def api_price_snapshot():
except Exception:
gate_summary = "-"
elif (r["monitor_type"] or "").strip() in KEY_MONITOR_AUTO_TYPES:
try:
gate = _key_hard_checks(
r["symbol"],
(r["direction"] or "long").lower(),
r["upper"],
r["lower"],
r["monitor_type"],
)
except Exception:
gate = None
direction = (r["direction"] or "long").lower()
if box_breakout_invalidate_by_mark(direction, price, r["upper"], r["lower"]):
edge_label = box_breakout_invalidate_edge_label(direction)
gate_summary = f"反向突破{edge_label}·将撤销"
box_gate_ok = False
else:
try:
gate = _key_hard_checks(
r["symbol"],
direction,
r["upper"],
r["lower"],
r["monitor_type"],
)
except Exception:
gate = None
if gate:
rank_seg = "ERR" if int(gate.get("rank_total") or 0) <= 0 else f"{gate.get('rank')}/{gate.get('rank_total')}"
gate_summary = (
@@ -7301,7 +7325,7 @@ def api_price_snapshot():
fib_gate_ok if is_fib
else fb_gate_ok if is_fb
else te_gate_ok if is_te
else bool(gate and gate.get("ok"))
else box_gate_ok and bool(gate and gate.get("ok"))
),
"gate_metrics": gate_metrics,
})
@@ -112,6 +112,7 @@ Binance / OKX 见各自目录下同名文档;共享逻辑在仓库根目录 `k
| `close_reason` | 含义 |
|----------------|------|
| `box_opposite_break` | 标记价先突破反向边界(多:≤下沿;空:≥上沿) |
| `rr_insufficient` | 门控通过但 RR 不达标或 SL/TP 几何无效 |
| `exchange_failed` | RR 达标但实盘/交易所等原因未开仓 |
| `auto_opened` | RR 达标且市价开仓成功 |