From 21b16751c54b7f3ea763114b09ca16a3696a31b4 Mon Sep 17 00:00:00 2001 From: hmo Date: Fri, 14 Aug 2026 17:56:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=B6=E6=AE=B54=E6=B8=A9=E5=8C=BA?= =?UTF-8?q?=E6=BA=AF=E6=BA=90=E6=8C=89=E5=B8=82=E5=9C=BA=E6=84=9F=E7=9F=A5?= =?UTF-8?q?=E2=80=94=E2=80=94market=5Fconfig=E5=8A=A0get=5Fregime=5Ftemp(c?= =?UTF-8?q?ode)(A=E8=82=A1=E8=A1=8C=E4=B8=BA=E4=B8=8D=E5=8F=98=E8=AF=BBsmo?= =?UTF-8?q?othed=E9=A1=B6=E5=B1=82,=E6=B8=AF=E8=82=A1=E8=AF=BBmarkets.hk),?= =?UTF-8?q?stale=5Fpush=5Fwlin/price=5Fmonitor=E4=BF=A1=E5=8F=B7=E6=BA=AF?= =?UTF-8?q?=E6=BA=90=E6=94=B9=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/market_config.py | 40 +++++++++++++++++++++++ deploy/profile-scripts/price_monitor.py | 10 +++--- deploy/profile-scripts/stale_push_wlin.py | 9 ++--- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/deploy/profile-scripts/market_config.py b/deploy/profile-scripts/market_config.py index 34c666fd..e50f483a 100644 --- a/deploy/profile-scripts/market_config.py +++ b/deploy/profile-scripts/market_config.py @@ -14,6 +14,7 @@ strategy_lab 中的 6 处重复实现。 """ from datetime import datetime +from pathlib import Path from mo_models import is_hk_stock @@ -104,6 +105,45 @@ def is_trading_now(market, dt=None): return False +def get_regime_temp(code): + """按标的市场读取温区+温度(信号溯源用,2026-08-14 阶段4)。 + + A股:smoothed 顶层(get_current_regime,K=5 平滑温区)+ get_market_temp('a') + —— 与既有单市场行为完全一致。 + 港股:smoothed markets.hk(K=5 平滑温区)+ get_market_temp('hk')。 + + 返回 (regime, temp_band),异常时 ("", "")。延迟 import 避免循环依赖。 + """ + mkt = market_for_code(code) + regime, temp = "", "" + try: + if mkt == 'hk': + import json as _json + sp = Path(__file__).resolve().parent.parent.parent / "data" / "market_regime_smoothed.json" + if sp.exists(): + d = _json.loads(sp.read_text(encoding="utf-8")) + mk = (d.get("markets") or {}).get("hk") or {} + regime = mk.get("current_regime", "") + temp = (mk.get("temp") or {}).get("band", "") + if not regime: # 回退:market_regime 表港股最新温区 + import sqlite3 as _sq + from market_regime import DB_PATH as _DB + conn = _sq.connect(str(_DB), timeout=5) + row = conn.execute( + "SELECT regime FROM market_regime WHERE market='hk' ORDER BY date DESC LIMIT 1" + ).fetchone() + conn.close() + regime = row[0] if row else "" + else: + from regime_gate import get_current_regime + regime = get_current_regime().get("regime", "") + from temp_band import get_market_temp + temp = get_market_temp(market='a').get("band", "") + except Exception: + pass + return regime, temp + + # ── 模块自检 ──────────────────────────────────────────────────────────── if __name__ == '__main__': diff --git a/deploy/profile-scripts/price_monitor.py b/deploy/profile-scripts/price_monitor.py index f7b7940a..b283a9ae 100644 --- a/deploy/profile-scripts/price_monitor.py +++ b/deploy/profile-scripts/price_monitor.py @@ -51,15 +51,13 @@ def _is_strategy_active(d_entry): return True def _record_signal(code, name, reason, strategy=""): - """信号溯源:记录到 signal_ledger""" + """信号溯源:记录到 signal_ledger(温区/温度按标的市场,2026-08-14 阶段4)""" try: from signal_ledger import record_signal - from regime_gate import get_current_regime - from temp_band import get_market_temp - rg = get_current_regime() - tp = get_market_temp() + from market_config import get_regime_temp + _regime, _temp = get_regime_temp(code) record_signal(code=code, name=name, strategy=strategy, version=strategy, - regime=rg.get("regime", ""), temp_band=tp.get("band", ""), + regime=_regime, temp_band=_temp, reason=reason, source_module="price_monitor") except Exception: pass diff --git a/deploy/profile-scripts/stale_push_wlin.py b/deploy/profile-scripts/stale_push_wlin.py index 599a59de..3939c0fb 100644 --- a/deploy/profile-scripts/stale_push_wlin.py +++ b/deploy/profile-scripts/stale_push_wlin.py @@ -943,12 +943,9 @@ def main(): regime_now = "" temp_now = "" try: - from regime_gate import get_current_regime - _rg = get_current_regime() - regime_now = _rg.get("regime", "") - from temp_band import get_market_temp - _tp = get_market_temp() - temp_now = _tp.get("band", "") + # 2026-08-14 阶段4:温区溯源按标的市场(A股=原行为, 港股=港股温区) + from market_config import get_regime_temp + regime_now, temp_now = get_regime_temp(code) except Exception: pass # 溯源记录 + 共振检测