fix: 九维分析全面升级-资金流+消息面入prompt+交叉综合+capital_flow_collector修mo_data引用

This commit is contained in:
知微
2026-07-10 11:45:03 +08:00
parent c48429b994
commit 7f65f0cbd2
3 changed files with 99 additions and 13 deletions
+47 -3
View File
@@ -84,14 +84,57 @@ def build_prompt(data):
cash = 321271 # 可用现金(从DB读取)
total = 952879 # 总资产
# 拉取资金流数据
_flow_note = "暂无资金流数据"
try:
import sqlite3 as _sq, json as _j
_db = _sq.connect("/home/hmo/MoFin/data/mofin.db")
_fr = _db.execute("SELECT cache_json FROM capital_flow_cache ORDER BY id DESC LIMIT 1").fetchone()
if _fr and _fr[0]:
_fc = _j.loads(_fr[0])
_stocks = _fc.get("stocks", {})
_s = _stocks.get(data['code'], {})
if _s and _s.get("analysis"):
_a = _s["analysis"]
_net = _a.get("net_flow", 0)
_main = _a.get("main_force", 0)
_retail = _a.get("retail_flow", 0)
_trend = _a.get("trend", "中性")
_flow_note = f"净流入{_net:.0f}万 主力{_main:.0f}万 散户{_retail:.0f}万 趋势{_trend}"
_db.close()
except:
pass
# 拉取近期消息面
_news_note = "暂无近期消息"
try:
import sqlite3 as _sq
_db = _sq.connect("/home/hmo/MoFin/data/mofin.db")
_nr = _db.execute(
"SELECT summary, overall_sentiment, created_at FROM signal_news "
"WHERE (code=? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') "
"ORDER BY id DESC LIMIT 3",
(data['code'], f'%{data.get("name","")[:4]}%')
).fetchall()
if _nr:
_news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _nr])
_db.close()
except:
pass
return f"""你是一个资深A股分析师。请对{data['code']} {data.get('name','')}做一个完整的九维矩阵分析,并输出策略参数。
当前数据:
⚠️ 重要:以下9个维度不是独立分析的,你必须交叉对比后给出综合结论。
例如:如果消息面利好但资金流在流出,说明利好可能是出货;如果基本面强但技术面破位,说明估值可能还没到底。
当前数据(以下数据均来自实时API,禁止使用模型训练数据):
大盘:{data.get('macro','震荡')}
最新价:{data.get('price',0)} 涨跌:{data.get('change_pct','0')}%
PE={data.get('pe','?')} 市值={data.get('mcap','?')}亿
行业:{data.get('sector_context','?')}
技术面:{data.get('tech_snapshot','')[:200]}
技术面:{data.get('tech_snapshot','')[:300]}
资金流:{_flow_note}
消息面:{_news_note}
当前信号:{data.get('timing_signal','?')} 分类:{data.get('stock_category','?')}
原策略:{(data.get('action','') or '')[:200]}
@@ -99,7 +142,8 @@ PE={data.get('pe','?')} 市值={data.get('mcap','?')}亿
请严格按以下格式输出:
① 大盘×基本面 [一句话]
【交叉分析】用2-3句话说明哪些维度出现矛盾/共振,最关键的信号是什么
① 大盘×基本面 [一句话,说明矛盾关系]
② 大盘×消息面 [一句话]
③ 大盘×技术面 [一句话]
④ 大盘×资金流 [一句话]
+9 -8
View File
@@ -11,8 +11,7 @@ from datetime import datetime
from urllib.request import urlopen, Request
from concurrent.futures import ThreadPoolExecutor, as_completed
from threading import Semaphore
from mo_data import read_portfolio, read_decisions, read_watchlist
from mofin_db import get_conn, write_capital_flow_cache
from mofin_db import get_conn, write_capital_flow_cache, query_holdings, query_holdings_db, query_watchlist
DATA_DIR = "/home/hmo/web-dashboard/data"
CACHE_PATH = f"{DATA_DIR}/capital_flow_cache.json"
@@ -134,13 +133,15 @@ def analyze_flow(flow_data):
def main():
codes = set()
# 读取持仓+自选
# 读取持仓+自选(从DB直接读,替代已删除的mo_data)
try:
dec = mo_data.read_decisions()
for d in dec.get("decisions", []):
c = d.get("code", "")
if c:
codes.add(c)
import sqlite3
_db = sqlite3.connect("/home/hmo/MoFin/data/mofin.db")
for row in _db.execute("SELECT DISTINCT code FROM holdings WHERE is_active=1").fetchall():
if row[0]: codes.add(row[0])
for row in _db.execute("SELECT DISTINCT code FROM holding_strategies WHERE status='active' AND decision_type='自选策略'").fetchall():
if row[0]: codes.add(row[0])
_db.close()
except:
pass
+43 -2
View File
@@ -394,12 +394,53 @@ def main():
except:
pass
# 拉取资金流数据
_flow_note = "暂无资金流数据"
try:
_fdb = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
_fr = _fdb.execute("SELECT cache_json FROM capital_flow_cache ORDER BY id DESC LIMIT 1").fetchone()
if _fr and _fr[0]:
_fc = __import__('json').loads(_fr[0])
_s = _fc.get("stocks", {}).get(code, {})
if _s and _s.get("analysis"):
_a = _s["analysis"]
_flow_note = f"净流入{_a.get('net_flow',0):.0f}万 主力{_a.get('main_force',0):.0f}万 趋势{_a.get('trend','中性')}"
_fdb.close()
except:
pass
# 拉取近期消息面
_news_note = "暂无近期消息"
try:
_ndb = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
_nr2 = _ndb.execute(
"SELECT summary, overall_sentiment, created_at FROM signal_news "
"WHERE (code=? OR sector LIKE ?) AND overall_sentiment IN ('利好','利空') "
"ORDER BY id DESC LIMIT 3",
(code, f'%{entry.get("name","")[:4]}%')
).fetchall()
if _nr2:
_news_note = " | ".join([f"{r[2][:10]} {r[1]} {r[0][:40]}" for r in _nr2])
_ndb.close()
except:
pass
_prompt = f"""你是一个资深股票分析师。请对股票{code}做一个完整的9维矩阵分析。
当前数据:大盘={_macro_desc or "震荡"} | PE/市值={_pe_val} {_pb_val} | 价格={price} 区间={entry.get("entry_low",0)}~{entry.get("entry_high",0)} 止损={entry.get("stop_loss",0)} 止盈={entry.get("take_profit",0)} RR={result.get("rr_ratio",entry.get("rr_ratio",0))} | 信号={result.get("timing_signal") or entry.get("timing_signal","")} | 行业={(result.get("sector_context") or entry.get("sector_context",""))[:50]}
⚠️ 重要:9个维度必须交叉对比,找出矛盾/共振点,给出综合判断。
当前数据(实时API,禁止使用模型训练数据):
大盘={_macro_desc or "震荡"} | PE/市值={_pe_val} {_pb_val} | 价格={price} 区间={entry.get("entry_low",0)}~{entry.get("entry_high",0)} 止损={entry.get("stop_loss",0)} 止盈={entry.get("take_profit",0)} RR={result.get("rr_ratio",entry.get("rr_ratio",0))} | 信号={result.get("timing_signal") or entry.get("timing_signal","")} | 行业={(result.get("sector_context") or entry.get("sector_context",""))[:50]}
策略={(result.get("action") or entry.get("action",""))[:200]}
技术={(result.get("tech_snapshot") or entry.get("tech_snapshot",""))[:200]}
资金流={_flow_note}
消息面={_news_note}
格式:①大盘×基本面 ②大盘×消息面 ③大盘×技术面 ④大盘×资金流 ⑤行业×基本面 ⑥行业×消息面 ⑦行业×技术面 ⑧个股×基本面 ⑨个股×消息面
格式:
【交叉分析】哪些维度矛盾/共振,关键信号
① 大盘×基本面 ② 大盘×消息面 ③ 大盘×技术面 ④ 大盘×资金流
⑤ 行业×基本面 ⑥ 行业×消息面 ⑦ 行业×技术面
⑧ 个股×基本面 ⑨ 个股×消息面
最后必须输出:
【综合结论】(买入/关注/观望/卖出)