diff --git a/deploy/profile-scripts/refresh_macro_context.py b/deploy/profile-scripts/refresh_macro_context.py index d7c75eea..7acc4735 100644 --- a/deploy/profile-scripts/refresh_macro_context.py +++ b/deploy/profile-scripts/refresh_macro_context.py @@ -42,15 +42,39 @@ def main(): # 计算偏向 sh = indices.get("上证指数", {}) sh_change = sh.get("change_pct", 0) if sh else 0 - if sh_change < -1.5: - overall = "bearish" - desc = "大盘偏弱" - elif sh_change > 1.0: + # 2026-08-19 修复:大盘描述用 market_regime 真实温区(不写死"震荡") + # 原逻辑:涨跌±1.5%内→永远"大盘震荡"(每30min一条无意义通知,老莫) + # 温区映射:trend_up=强势 / trend_down=弱势 / choppy=震荡(真实ADX判定) + _regime = "unknown" + try: + import sqlite3 as _sq3 + _c3 = _sq3.connect(str(DB), timeout=5) + _r3 = _c3.execute("SELECT regime FROM market_regime WHERE market='a' ORDER BY date DESC LIMIT 1").fetchone() + _c3.close() + if _r3: + _regime = _r3[0] or "unknown" + except Exception: + pass + if _regime == "trend_up": overall = "bullish" - desc = "大盘偏强" - else: + desc = "大盘强势(趋势市)" + elif _regime == "trend_down": + overall = "bearish" + desc = "大盘弱势(下跌趋势)" + elif _regime == "choppy": overall = "neutral" - desc = "大盘震荡" + desc = "大盘震荡(ADX<20)" + else: + # 温区不可用 → 退回涨跌幅度判断 + if sh_change < -1.5: + overall = "bearish" + desc = "大盘偏弱" + elif sh_change > 1.0: + overall = "bullish" + desc = "大盘偏强" + else: + overall = "neutral" + desc = "大盘震荡" structure = json.dumps({"overall": overall, "description": desc}, ensure_ascii=False) indices_json = json.dumps(indices, ensure_ascii=False)