fix: 九维分析从DB拉取大盘+基本面数据
This commit is contained in:
@@ -33,36 +33,75 @@ def _build_full_analysis(code, entry, result):
|
||||
rr = result.get("rr_ratio") or entry.get("rr_ratio", 0)
|
||||
act = result.get("action", "")
|
||||
|
||||
# 从tech_snapshot提取关键数据
|
||||
ma5 = ma10 = ma20 = ma60 = "?"
|
||||
# ── 从DB拉取大盘、基本面、资金流 ──
|
||||
macro_desc = ""
|
||||
pe_val = pb_val = ""
|
||||
fund_flow = ""
|
||||
try:
|
||||
import sqlite3 as _sq
|
||||
_db = _sq.connect("/home/hmo/MoFin/data/mofin.db")
|
||||
# 大盘
|
||||
_m = _db.execute("SELECT structure FROM macro_context_log ORDER BY id DESC LIMIT 1").fetchone()
|
||||
if _m and _m[0]:
|
||||
import json as _j
|
||||
_s = _j.loads(_m[0])
|
||||
_indices = _s.get("indices", {})
|
||||
_parts = []
|
||||
for _k in ["上证指数", "深证成指", "创业板指"]:
|
||||
if _k in _indices:
|
||||
_d = _indices[_k]
|
||||
_chg = _d.get("change_pct", 0)
|
||||
_parts.append(f"{_k}({_chg:+.1f}%)")
|
||||
if _parts:
|
||||
macro_desc = " ".join(_parts)
|
||||
_mood = _s.get("sector_mood", "")
|
||||
if _mood:
|
||||
macro_desc += f" 情绪={_mood}"
|
||||
# 基本面
|
||||
_f = _db.execute("SELECT pe, pb FROM stock_fundamentals WHERE code=?", (code,)).fetchone()
|
||||
if _f:
|
||||
if _f[0]: pe_val = f"PE={_f[0]:.1f}"
|
||||
if _f[1]: pb_val = f"PB={_f[1]:.2f}"
|
||||
_db.close()
|
||||
except:
|
||||
pass
|
||||
|
||||
# ── 从tech_snapshot提取MA和支撑阻力 ──
|
||||
import re
|
||||
ma5 = ma10 = ma20 = ma60 = "?"
|
||||
ma_match = re.search(r'MA5=([\d.]+).*?MA10=([\d.]+).*?MA20=([\d.]+).*?MA60=([\d.]+)', tech)
|
||||
if ma_match:
|
||||
ma5, ma10, ma20, ma60 = ma_match.groups()
|
||||
|
||||
lines.append(f"【{name}({code}) 九维全析】")
|
||||
lines.append(f"【{name}({code} 九维全析)】")
|
||||
lines.append("")
|
||||
lines.append(f"① 大盘×技术面:价格{price},MA5={ma5} MA10={ma10} MA20={ma20} MA60={ma60}")
|
||||
if el and eh:
|
||||
lines.append(f"② 大盘×买入区:当前价{'在买入区' if el <= price <= eh else ('低于买入区' if price < el else '高于买入区')}{el}~{eh}")
|
||||
lines.append(f"③ 大盘×资金流:信号={signal},分类={category}")
|
||||
if macro_desc:
|
||||
lines.append(f"① 大盘环境:{macro_desc}")
|
||||
else:
|
||||
lines.append(f"① 大盘环境:数据待刷新")
|
||||
if pe_val or pb_val:
|
||||
lines.append(f"② 个股基本面:{pe_val} {pb_val}")
|
||||
else:
|
||||
lines.append(f"② 个股基本面:数据待补充")
|
||||
lines.append(f"③ 技术面:MA5={ma5} MA10={ma10} MA20={ma20} MA60={ma60}")
|
||||
if el and eh and price > 0:
|
||||
pos = "在买入区内" if el <= price <= eh else (f"低于买入区{(1-price/el)*100:.0f}%" if price < el else f"高于买入区{(price/eh-1)*100:.0f}%")
|
||||
lines.append(f"④ 价格位置:{price} {pos} 区间{el}~{eh}")
|
||||
else:
|
||||
lines.append(f"④ 价格位置:数据待刷新")
|
||||
if sl and tp and rr:
|
||||
lines.append(f"⑤ 风报比:止损{sl} 止盈{tp} RR={rr:.1f}")
|
||||
# 支撑阻力
|
||||
sr_m = re.search(r'强撑:([\d.]+).*?弱撑:([\d.]+).*?弱压:([\d.]+).*?强压:([\d.]+)', tech)
|
||||
if sr_m:
|
||||
lines.append(f"⑥ 支撑阻力:强撑{sr_m.group(1)}→弱撑{sr_m.group(2)}→弱压{sr_m.group(3)}→强压{sr_m.group(4)}")
|
||||
if sector:
|
||||
lines.append(f"④ 行业×基本面:{sector}")
|
||||
if tech:
|
||||
# 提取形态和量价
|
||||
shape_m = re.search(r'形态:([^\s]+)', tech)
|
||||
vol_m = re.search(r'量价:([^\s]+)', tech)
|
||||
shape = shape_m.group(1) if shape_m else "?"
|
||||
vol = vol_m.group(1) if vol_m else "?"
|
||||
lines.append(f"⑤ 个股×技术面:{shape} | {vol}")
|
||||
sr_m = re.search(r'强撑:([\d.]+).*?弱撑:([\d.]+).*?弱压:([\d.]+).*?强压:([\d.]+)', tech)
|
||||
if sr_m:
|
||||
lines.append(f"⑥ 个股×支撑阻力:强撑{sr_m.group(1)}→弱撑{sr_m.group(2)}→弱压{sr_m.group(3)}→强压{sr_m.group(4)}")
|
||||
if sl and tp:
|
||||
lines.append(f"⑦ 个股×风报比:止损{sl} 止盈{tp} RR={rr:.1f}")
|
||||
lines.append(f"⑦ 行业背景:{sector}")
|
||||
if category:
|
||||
lines.append(f"⑧ 分类评级:{category}")
|
||||
lines.append(f"⑨ 策略信号:{signal}")
|
||||
if act:
|
||||
lines.append(f"⑧ 策略判定:{act[:100]}")
|
||||
lines.append(f"⑨ 综合结论:{signal},建议{'关注买入' if '买入' in signal else '持有观望' if signal == '持有' else '观望等待'}")
|
||||
lines.append(f"\n策略详情:{act[:200]}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user