fix: 破止损推送——重评后带完整操作原因+逻辑自洽(重评持有则不推卖出,止损更新到重评值)

This commit is contained in:
xxm
2026-08-17 10:16:49 +08:00
parent 1163d0cce1
commit ec6bdcb648
+39 -12
View File
@@ -611,18 +611,45 @@ def run_once(round_label=""):
if result:
timing_signal = result.get("timing_signal", "")
action = result.get("action", "")
if "买入" in timing_signal or "加仓" in timing_signal or timing_signal in ("卖出","止盈"):
buy_lo = d.get("entry_low", 0)
buy_hi = d.get("entry_high", 0)
rr = result.get("rr_ratio", 0)
# 分级(老爸规则:只有持仓风控动作才ACTION直推;买入/加仓机会进摘要)
if timing_signal in ("卖出","止盈") and (d.get("shares") or 0) > 0:
if _can_push(code, "stop_loss"):
msg = f"🔔 {name}({code}) 价{price}→触发操作区间{max(buy_lo,0):.2f}~{buy_hi:.2f},已触发重评|RR={rr}"
_push_action("操作信号", msg)
else:
_zone_entries.append(f"{name}({code}) {price}→入区+重评{timing_signal}|RR={rr}")
outputs.append(f" 📨 止损重评→已推送Dad: {action}")
# ── 2026-08-17 老莫:进操作区间→重评→按重评发推荐,且带详细原因 ──
# 推送内容 = 重评的完整操作结论(timing_signal + action 全文),不自拼价格/RR
buy_lo = d.get("entry_low", 0)
buy_hi = d.get("entry_high", 0)
rr = result.get("rr_ratio", 0)
sl_new = result.get("stop_loss", 0)
tp_new = result.get("take_profit", 0)
# 汇总重评原因(信号因子/备注)
reason_extra = ""
for k in ("action_note", "signal_factors"):
v = result.get(k)
if v:
if isinstance(v, list):
v = "".join(str(x) for x in v)
reason_extra += f" [{k}={v}]"
if timing_signal in ("卖出", "止盈") and (d.get("shares") or 0) > 0:
if _can_push(code, "stop_loss"):
msg = (f"🔔 {name}({code}) 价{price} → 跌破止损,重评结论【{timing_signal}】| RR={rr}"
f" | 止损{sl_new}/止盈{tp_new}"
f" | 操作: {str(action)[:250]}{reason_extra}")
_push_action("操作信号", msg)
elif "持有" in timing_signal or "关注" in timing_signal or "观望" in timing_signal:
# 破止损但重评确认持有 → 不推卖出(逻辑自洽),更新止损位到重评值
try:
import sqlite3 as _sq
_c = _sq.connect("/home/hmo/MoFin/data/mofin.db", timeout=10)
if sl_new:
_c.execute(
"UPDATE holding_strategies SET stop_loss=?, updated_at=datetime('now','localtime') "
"WHERE code=? AND status='active'", (sl_new, code))
_c.commit()
_c.close()
except Exception:
pass
_zone_entries.append(f"{name}({code}) {price}→破止损但重评{timing_signal},止损已更新至{sl_new}")
outputs.append(f" 📨 破止损→重评{timing_signal}(不卖出,止损更新{sl_new}: {str(action)[:120]}")
else:
_zone_entries.append(f"{name}({code}) {price}→入区+重评{timing_signal}|RR={rr}")
outputs.append(f" 📨 止损重评→{timing_signal}: {str(action)[:120]}")
except Exception as e:
outputs.append(f" ⚠️ 止损重评失败: {e}")
try: