fix(tag): RR检查前置于tag打标——RR<2.0不打current_recommend

- 原顺序:打tag→查RR→RR<2.0拒绝入队但tag已落盯盘→盯盘≠XMPP
- 修正: 先查RR→RR<2.0直接跳过不打tag→盯盘和XMPP永远一致
This commit is contained in:
hmo
2026-07-27 11:15:50 +08:00
parent f723664ca3
commit 46ca7bf404
+22 -8
View File
@@ -1287,16 +1287,30 @@ def sync_recommend_tag(conn, code: str, timing_signal: str):
conn.commit()
print(f" [AUTO-POS] {code} 仓位'{_pos_r[1]}''{_pos_auto}'", flush=True)
if timing_signal in _ACTION_BUY or timing_signal in _ACTION_SELL:
conn.execute(
"UPDATE holding_strategies SET tag='current_recommend' "
"WHERE code=? AND status='active' AND (tag IS NULL OR tag != 'active_manual')",
(code,))
conn.commit()
# 入队条件:tag 新鲜转成 或 信号从非动作级转入动作级
#(防:信号持有→卖出但tag已遗留current_recommend就不入队——2026-07-27 老爸)
# ── 买入RR质量门禁(2026-07-27 老爸:RR<2.0的买入不值得推荐,tag都不能打,防盯盘垃圾)──
# 此前tag先打、enqueue再查RR,结果RR<2.0的tag已落盯盘,与XMPP不一致。
_should_tag = True
if timing_signal in _ACTION_BUY:
_rr_chk = conn.execute(
"SELECT rr_ratio FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
if _rr_chk and (_rr_chk[0] or 0) < 2.0:
print(f" [TAG SYNC] {code} RR={_rr_chk[0]:.2f}<2.0,不打推荐tag", flush=True)
_should_tag = False
if _should_tag:
conn.execute(
"UPDATE holding_strategies SET tag='current_recommend' "
"WHERE code=? AND status='active' AND (tag IS NULL OR tag != 'active_manual')",
(code,))
conn.commit()
else:
# RR不达标 → 清除旧tag(如果打了)
if _old_tag == 'current_recommend':
conn.execute("UPDATE holding_strategies SET tag='' WHERE code=? AND status='active'", (code,))
conn.commit()
# 入队条件(2026-07-27 老爸:tag新鲜转成、信号转入动作级、或卖出信号 — 三个场景均需入队)
_old_action = _old_sig in _ACTION_BUY or _old_sig in _ACTION_SELL
_new_action = timing_signal in _ACTION_BUY or timing_signal in _ACTION_SELL
if _old_tag != 'current_recommend' or (not _old_action and _new_action):
if (_should_tag and _old_tag != 'current_recommend') or (not _old_action and _new_action):
enqueue_recommend(conn, code) # 新推荐 → 摘要队列(batch 结束统一发)
elif _old_tag == 'current_recommend':
# 空信号或非动作信号 → 清除自动推荐(active_manual 不动)