stale_push_wlin: 按Dad确认流程重构推送逻辑

1. 加重评冷却(4小时)— 查holding_strategies.updated_at
2. 修zone_notes早退bug — 有区间说明时不静默退出
3. zone_notes冷却30分→4小时(匹配重评冷却)
4. 标题自适应:有推荐→自选买入提醒 | 仅区间提醒→操作区间提醒
5. 区间说明格式:'进入操作区间,但重评结果:x'
6. 操作建议标题只在有可操作项时显示
7. has_actionable判定改用实际lines内容
This commit is contained in:
知微
2026-07-09 10:33:50 +08:00
parent a147085f1a
commit c745f1318a
22 changed files with 3452 additions and 1315 deletions
+44 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""stale_detector.py — 检查所有策略,标记价格偏离/过期的策略
读取 decisions.json 的扁平列表。自选策略和持仓策略分开判断
读取 holding_strategies + watchlist_stocks 的DB双源数据
可被 cron no_agent 模式调用:stdout 注入到后续 LLM 分析。
输出格式:
@@ -162,6 +162,49 @@ def main():
except Exception as e:
print(f"[AUTO_REASSESS FAIL] {e}")
# ----- 结束 自选股重评 -----
# 🔁 重评后重新从DB读取策略数据,刷新to_check
try:
decisions_list = read_decisions()
if not isinstance(decisions_list, list):
decisions_list = decisions_list.get("decisions", []) if isinstance(decisions_list, dict) else []
to_check = [d for d in decisions_list if (d.get("entry_low") is not None or d.get("entry_high") is not None) and d.get("status") not in EXCLUDED_STATUSES]
# 重新合并watchlist_stocks
db2 = sqlite3.connect('/home/hmo/MoFin/data/mofin.db')
db2.row_factory = sqlite3.Row
wl_rows2 = db2.execute(
"SELECT code, name, price, entry_low, entry_high, stop_loss, analysis_json "
"FROM watchlist_stocks WHERE is_active=1 AND entry_low IS NOT NULL AND entry_high IS NOT NULL"
).fetchall()
db2.close()
existing_codes2 = {d["code"] for d in to_check}
for row in wl_rows2:
code = str(row["code"])
if code in existing_codes2:
continue
entry_low = row["entry_low"]
entry_high = row["entry_high"]
if not entry_low or not entry_high or entry_low <= 0:
continue
analysis = {}
try:
analysis = json.loads(row["analysis_json"]) if row["analysis_json"] and row["analysis_json"] != "null" else {}
except (json.JSONDecodeError, TypeError):
pass
action = analysis.get("action", "") if isinstance(analysis, dict) else ""
timing_signal = analysis.get("timing_signal", "买入") if isinstance(analysis, dict) else "买入"
wl_entry = {
"code": code,
"name": row["name"] or code,
"entry_low": entry_low,
"entry_high": entry_high,
"stop_loss": row["stop_loss"],
"type": "自选策略",
"action": action,
"timing_signal": timing_signal,
}
to_check.append(wl_entry)
except Exception as e:
print(f"[RELOAD FAIL] {e}", file=sys.stderr)
# ----- 组合级监测:读取总仓位 + 弱势比例 -----
position_pct = 0