feat: macro_context/market数据全部DB优先,JSON回退

- 建 macro_context_log 表,macro_context_collector.py 双写
- strategy_lifecycle.py load_macro_context() 优先DB
- strategy_tree.py detect_scenario() 优先DB
- stale_push_wlin.py load_macro_line() 优先DB
- xiaoguo_signal_consumer.py 大盘判断优先DB
- stock_profile.py load_macro() 优先DB
- system_audit.py 管道审计改查DB market_snapshots
- JSON保留作fallback,确保过渡期不中断
This commit is contained in:
知微
2026-06-24 22:34:08 +08:00
parent 843012e045
commit 39ff4d95f7
8 changed files with 132 additions and 39 deletions
+28 -6
View File
@@ -74,19 +74,41 @@ def quick_assess(quote):
score = 0
reasons = []
# 大盘环境(简化:交易日9:30-15:00且在涨
# 引用 macro_context.json 中的大盘方向
# 大盘环境,从DB读(回退JSON
try:
mc = json.loads((DATA / "macro_context.json").read_text())
sh = mc.get("shanghai", {}).get("change_pct", 0)
import sqlite3
conn = sqlite3.connect(str(DB_PATH))
row = conn.execute(
"SELECT indices FROM macro_context_log WHERE has_valid_data=1 ORDER BY created_at DESC LIMIT 1"
).fetchone()
conn.close()
if row and row[0]:
mc = json.loads(row[0])
else:
raise ValueError
sh = 0
for k, v in mc.items():
if "上证" in k:
sh = v.get("change_pct", 0)
break
if sh > 0.5:
score += 1
reasons.append(f"大盘+{sh:.1f}%偏强")
elif sh < -0.5:
score -= 1
reasons.append(f"大盘{sh:.1f}%偏弱")
except:
pass
except Exception:
try:
mc = json.loads((DATA / "macro_context.json").read_text())
sh = mc.get("shanghai", {}).get("change_pct", 0)
if sh > 0.5:
score += 1
reasons.append(f"大盘+{sh:.1f}%偏强")
elif sh < -0.5:
score -= 1
reasons.append(f"大盘{sh:.1f}%偏弱")
except:
pass
# 技术面:涨跌幅
chg = quote.get("change_pct", 0)