fix(key-monitor): repair trigger entry bugs in four exchange apps

Restore missing check_fib_key_monitors, fix gate preview and OKX add_key,
and unify trigger execution error handling to avoid duplicate history writes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-14 01:06:53 +08:00
parent edf4bb835d
commit 4573ccca9a
4 changed files with 179 additions and 130 deletions
+28 -24
View File
@@ -5391,18 +5391,30 @@ def _execute_trigger_entry_cross(conn, row):
conn.execute("DELETE FROM key_monitors WHERE id=?", (kid,))
conn.commit()
ok, err, det = _market_open_for_trigger_entry(
conn,
symbol,
direction,
ex_sym,
entry,
sl,
tp,
breakeven_enabled=be_en,
time_close_enabled=tc_en,
time_close_hours=tc_h,
)
try:
ok, err, det = _market_open_for_trigger_entry(
conn,
symbol,
direction,
ex_sym,
entry,
sl,
tp,
breakeven_enabled=be_en,
time_close_enabled=tc_en,
time_close_hours=tc_h,
)
except Exception as e:
fail_msg = friendly_exchange_error(e)
send_wechat_msg(
f"# ❌ {symbol} 触价开仓异常\n"
f"**账户:{_wechat_account_label()}**\n"
f"- 计划入场:{format_price_for_symbol(symbol, entry)}\n"
f"- 原因:{fail_msg}\n"
)
insert_key_monitor_history(conn, row, 0, fail_msg, TRIGGER_ENTRY_CLOSE_EXCHANGE_FAILED)
return False, fail_msg
if ok and det:
rr_txt = format_wechat_scalar_2dp(det.get("planned_rr_fill")) if det.get("planned_rr_fill") is not None else "-"
msg = (
@@ -5468,17 +5480,7 @@ def check_trigger_entry_key_monitors():
_finalize_key_monitor_one_shot(conn, r, msg, TRIGGER_ENTRY_CLOSE_TP_INVALIDATE)
continue
if trigger_entry_reached(direction, mark, entry):
try:
_execute_trigger_entry_cross(conn, r)
except Exception as e:
fail_msg = friendly_exchange_error(e)
try:
insert_key_monitor_history(conn, r, 0, fail_msg, TRIGGER_ENTRY_CLOSE_EXCHANGE_FAILED)
except Exception:
pass
send_wechat_msg(
f"# ❌ {symbol} 触价开仓异常\n**账户:{_wechat_account_label()}**\n- {fail_msg}\n"
)
_execute_trigger_entry_cross(conn, r)
conn.commit()
conn.close()
@@ -6989,6 +6991,7 @@ def api_price_snapshot():
gate_metrics = ""
fib_gate_ok = True
fb_gate_ok = True
te_gate_ok = True
if is_fib:
direction = (r["direction"] or "long").lower()
inval = fib_invalidate_by_mark(direction, price, r["upper"], r["lower"])
@@ -7027,7 +7030,7 @@ def api_price_snapshot():
)
gate_summary = prev.get("summary") or "-"
gate_metrics = prev.get("metrics") or ""
fib_gate_ok = bool(prev.get("gate_ok"))
te_gate_ok = bool(prev.get("gate_ok"))
elif (r["monitor_type"] or "").strip() in KEY_MONITOR_RS_TYPES:
try:
prev = _key_rs_gate_preview(r["symbol"], r["upper"], r["lower"])
@@ -7087,6 +7090,7 @@ def api_price_snapshot():
"gate_ok": (
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"))
),
"gate_metrics": gate_metrics,