fix: 空信号清除tag + 卖出/止盈仅持仓股算动作信号

This commit is contained in:
hmo
2026-07-22 10:48:49 +08:00
parent b18e0d2164
commit 1910cef98b
+10 -3
View File
@@ -1148,12 +1148,18 @@ def sync_recommend_tag(conn, code: str, timing_signal: str):
"""裸 SQL 调用方(batch_reassess / per_stock_reassess)的推荐 tag 同步。
动作级信号 → current_recommend;信号降级 → 清除 current_recommend
active_manual(人工标记)永不动。与 XMPP 动作级告警同源(红线#12)。"""
_ACTION_SIGNALS = ("买入", "可买入", "可加仓", "卖出", "止盈")
try:
_old_tag_row = conn.execute(
"SELECT tag FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
_old_tag = (_old_tag_row[0] or '') if _old_tag_row else ''
if timing_signal in _ACTION_SIGNALS:
# 卖出/止盈 仅对持仓股算动作信号(没持仓卖什么)
_ACTION_BUY = ("买入", "可买入", "可加仓")
_ACTION_SELL = ("卖出", "止盈")
if timing_signal in _ACTION_SELL:
_h = conn.execute("SELECT shares FROM holdings WHERE code=? AND is_active=1", (code,)).fetchone()
if not (_h and (_h[0] or 0) > 0):
timing_signal = "" # 非持仓的卖出/止盈不算动作信号
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')",
@@ -1161,7 +1167,8 @@ def sync_recommend_tag(conn, code: str, timing_signal: str):
conn.commit()
if _old_tag != 'current_recommend':
enqueue_recommend(conn, code) # 新推荐 → 摘要队列(batch 结束统一发)
elif timing_signal:
elif _old_tag == 'current_recommend':
# 空信号或非动作信号 → 清除自动推荐(active_manual 不动)
conn.execute(
"UPDATE holding_strategies SET tag='' "
"WHERE code=? AND status='active' AND tag='current_recommend'",