修改支撑阻力的企业微信推送

This commit is contained in:
dekun
2026-05-28 11:54:37 +08:00
parent a829cf50f3
commit b2b6aac094
6 changed files with 384 additions and 202 deletions
+46 -64
View File
@@ -84,8 +84,11 @@ from key_monitor_lib import (
format_auto_amp_line,
format_auto_confirm_line,
notify_interval_elapsed,
resolve_rs_break_for_alert,
rs_break_from_direction,
run_rs_level_alert_tick,
)
from wechat_notify_lib import build_wechat_rs_level_message, send_wechat_webhook
from hub_auth import request_allowed as hub_request_allowed
from history_window_lib import (
PRESET_CUSTOM,
@@ -298,16 +301,9 @@ LIQUIDITY_RANK_CACHE = {
# 企业微信推送
def send_wechat_msg(content):
prefix = "【加密货币】"
full_msg = f"{prefix}\n{content}"
data = {
"msgtype": "text",
"text": {"content": full_msg}
}
try:
requests.post(WECHAT_WEBHOOK, json=data, timeout=WECHAT_TIMEOUT_SECONDS)
except:
pass
send_wechat_webhook(
WECHAT_WEBHOOK, content, timeout=WECHAT_TIMEOUT_SECONDS
)
_BREAKEVEN_EXCHANGE_WARNED_IDS = set()
@@ -1385,6 +1381,7 @@ def init_db():
"ALTER TABLE key_monitors ADD COLUMN sl_tp_mode TEXT DEFAULT 'standard'",
"ALTER TABLE key_monitors ADD COLUMN manual_take_profit REAL",
"ALTER TABLE key_monitors ADD COLUMN breakeven_enabled INTEGER DEFAULT 0",
"ALTER TABLE key_monitors ADD COLUMN last_rs_bar_ts INTEGER",
):
try:
c.execute(ddl)
@@ -4126,39 +4123,6 @@ def _fetch_last_closed_bar(symbol):
return closed[-1] if closed else None
def build_wechat_rs_level_message(
symbol,
monitor_type,
trigger_time,
upper,
lower,
trigger_close,
break_info,
notify_index,
notify_max,
):
lines = [
f"# 📌 {symbol} 关键位突破提醒({notify_index}/{notify_max}",
f"**账户:{_wechat_account_label()}**",
"",
"---",
"",
"### 突破判定(5m 收盘)",
f"- 类型:**{monitor_type}**",
f"- 触发时间:`{trigger_time}`",
f"- 上沿:`{upper}`|下沿:`{lower}`",
f"- 触发收盘:`{format_price_for_symbol(symbol, trigger_close)}`",
f"- **{break_info['break_label']}**(程序推断:**{_wechat_direction_text(break_info['direction'])}**",
f"- 突破价位:`{format_price_for_symbol(symbol, break_info['edge_price'])}`",
"",
"### 说明",
"- 本条为**人工盯盘**用途:录入时**不选多空**,由上/下沿突破方向自动判定。",
f"- 共推送 **{notify_max}** 次(间隔约 {KEY_ALERT_INTERVAL_MINUTES} 分钟),推送完毕后本条监控结案。",
"- **不参与**自动开仓、量能/二确/盈亏比门控。",
]
return "\n".join(lines)
def _key_rs_gate_preview(symbol, upper, lower):
"""页面门控预览:阻力/支撑仅显示距上/下沿与是否已越线。"""
bar = _fetch_last_closed_bar(symbol)
@@ -4189,45 +4153,63 @@ def _process_key_rs_level_alert(conn, row):
return
close = float(bar[4])
ts = bar[0]
count = int(row["notification_count"] or 0)
max_n = max(1, int(row["max_notify"] or KEY_ALERT_MAX_TIMES))
interval = max(1, int(row["notify_interval_min"] or KEY_ALERT_INTERVAL_MINUTES))
now_dt = app_now()
tick = run_rs_level_alert_tick(
row,
close,
ts,
now_dt,
default_max_notify=KEY_ALERT_MAX_TIMES,
default_interval_min=KEY_ALERT_INTERVAL_MINUTES,
)
if not tick:
return
if count == 0:
br = detect_rs_box_break(close, up, low)
if not br:
return
else:
if not notify_interval_elapsed(row["last_notified_at"], interval, now_dt):
return
br = rs_break_from_direction(row["direction"], up, low)
if not br:
br = tick["break_info"]
notify_index = int(tick["notify_index"])
max_n = int(tick["notify_max"])
interval = int(tick["interval_min"])
bar_ts = tick.get("bar_ts")
if tick.get("need_claim_first"):
conn.execute(
"UPDATE key_monitors SET notification_count=1, direction=?, last_notified_at=?, last_rs_bar_ts=? "
"WHERE id=? AND COALESCE(notification_count,0)=0",
(br["direction"], app_now_str(), bar_ts, row["id"]),
)
if conn.total_changes == 0:
return
conn.commit()
trigger_time = ms_to_app_local_str(int(ts)) if ts else app_now_str()
notify_index = count + 1
msg = build_wechat_rs_level_message(
symbol=sym,
monitor_type=typ,
account_label=_wechat_account_label(),
trigger_time=trigger_time,
upper=up,
lower=low,
trigger_close=close,
break_info=br,
upper_txt=format_price_for_symbol(sym, up),
lower_txt=format_price_for_symbol(sym, low),
close_txt=format_price_for_symbol(sym, close),
edge_txt=format_price_for_symbol(sym, br["edge_price"]),
break_label=br["break_label"],
direction=br["direction"],
notify_index=notify_index,
notify_max=max_n,
interval_min=interval,
)
send_wechat_msg(msg)
conn.execute(
"UPDATE key_monitors SET direction=?, notification_count=?, last_notified_at=?, last_alert_message=? WHERE id=?",
(br["direction"], notify_index, app_now_str(), msg, row["id"]),
"UPDATE key_monitors SET direction=?, notification_count=?, last_notified_at=?, "
"last_alert_message=?, last_rs_bar_ts=? WHERE id=?",
(br["direction"], notify_index, app_now_str(), msg, bar_ts, row["id"]),
)
conn.commit()
if notify_index >= max_n:
hist_row = conn.execute("SELECT * FROM key_monitors WHERE id=?", (row["id"],)).fetchone()
if hist_row:
insert_key_monitor_history(conn, hist_row, notify_index, msg, "key_level_alert_done")
conn.execute("DELETE FROM key_monitors WHERE id=?", (row["id"],))
conn.commit()
def _key_hard_lines_from_checks(checks):
@@ -4860,8 +4842,8 @@ def check_key_monitors():
if typ in KEY_MONITOR_RS_TYPES:
try:
_process_key_rs_level_alert(conn, r)
except Exception:
pass
except Exception as e:
print(f"[key_rs_level_alert] {sym} id={r['id']}: {e}")
continue
direction = (r["direction"] or "long").lower()