From 0e09da12dbcd7a84f8e63ec7a51d2a77da66ede4 Mon Sep 17 00:00:00 2001 From: xxm Date: Wed, 19 Aug 2026 11:03:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20refresh=5Fmacro=5Fcontext=E5=A4=A7?= =?UTF-8?q?=E7=9B=98=E6=8F=8F=E8=BF=B0=E7=94=A8=E7=9C=9F=E5=AE=9E=E6=B8=A9?= =?UTF-8?q?=E5=8C=BA(=E4=B8=8D=E5=86=99=E6=AD=BB=E9=9C=87=E8=8D=A1)?= =?UTF-8?q?=E2=80=94=E2=80=94=E5=BD=93=E5=89=8Dtrend=5Fup=E2=86=92?= =?UTF-8?q?=E5=A4=A7=E7=9B=98=E5=BC=BA=E5=8A=BF(=E8=B6=8B=E5=8A=BF?= =?UTF-8?q?=E5=B8=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile-scripts/refresh_macro_context.py | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) 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)