clean: 移除早上健康检查/系统审计中的小果残留引用(二次提交—deploy guard恢复旧版后重新应用)

This commit is contained in:
知微
2026-07-21 12:05:43 +08:00
parent 9d3cab2306
commit 34337fc5b7
12 changed files with 694 additions and 328 deletions
BIN
View File
Binary file not shown.
View File
+538
View File
@@ -39,6 +39,14 @@
"close": 13.41,
"volume": 41864386.0,
"amount": 56681.0
},
{
"date": "2026-07-21",
"high": 13.98,
"low": 13.05,
"close": 13.88,
"volume": 21053573.0,
"amount": 28442.0
}
],
"688775": [
@@ -81,6 +89,14 @@
"close": 136.32,
"volume": 4713131.0,
"amount": 63136.0
},
{
"date": "2026-07-21",
"high": 135.31,
"low": 127.44,
"close": 129.94,
"volume": 3284644.0,
"amount": 42769.0
}
],
"688475": [
@@ -165,6 +181,14 @@
"close": 43.0,
"volume": 9254116.0,
"amount": 40066.0
},
{
"date": "2026-07-21",
"high": 45.54,
"low": 42.81,
"close": 45.23,
"volume": 7045084.0,
"amount": 31399.0
}
],
"688501": [
@@ -417,6 +441,14 @@
"close": 20.22,
"volume": 992552.0,
"amount": 2026.0
},
{
"date": "2026-07-21",
"high": 20.52,
"low": 19.98,
"close": 20.47,
"volume": 809558.0,
"amount": 1635.0
}
],
"01088": [
@@ -459,6 +491,14 @@
"close": 43.6,
"volume": 11166601.0,
"amount": 483013474.62
},
{
"date": "2026-07-21",
"high": 43.72,
"low": 42.62,
"close": 43.0,
"volume": 3256797.0,
"amount": 140528469.52
}
],
"688566": [
@@ -501,6 +541,14 @@
"close": 25.25,
"volume": 2923287.0,
"amount": 7436.0
},
{
"date": "2026-07-21",
"high": 25.25,
"low": 23.57,
"close": 24.08,
"volume": 2344451.0,
"amount": 5662.0
}
],
"01211": [
@@ -585,6 +633,14 @@
"close": 15.99,
"volume": 9039229.0,
"amount": 14474.0
},
{
"date": "2026-07-21",
"high": 16.14,
"low": 15.63,
"close": 16.03,
"volume": 4310855.0,
"amount": 6844.0
}
],
"688582": [
@@ -627,6 +683,14 @@
"close": 36.95,
"volume": 9774815.0,
"amount": 37047.0
},
{
"date": "2026-07-21",
"high": 38.13,
"low": 34.86,
"close": 37.95,
"volume": 7028435.0,
"amount": 25791.0
}
],
"01478": [
@@ -711,6 +775,14 @@
"close": 23.23,
"volume": 1436355.0,
"amount": 3390.0
},
{
"date": "2026-07-21",
"high": 23.24,
"low": 22.15,
"close": 22.61,
"volume": 783114.0,
"amount": 1765.0
}
],
"02202": [
@@ -753,6 +825,14 @@
"close": 2.44,
"volume": 13295500.0,
"amount": 32619014.9
},
{
"date": "2026-07-21",
"high": 2.46,
"low": 2.38,
"close": 2.4,
"volume": 7926700.0,
"amount": 19045845.1
}
],
"688692": [
@@ -795,6 +875,14 @@
"close": 216.1,
"volume": 1795104.0,
"amount": 38484.0
},
{
"date": "2026-07-21",
"high": 222.86,
"low": 213.11,
"close": 220.26,
"volume": 1149200.0,
"amount": 25212.0
}
],
"300750": [
@@ -879,6 +967,14 @@
"close": 62.72,
"volume": 1078476.0,
"amount": 6756.0
},
{
"date": "2026-07-21",
"high": 63.64,
"low": 61.55,
"close": 62.61,
"volume": 706654.0,
"amount": 4414.0
}
],
"518880": [
@@ -963,6 +1059,14 @@
"close": 44.91,
"volume": 1781103.0,
"amount": 7823.0
},
{
"date": "2026-07-21",
"high": 46.55,
"low": 44.23,
"close": 46.06,
"volume": 1124450.0,
"amount": 5109.0
}
],
"688779": [
@@ -1005,6 +1109,14 @@
"close": 6.9,
"volume": 37370857.0,
"amount": 25733.0
},
{
"date": "2026-07-21",
"high": 7.08,
"low": 6.81,
"close": 7.0,
"volume": 23142938.0,
"amount": 16082.0
}
],
"300035": [
@@ -1089,6 +1201,14 @@
"close": 47.71,
"volume": 1814330.0,
"amount": 8528.0
},
{
"date": "2026-07-21",
"high": 48.73,
"low": 47.09,
"close": 47.38,
"volume": 933550.0,
"amount": 4448.0
}
],
"600563": [
@@ -1233,6 +1353,14 @@
"close": 144.0,
"volume": 93942500.0,
"amount": 1346494.0
},
{
"date": "2026-07-21",
"high": 156.72,
"low": 140.58,
"close": 155.81,
"volume": 74187978.0,
"amount": 1099957.0
}
],
"688372": [
@@ -1443,6 +1571,14 @@
"close": 8.63,
"volume": 4281284.0,
"amount": 3721.0
},
{
"date": "2026-07-21",
"high": 8.77,
"low": 8.42,
"close": 8.71,
"volume": 3240110.0,
"amount": 2786.0
}
],
"688621": [
@@ -1485,6 +1621,14 @@
"close": 56.88,
"volume": 4638705.0,
"amount": 26217.0
},
{
"date": "2026-07-21",
"high": 57.07,
"low": 53.55,
"close": 54.13,
"volume": 2827015.0,
"amount": 15448.0
}
],
"000850": [
@@ -1721,6 +1865,14 @@
"close": 114.41,
"volume": 1143940.0,
"amount": 12834.0
},
{
"date": "2026-07-21",
"high": 126.0,
"low": 118.94,
"close": 124.29,
"volume": 6616802.0,
"amount": 81734.0
}
],
"688800": [
@@ -1731,6 +1883,14 @@
"close": 63.51,
"volume": 1447347.0,
"amount": 9241.0
},
{
"date": "2026-07-21",
"high": 58.73,
"low": 50.0,
"close": 58.61,
"volume": 13309393.0,
"amount": 72395.0
}
],
"688758": [
@@ -1741,6 +1901,14 @@
"close": 24.79,
"volume": 3826638.0,
"amount": 9338.0
},
{
"date": "2026-07-21",
"high": 25.18,
"low": 22.61,
"close": 25.15,
"volume": 12136498.0,
"amount": 29182.0
}
],
"688289": [
@@ -1761,6 +1929,14 @@
"close": 38.48,
"volume": 1020332.0,
"amount": 3950.0
},
{
"date": "2026-07-21",
"high": 37.72,
"low": 34.81,
"close": 37.68,
"volume": 6324151.0,
"amount": 23002.0
}
],
"688576": [
@@ -1771,6 +1947,14 @@
"close": 38.67,
"volume": 61912.0,
"amount": 239.0
},
{
"date": "2026-07-21",
"high": 36.99,
"low": 34.83,
"close": 36.5,
"volume": 527607.0,
"amount": 1891.0
}
],
"688122": [
@@ -1811,6 +1995,14 @@
"close": 44.58,
"volume": 977623.0,
"amount": 4270.0
},
{
"date": "2026-07-21",
"high": 42.53,
"low": 38.2,
"close": 42.38,
"volume": 4671790.0,
"amount": 18899.0
}
],
"688281": [
@@ -1831,6 +2023,14 @@
"close": 220.22,
"volume": 2634862.0,
"amount": 55058.0
},
{
"date": "2026-07-21",
"high": 223.66,
"low": 211.68,
"close": 211.84,
"volume": 1386950.0,
"amount": 30036.0
}
],
"688606": [
@@ -1841,6 +2041,14 @@
"close": 44.26,
"volume": 544130.0,
"amount": 2421.0
},
{
"date": "2026-07-21",
"high": 44.26,
"low": 42.56,
"close": 43.17,
"volume": 433254.0,
"amount": 1870.0
}
],
"688314": [
@@ -1862,5 +2070,335 @@
"volume": 728146.0,
"amount": 31883.0
}
],
"688526": [
{
"date": "2026-07-21",
"high": 12.87,
"low": 12.64,
"close": 12.78,
"volume": 1019907.0,
"amount": 1297.0
}
],
"688539": [
{
"date": "2026-07-21",
"high": 23.58,
"low": 21.36,
"close": 23.58,
"volume": 2668816.0,
"amount": 5996.0
}
],
"688543": [
{
"date": "2026-07-21",
"high": 35.18,
"low": 33.88,
"close": 34.96,
"volume": 4196332.0,
"amount": 14505.0
}
],
"688558": [
{
"date": "2026-07-21",
"high": 25.99,
"low": 23.85,
"close": 25.93,
"volume": 1795891.0,
"amount": 4472.0
}
],
"688569": [
{
"date": "2026-07-21",
"high": 16.4,
"low": 15.94,
"close": 16.15,
"volume": 708010.0,
"amount": 1141.0
}
],
"688580": [
{
"date": "2026-07-21",
"high": 50.26,
"low": 46.18,
"close": 49.36,
"volume": 1555242.0,
"amount": 7462.0
}
],
"688581": [
{
"date": "2026-07-21",
"high": 51.4,
"low": 49.7,
"close": 50.4,
"volume": 408774.0,
"amount": 2061.0
}
],
"688605": [
{
"date": "2026-07-21",
"high": 71.87,
"low": 62.0,
"close": 71.59,
"volume": 7382675.0,
"amount": 49852.0
}
],
"688612": [
{
"date": "2026-07-21",
"high": 28.89,
"low": 26.12,
"close": 28.79,
"volume": 4235793.0,
"amount": 11663.0
}
],
"688616": [
{
"date": "2026-07-21",
"high": 9.73,
"low": 9.1,
"close": 9.54,
"volume": 1902612.0,
"amount": 1789.0
}
],
"688618": [
{
"date": "2026-07-21",
"high": 24.2,
"low": 21.2,
"close": 24.09,
"volume": 3172718.0,
"amount": 7112.0
}
],
"688623": [
{
"date": "2026-07-21",
"high": 55.55,
"low": 53.06,
"close": 54.3,
"volume": 617251.0,
"amount": 3342.0
}
],
"688626": [
{
"date": "2026-07-21",
"high": 43.95,
"low": 40.4,
"close": 42.68,
"volume": 2132067.0,
"amount": 8910.0
}
],
"688648": [
{
"date": "2026-07-21",
"high": 28.58,
"low": 26.66,
"close": 28.36,
"volume": 1502324.0,
"amount": 4155.0
}
],
"688678": [
{
"date": "2026-07-21",
"high": 16.68,
"low": 14.81,
"close": 16.29,
"volume": 15515578.0,
"amount": 24554.0
}
],
"688683": [
{
"date": "2026-07-21",
"high": 25.5,
"low": 22.37,
"close": 25.42,
"volume": 2193071.0,
"amount": 5211.0
}
],
"688689": [
{
"date": "2026-07-21",
"high": 38.46,
"low": 32.27,
"close": 37.7,
"volume": 10503245.0,
"amount": 37306.0
}
],
"688718": [
{
"date": "2026-07-21",
"high": 11.6,
"low": 10.31,
"close": 11.28,
"volume": 2949413.0,
"amount": 3222.0
}
],
"688799": [
{
"date": "2026-07-21",
"high": 47.49,
"low": 43.8,
"close": 46.09,
"volume": 3286201.0,
"amount": 14940.0
}
],
"688805": [
{
"date": "2026-07-21",
"high": 37.21,
"low": 33.51,
"close": 36.27,
"volume": 1330043.0,
"amount": 4655.0
}
],
"688816": [
{
"date": "2026-07-21",
"high": 46.87,
"low": 44.03,
"close": 45.92,
"volume": 330420.0,
"amount": 1495.0
}
],
"688819": [
{
"date": "2026-07-21",
"high": 22.19,
"low": 21.02,
"close": 21.72,
"volume": 3491209.0,
"amount": 7610.0
}
],
"688267": [
{
"date": "2026-07-21",
"high": 16.48,
"low": 15.58,
"close": 16.35,
"volume": 1547669.0,
"amount": 2478.0
}
],
"688318": [
{
"date": "2026-07-21",
"high": 71.5,
"low": 68.33,
"close": 69.5,
"volume": 3873944.0,
"amount": 27085.0
}
],
"688076": [
{
"date": "2026-07-21",
"high": 27.79,
"low": 26.69,
"close": 27.18,
"volume": 2094599.0,
"amount": 5667.0
}
],
"688305": [
{
"date": "2026-07-21",
"high": 53.5,
"low": 50.65,
"close": 53.47,
"volume": 2331843.0,
"amount": 12172.0
}
],
"688315": [
{
"date": "2026-07-21",
"high": 12.86,
"low": 12.19,
"close": 12.57,
"volume": 3031391.0,
"amount": 3780.0
}
],
"688330": [
{
"date": "2026-07-21",
"high": 31.78,
"low": 30.71,
"close": 31.25,
"volume": 753646.0,
"amount": 2345.0
}
],
"688331": [
{
"date": "2026-07-21",
"high": 124.97,
"low": 118.01,
"close": 124.86,
"volume": 5979187.0,
"amount": 72466.0
}
],
"688336": [
{
"date": "2026-07-21",
"high": 43.88,
"low": 40.6,
"close": 42.85,
"volume": 12339535.0,
"amount": 51873.0
}
],
"688410": [
{
"date": "2026-07-21",
"high": 10.34,
"low": 9.71,
"close": 10.13,
"volume": 6328842.0,
"amount": 6336.0
}
],
"688455": [
{
"date": "2026-07-21",
"high": 13.38,
"low": 11.97,
"close": 13.1,
"volume": 2149855.0,
"amount": 2744.0
}
],
"688578": [
{
"date": "2026-07-21",
"high": 128.5,
"low": 122.8,
"close": 126.05,
"volume": 8949608.0,
"amount": 112505.0
}
]
}
+64 -181
View File
@@ -1,30 +1,19 @@
#!/usr/bin/env python3
"""batch_reassess.py — 批量补全12维(九维矩阵)LLM分析(逐只处理,间隔防限流)
"""batch_reassess.py — 批量补全九维分析(逐只处理,间隔防限流)
用法:
python3 batch_reassess.py # 所有缺分析/过期的 active 策略
python3 batch_reassess.py --type holding # 只处理持仓策略
python3 batch_reassess.py --type watchlist # 只处理自选策略
python3 batch_reassess.py --type holding --today # 持仓每日刷新(今早未评过的强制重评)
python3 batch_reassess.py --code XXXXXX # 单只
用法: python3 batch_reassess.py [--all] [--code XXXXXX]
流程:收集最新数据 → 调LLM(gateway)写12维分析+策略 → 保存到DB
流程:收集最新数据 → 调LLM(gateway)写维分析+策略 → 保存到DB
"""
import sys, json, subprocess, sqlite3, re, time, os
import sys, json, subprocess, sqlite3, re, time
from datetime import datetime
# ── 共享 LLM 客户端 + DB 工具(profile-scripts 硬链到同目录)──
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, "/home/hmo/MoFin")
from llm_client import call_llm, REASSESS_MODEL, gateway_alive, ocg_alive
from mofin_db import snapshot_strategy_history
DB = "/home/hmo/MoFin/data/mofin.db"
GATEWAY = "http://127.0.0.1:8643/v1/chat/completions"
COOLDOWN_HOURS = 1
STALE_HOURS = 20 # 分析超过20小时视为过期,需要重评
def has_llm_analysis(code):
"""检查是否为LLM生成的12维分析(>500字)"""
"""检查是否为LLM生成的维分析(>500字)"""
conn = sqlite3.connect(DB)
r = conn.execute("SELECT LENGTH(full_analysis) FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
conn.close()
@@ -44,41 +33,13 @@ def in_cooldown(code):
except:
return False
def analysis_stale(code, force_today=False):
"""分析是否过期(>STALE_HOURS 或 force_today 时今早4点前未重评)"""
conn = sqlite3.connect(DB)
r = conn.execute("SELECT reassessed_at FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
conn.close()
if not r or not r[0]:
return True
try:
last = datetime.fromisoformat(r[0])
if force_today:
today4am = datetime.now().replace(hour=4, minute=0, second=0, microsecond=0)
return last < today4am
return (datetime.now() - last).total_seconds() / 3600 > STALE_HOURS
except:
return True
def get_portfolio():
"""从 portfolio_summary 读实时现金/总资产(不再硬编码)"""
try:
conn = sqlite3.connect(DB)
r = conn.execute("SELECT cash, total_assets FROM portfolio_summary WHERE id=1").fetchone()
conn.close()
if r and r[1]:
return int(r[0] or 0), int(r[1])
except Exception:
pass
return 0, 0
def collect_data(code):
"""收集最新数据(含完整策略原文)"""
"""收集最新数据"""
data = {"code": code}
# 从DB读策略(含 full_analysis / changelog_json / position_advice
# 从DB读策略
conn = sqlite3.connect(DB)
r = conn.execute("SELECT name, entry_low, entry_high, stop_loss, take_profit, timing_signal, action, rr_ratio, tech_snapshot, sector_context, stock_category, full_analysis, changelog_json, reassessed_at, position_advice FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
r = conn.execute("SELECT name, entry_low, entry_high, stop_loss, take_profit, timing_signal, action, rr_ratio, tech_snapshot, sector_context, stock_category FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
if r:
data["name"] = r[0]
data["entry_low"] = r[1] or 0
@@ -91,21 +52,10 @@ def collect_data(code):
data["tech_snapshot"] = r[8] or ""
data["sector_context"] = r[9] or ""
data["stock_category"] = r[10] or ""
data["full_analysis"] = r[11] or ""
data["changelog_json"] = r[12] or ""
data["reassessed_at"] = r[13] or ""
data["position_advice"] = r[14] or ""
conn.close()
# 从腾讯API拉最新价和基本面
# 代码前缀:5位=港股(hk)6/9开头=沪(sh),其他=深(sz)
_c = str(code)
if len(_c) == 5:
prefix = "hk"
elif _c.startswith(("6", "9")):
prefix = "sh"
else:
prefix = "sz"
prefix = "sh" if str(code).startswith(("6","9")) else "sz"
try:
r = subprocess.run(["curl", "-s", f"http://qt.gtimg.cn/q={prefix}{code}"], capture_output=True, timeout=10)
parts = r.stdout.decode("gbk", errors="ignore").split("~")
@@ -130,10 +80,9 @@ def collect_data(code):
return data
def build_prompt(data):
"""构建LLM prompt先审阅原策略再结合实时数据输出修改判断+九维矩阵分析"""
cash, total = get_portfolio()
if not total:
cash, total = 241330, 929727 # 兜底(DB读不到时)
"""构建LLM prompt要求输出完整策略"""
cash = 321271 # 可用现金(从DB读取)
total = 952879 # 总资产
# 拉取资金流数据
_flow_note = "暂无资金流数据"
@@ -173,53 +122,7 @@ def build_prompt(data):
except:
pass
# ── 构建【原策略全文】section ──
_params_parts = []
if data.get('action'): _params_parts.append(f"当前策略: {data['action']}")
if data.get('timing_signal'): _params_parts.append(f"信号: {data['timing_signal']}")
if data.get('entry_low') or data.get('entry_high'):
_params_parts.append(f"买入区间: {data.get('entry_low',0)}~{data.get('entry_high',0)}")
if data.get('stop_loss'): _params_parts.append(f"止损: {data['stop_loss']}")
if data.get('take_profit'): _params_parts.append(f"止盈: {data['take_profit']}")
if data.get('position_advice'): _params_parts.append(f"仓位: {data['position_advice']}")
_params_str = " | ".join(_params_parts) if _params_parts else "无策略参数"
# 最近3条变更记录
_changelog_str = "无变更记录"
try:
_cl_raw = data.get('changelog_json', '')
if _cl_raw:
_cl = json.loads(_cl_raw) if isinstance(_cl_raw, str) else _cl_raw
if isinstance(_cl, list) and _cl:
_recent = _cl[-3:] if len(_cl) > 3 else _cl
_cl_lines = []
for i, c in enumerate(_recent):
_act = c.get('action', c.get('reason', '')) if isinstance(c, dict) else str(c)
_ts = c.get('timestamp', '') if isinstance(c, dict) else ''
_cl_lines.append(f" {i+1}. {_ts[:16]} {_act[:80]}")
if _cl_lines:
_changelog_str = "\n".join(_cl_lines)
except:
pass
# 完整分析原文(不截断)
_full_analysis = data.get('full_analysis', '') or ''
_fa_display = _full_analysis if _full_analysis else '(首次分析,无历史)'
_orig_strategy_section = f"""当前策略参数: {_params_str}
变更记录(最近3条):
{_changelog_str}
完整分析原文:
{_fa_display}"""
return f"""你是一个资深A股分析师。请先审阅以下【原策略全文】,判断是否需要修改策略,然后做出完整的九维矩阵分析。
【原策略全文】
{_orig_strategy_section}
── 以上是已有的策略,以下是当前实时数据,请结合两者做出判断 ──
return f"""你是一个资深A股分析师。请对{data['code']} {data.get('name','')}做一个完整的九维矩阵分析,并输出策略参数。
⚠️ 重要:以下9个维度不是独立分析的,你必须交叉对比后给出综合结论。
例如:如果消息面利好但资金流在流出,说明利好可能是出货;如果基本面强但技术面破位,说明估值可能还没到底。
@@ -233,18 +136,11 @@ PE={data.get('pe','?')}(最新财报) 市值={data.get('mcap','?')}亿
资金流:{_flow_note}(近5日累计)
消息面:{_news_note}(最近3条,自动标注抓取时间)
当前信号:{data.get('timing_signal','?')} 分类:{data.get('stock_category','?')}
原策略:{(data.get('action','') or '')[:200]}
我的总资产={total}元,可用现金={cash}元。
请严格按以下格式输出(注意节标题不可省略)
【维持或修改】明确二选一判断:维持原策略 / 需要修改策略
【修改点及理由】
如果维持原策略 → 写"无需修改"
如果需要修改 → 逐条列出(每条格式:"- 修改点名称:理由说明"
【最终新策略】
用自然语言输出完整的最终策略全文(200-400字),自包含核心交易逻辑、买入区间价格、止损价、止盈价、仓位比例、风险提示。
⚠️ 本段不要使用【综合结论】【买入区间】等标签——用自然语言描述即可。
请严格按以下格式输出:
【交叉分析】用2-3句话说明哪些维度出现矛盾/共振,最关键的信号是什么
① 大盘×基本面 [一句话,说明矛盾关系]
@@ -266,18 +162,13 @@ PE={data.get('pe','?')}(最新财报) 市值={data.get('mcap','?')}亿
【建议止损】数字
【建议止盈】数字
【建议仓位】⚠️不可省略。综合结论非"买入"时写"不新建仓""买入"按以下公式:
【建议仓位】只有综合结论"买入"才输出此项。仓位计算公式:
基础仓位按RR确定:RR<1.5→不推荐,RR1.5~3→8%RR3~5→12%RR5+→15%
大盘偏弱×0.8,大盘偏强×1.15
蓝筹/白马×1.2,成长×0.85,题材/短线×0.6
最终仓位范围:5%~20%
同时考虑:现金{cash}元足够买多少手。
输出格式:"X%(理由:一句话说明为什么这个仓位)"
⚠️ 输出纪律(必须遵守):
1. 直接以【维持或修改】开头,禁止任何寒暄、开场白、分隔线
2. 禁止输出 <structured_data> 或任何 XML/JSON/代码块
3. 所有【】节标题一个都不能少"""
输出格式:"X%(理由:一句话说明为什么这个仓位)"""
def parse_response(text):
"""从LLM回复中提取策略参数"""
result = {"signal": "", "entry_low": 0, "entry_high": 0, "stop_loss": 0, "take_profit": 0, "position": ""}
@@ -326,13 +217,10 @@ def parse_response(text):
return result
def save_result(code, full_text, parsed):
"""保存LLM结果到DB(先快照再UPDATE"""
"""保存LLM结果到DB"""
conn = sqlite3.connect(DB)
now = datetime.now().isoformat()
# ── 修改前快照 ──
snapshot_strategy_history(conn, code, 'batch_12d')
updates = ["full_analysis=?", "reassessed_at=?"]
params = [full_text, now]
@@ -372,111 +260,106 @@ def save_result(code, full_text, parsed):
_tp = parsed.get("take_profit", 0)
_pos = parsed.get("position", "")
_msg = f"📈 {_name}({code}) 价{_p}→12维分析生成买入信号!区间{_el}~{_eh}{_sl}{_tp} 仓位{_pos}"
from alert_helper import notify as _notify, ACTION as _ACT
_notify("买入信号", _msg, _ACT)
print(f" \U0001f4e8 XMPP推送成功: {_msg[:60]}")
import urllib.request, json as _jj
_req = urllib.request.Request("http://127.0.0.1:5805/",
data=_jj.dumps({"body": _msg, "to": "hmo@yoin.fun", "type": "chat"}).encode(),
headers={"Content-Type": "application/json"})
urllib.request.urlopen(_req, timeout=5)
print(f" 📨 XMPP推送成功: {_msg[:60]}")
except Exception as _e:
print(f" \u26a0\ufe0f XMPP推送失败: {_e}")
print(f" ⚠️ XMPP推送失败: {_e}")
conn.close()
def process_stock(code, force_today=False):
def process_stock(code):
"""处理单只股票"""
print(f"\n{'='*50}")
print(f"处理: {code}")
print(f"{'='*50}")
if in_cooldown(code):
print(f" \u23ed 冷却期内,跳过")
if has_llm_analysis(code):
print(f" ⏭ 已有LLM九维分析,跳过")
return False
# 有分析且未过期 \u2192 跳过(除非 force_today 且今早未评)
if has_llm_analysis(code) and not analysis_stale(code, force_today):
print(f" \u23ed 已有12维分析且未过期,跳过")
if in_cooldown(code):
print(f" ⏭ 冷却期内,跳过")
return False
print(f" 收集数据...", flush=True)
data = collect_data(code)
if not data.get("price"):
print(f" \u26a0\ufe0f 无价格数据,跳过")
print(f" ⚠️ 无价格数据,跳过")
return False
print(f" 调LLM生成九维分析...", flush=True)
prompt = build_prompt(data)
# ── 使用共享 LLM 客户端(替代 curl subprocess)──
result = call_llm(prompt, model=REASSESS_MODEL, max_tokens=4096)
try:
r = subprocess.run(["curl", "-s", "--max-time", "300",
"-H", "Content-Type: application/json",
"-H", "Authorization: Bearer hermes123",
"-d", json.dumps({"model":"deepseek-v4-flash","messages":[{"role":"user","content":prompt}],"max_tokens":2048}),
GATEWAY], capture_output=True, timeout=310)
if not result["ok"]:
print(f" \u274c LLM调用失败: {result.get('error','未知错误')}")
if r.returncode != 0:
print(f" ❌ curl失败: {r.stderr.decode()[:100]}")
return False
full_text = result["content"]
print(f" \u2705 LLM返回({len(full_text)}字, {result['elapsed']:.1f}s, 尝试{result['attempts']}次)", flush=True)
resp = json.loads(r.stdout)
if "choices" not in resp:
print(f" ❌ API异常: {str(resp)[:200]}")
return False
full_text = resp["choices"][0]["message"]["content"]
print(f" ✅ LLM返回({len(full_text)}字)", flush=True)
parsed = parse_response(full_text)
print(f" 信号={parsed['signal']} 区间={parsed['entry_low']}~{parsed['entry_high']} 损={parsed['stop_loss']} 盈={parsed['take_profit']} 仓位={parsed['position']}")
save_result(code, full_text, parsed)
print(f" \u2705 已保存到DB")
print(f" 已保存到DB")
return True
def main():
# ── 双通道预检:OCG直连 + hermes gateway 兜底,全挂才退出 ──
_ocg_ok = ocg_alive()
_gw_ok = gateway_alive()
if not _ocg_ok and not _gw_ok:
print("[FATAL] OCG上游与hermes gateway均不可用,退出")
sys.exit(1)
if not _ocg_ok:
print("[WARN] OCG直连不可用,将使用gateway兜底(agent运行时,较慢)")
if not _gw_ok:
print("[WARN] hermes gateway不可用,仅使用OCG直连")
except subprocess.TimeoutExpired:
print(f" ❌ 超时")
return False
except Exception as e:
print(f" ❌ 错误: {e}")
return False
def main():
codes = []
force_today = "--today" in sys.argv
dtype = None
if "--type" in sys.argv:
idx = sys.argv.index("--type")
dtype = sys.argv[idx + 1] # holding | watchlist | all
if "--code" in sys.argv:
idx = sys.argv.index("--code")
codes = [sys.argv[idx+1]]
else:
# 按类型筛选 active 策略
type_map = {"holding": "持仓策略", "watchlist": "自选策略"}
# 所有自选策略
conn = sqlite3.connect(DB)
if dtype in type_map:
rows = conn.execute(
"SELECT code FROM holding_strategies WHERE status='active' AND decision_type=? ORDER BY code",
(type_map[dtype],)).fetchall()
else:
rows = conn.execute(
"SELECT code FROM holding_strategies WHERE status='active' ORDER BY decision_type, code").fetchall()
rows = conn.execute("SELECT code FROM holding_strategies WHERE status='active' AND decision_type='自选策略' ORDER BY code").fetchall()
conn.close()
codes = [r[0] for r in rows]
print(f"待处理: {len(codes)} (type={dtype or 'all'}, force_today={force_today})")
print(f"待处理: {len(codes)}")
ok = 0
fail = 0
skip = 0
for i, code in enumerate(codes):
if has_llm_analysis(code) and not analysis_stale(code, force_today):
print(f" [{i+1}/{len(codes)}] \u23ed {code} 已有12维分析且未过期")
if has_llm_analysis(code):
print(f" [{i+1}/{len(codes)}] {code} 已有LLM分析")
skip += 1
continue
print(f" [{i+1}/{len(codes)}] ", end="", flush=True)
if process_stock(code, force_today):
if process_stock(code):
ok += 1
else:
fail += 1
# 间隔8秒(pro model较重但gateway可承受;retry逻辑吸收瞬断
# 间隔15秒(防gateway过载
if i < len(codes) - 1:
print(f" 等待8秒...", flush=True)
time.sleep(8)
print(f" 等待15秒...", flush=True)
time.sleep(15)
print(f"\n{'='*50}")
print(f"完成: {ok}成功, {fail}失败, {skip}跳过")
+1 -3
View File
@@ -17,9 +17,7 @@ DB_PATH = Path("/home/hmo/MoFin/data/mofin.db")
UA = "Mozilla/5.0"
def get_conn():
c = sqlite3.connect(str(DB_PATH), timeout=30)
c.execute("PRAGMA busy_timeout=30000")
return c
return sqlite3.connect(str(DB_PATH))
def log_candidate(conn, code, stage, passed, detail):
"""记录过滤日志"""
@@ -0,0 +1,7 @@
{
"timestamp": "2026-07-21 11:30",
"source": "ths",
"sector_count": 90,
"xiaoguo_status": "offline",
"note": "小果不在线,未做LLM全市场筛选"
}
+23 -16
View File
@@ -21,26 +21,33 @@ def port_open(port, host="127.0.0.1"):
s.close()
def check_session_health():
"""检测 gateway LLM 是否可用——扫 agent.log 最近一次真实调用结果。
不再发真实 LLM ping25s 超时对 20-100s 的冷启动延迟必误报,且每次白烧 22k token)。
"""
"""gateway API,检测session是否卡死。超过15s无响应→不健康"""
try:
sys.path.insert(0, '/home/hmo/MoFin')
from xmpp_logger import _scan_agent_log
r = _scan_agent_log(time.time(), "zhiwei")
if r["status"] == "ok":
print(f"Session {SESSION_ID} 健康 ✓ (agent.log: latency={r.get('latency')}, {r.get('age_sec')}s前)")
payload = json.dumps({
"model": "hermes-agent",
"messages": [{"role": "user", "content": "ping"}]
}).encode()
req = urllib.request.Request(GATEWAY_URL, data=payload, method="POST")
req.add_header("Content-Type", "application/json")
req.add_header("Authorization", f"Bearer {API_KEY}")
req.add_header("X-Hermes-Session-Id", SESSION_ID)
t0 = time.time()
with urllib.request.urlopen(req, timeout=25) as r:
data = json.loads(r.read())
reply = data.get("choices", [{}])[0].get("message", {}).get("content", "")
elapsed = time.time() - t0
if reply:
print(f"Session {SESSION_ID} 健康 ✓ ({elapsed:.1f}s)")
return True
# error/unknown:只有近期有明确失败记录才判不健康
if r["status"] == "error":
print(f"Session {SESSION_ID} 不健康: agent.log 最近调用失败 — {r.get('error','')[:100]}", file=sys.stderr)
else:
print(f"Session {SESSION_ID} 返回空", file=sys.stderr)
return False
except urllib.request.HTTPError as e:
print(f"Session {SESSION_ID} HTTP错误: {e.code}", file=sys.stderr)
return False
# unknown(无近期调用记录)= 空闲,不算不健康
print(f"Session {SESSION_ID} 无近期调用记录(空闲正常)")
return True
except Exception as e:
print(f"Session {SESSION_ID} 健康检查异常: {e}(按健康处理)", file=sys.stderr)
return True
print(f"Session {SESSION_ID} 健康: {e}", file=sys.stderr)
return False
def restart_gateway():
"""通过systemd重启gateway"""
@@ -59,7 +59,7 @@ def derive_fix_action(detail, msg):
return f"cd {BASE} && echo '需手动设置: cronjob action=update deliver=local'"
# 小果→知微桥不通(小果已归档,不再自动修复)
if "信号桥" in msg:
return None
return None # 小果已归档,信号桥不再使用
return None
@@ -598,9 +598,9 @@ def run_check(item):
elif check_spec == "meta:checklist_completeness":
ok, detail = check_meta_checklist_completeness()
elif check_spec == "pipeline:xiaoguo_signal_flow":
# 小果已归档,管道不再检查
# 小果已归档,管道不再检查
ok = True
detail = "skipped (xiaoguo archived)"
detail = "小果已归档,跳过信号流检查"
elif check_spec == "pipeline:registry_audit":
ok = True
gaps = []
+24 -99
View File
@@ -34,11 +34,8 @@ def _in_cooldown(code):
sys.path.insert(0, "/home/hmo/web-dashboard")
sys.path.insert(0, "/home/hmo/MoFin")
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # profile-scripts 硬链目录
from strategy_lifecycle import reassess_with_context as reassess_strategy
from mo_data import read_decisions, read_portfolio
from llm_client import call_llm, REASSESS_MODEL
from mofin_db import snapshot_strategy_history
def _build_full_analysis(code, entry, result):
@@ -434,76 +431,18 @@ def main():
except:
pass
# ── 拉取已有策略全文 + 最近变更 ──
_existing_full_analysis = ""
_existing_changelog_text = "无变更记录"
try:
_edb = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
_er = _edb.execute(
"SELECT full_analysis, changelog_json FROM holding_strategies "
"WHERE code=? AND status='active'", (code,)
).fetchone()
if _er:
_existing_full_analysis = _er[0] or ""
_cl_raw = _er[1] or ""
if _cl_raw:
_cl = __import__('json').loads(_cl_raw) if isinstance(_cl_raw, str) else _cl_raw
if isinstance(_cl, list) and _cl:
_recent = _cl[-3:]
_existing_changelog_text = "\n".join(
[f" [{c.get('timestamp','?')}] {c.get('action','?')}: {c.get('reason','')}"[:120]
for c in reversed(_recent)]
)
_edb.close()
except:
pass
_prompt = f"""你是一个资深股票分析师。请对股票{code}评估现有策略是否仍然有效,并输出完整的新策略。
╔══════════════════════════════════════════════╗
║ 📋 第一步:审阅原策略 ║
╚══════════════════════════════════════════════╝
【原策略全文】(上次完整分析):
{_existing_full_analysis or '暂无完整策略分析'}
【当前策略参数】:
价格={price} 信号={result.get("timing_signal") or entry.get("timing_signal","")}
买入区间={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("action") or entry.get("action","")}
行业={(result.get("sector_context") or entry.get("sector_context",""))[:50]}(当日实时)
技术={(result.get("tech_snapshot") or entry.get("tech_snapshot",""))[:200]}MA=5/10/20/60日 支撑阻力=近20日 量价=当日+近5日趋势)
【最近变更记录】:
{_existing_changelog_text}
╔══════════════════════════════════════════════╗
║ 📊 第二步:12维矩阵交叉分析 ║
╚══════════════════════════════════════════════╝
_prompt = f"""你是一个资深股票分析师。请对股票{code}做一个完整的12维矩阵分析(3横×4纵:大盘/行业/个股 × 基本面/消息面/技术面/资金面)。
⚠️ 重要:12个维度必须交叉对比,找出矛盾/共振点,给出综合判断。
当前实时数据(每条标注时间窗口,禁止使用模型训练数据):
大盘={_macro_desc or "震荡"}(当日实时) | PE/市值={_pe_val} {_pb_val}(最新财报)
当前数据(实时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]}MA=5/10/20/60日 支撑阻力=近20日 量价=当日+近5日趋势)
资金流={_flow_note}(近5日累计)
消息面={_news_note}(最近3条,自动标注抓取时间)
╔══════════════════════════════════════════════╗
║ 📝 第三步:决策输出 ║
╚══════════════════════════════════════════════╝
请严格按以下顺序输出:
【维持或修改】判断当前策略是否仍然有效,回答「维持」或「修改」。
【修改点及理由】(如果维持,写「无需修改」;如果修改,逐条列出):
- 修改什么参数/方向
- 理由(引用具体维度矛盾或共振)
【最终新策略】(完整策略全文,self-contained,可直接存入DB
格式:
【交叉分析】哪些维度矛盾/共振,关键信号
① 大盘×基本面 ② 大盘×消息面 ③ 大盘×技术面 ④ 大盘×资金面
⑤ 行业×基本面 ⑥ 行业×消息面 ⑦ 行业×技术面 ⑧ 行业×资金面
@@ -513,42 +452,26 @@ def main():
【综合结论】(买入/关注/观望/卖出)
【操作建议】
【建议止损】
【建议止盈】
【建议仓位】⚠️不可省略,非"买入"时写"不新建仓"
⚠️ 输出纪律(必须遵守):
1. 直接以【维持或修改】开头,禁止任何寒暄、开场白、分隔线
2. 禁止输出 <structured_data> 或任何 XML/JSON/代码块
3. 所有【】节标题一个都不能少"""
_full_analysis_text = None
【建议止盈】"""
try:
_llm_result = call_llm(_prompt, max_tokens=4096, timeout=150, retries=1, backoff=20)
if _llm_result["ok"]:
_full_analysis_text = _llm_result["content"]
print(f" ✅ LLM12维分析完成({len(_full_analysis_text)}字, {_llm_result['elapsed']:.1f}s)", flush=True)
else:
print(f" ❌ LLM12维分析失败({_llm_result['attempts']}次): {_llm_result['error'][:200]}", flush=True)
_ur = __import__('urllib.request', fromlist=['Request'])
_req = _ur.Request("http://127.0.0.1:8643/v1/chat/completions",
data=__import__('json').dumps({"model":"deepseek-v4-flash","messages":[{"role":"user","content":_prompt}],"max_tokens":1024}).encode(),
headers={"Content-Type":"application/json","Authorization":"Bearer hermes123"})
_resp = _ur.build_opener(_ur.ProxyHandler({})).open(_req, timeout=300)
_llm_out = __import__('json').loads(_resp.read().decode())["choices"][0]["message"]["content"]
_full_analysis_text = _llm_out
print(f" ✅ LLM12维分析完成({len(_full_analysis_text)}字)", flush=True)
except Exception as _e:
print(f" ❌ LLM12维分析异常: {_e}", flush=True)
print(f" ❌ LLM12维分析失败: {_e}", file=__import__('sys').stderr)
_full_analysis_text = None
# ── 保存到DB(覆写前先快照)──
# 保存到DB
_fa_conn = __import__('sqlite3').connect("/home/hmo/MoFin/data/mofin.db")
if _full_analysis_text:
# 快照旧策略(使用共享函数)
try:
snapshot_strategy_history(_fa_conn, code, "per_stock_12d")
except Exception as _se:
print(f" ⚠️ 快照失败: {_se}", flush=True)
_fa_conn.execute(
"UPDATE holding_strategies SET full_analysis=?, reassessed_at=? WHERE code=? AND status='active'",
(_full_analysis_text, __import__('datetime').datetime.now().isoformat(), code))
_fa_conn.execute("UPDATE holding_strategies SET full_analysis=?, reassessed_at=? WHERE code=? AND status='active'", (_full_analysis_text, __import__('datetime').datetime.now().isoformat(), code))
_fa_conn.commit()
_fa_conn.close()
if _full_analysis_text:
print(f" ✅ 完整12维分析已保存({len(_full_analysis_text)}字)")
else:
print(f" ⚠️ 12维分析未完成,跳过保存")
print(f" ✅ 完整12维分析已保存({len(_full_analysis_text)}字)" if _full_analysis_text else f" ⚠️ 12维分析未完成,跳过保存")
print(f" [DB] holding_strategies 已更新: {code}")
# 从LLM输出提取信号
if _full_analysis_text and '【综合结论】' in _full_analysis_text:
@@ -567,8 +490,10 @@ def main():
"SELECT name, price, entry_low, entry_high, stop_loss, take_profit, position_advice FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
if _nr2:
_xm = f"📈 {_nr2[0] or code}({code}) 价{_nr2[1]}→12维买入信号!区间{_nr2[2]}~{_nr2[3]}{_nr2[4]}{_nr2[5]} 仓位{_nr2[6] or '-'}"
from alert_helper import notify as _notify2, ACTION as _ACT2
_notify2("买入信号", _xm, _ACT2)
_xr = __import__('urllib.request').Request("http://127.0.0.1:5805/",
data=__import__('json').dumps({"body": _xm, "to": "hmo@yoin.fun", "type": "chat"}).encode(),
headers={"Content-Type": "application/json"})
__import__('urllib.request').urlopen(_xr, timeout=5)
print(f" 📨 XMPP推送买入信号")
except: pass
except: pass
+3 -11
View File
@@ -142,7 +142,7 @@ def main():
reassess_scripts.append(code)
print(f"[AUTO_REASSESS] {name}({code}) 价{cur_price:.2f}偏离买入区中心{center:.2f} {drift:+.0f}% → 触发重评")
if reassess_scripts:
# 调用 per_stock_reassess(每轮最多5只,防LLM慢导致整批超时;其余下轮继续)
# 调用 per_stock_reassess
reassess_path = None
for p in ['/home/hmo/MoFin/scripts/per_stock_reassess.py',
'/home/hmo/.hermes/profiles/position-analyst/scripts/per_stock_reassess.py']:
@@ -150,20 +150,12 @@ def main():
reassess_path = p
break
if reassess_path:
MAX_PER_RUN = 5
batch = reassess_scripts[:MAX_PER_RUN]
if len(reassess_scripts) > MAX_PER_RUN:
print(f"[AUTO_REASSESS] 本轮限{MAX_PER_RUN}只,剩余{len(reassess_scripts)-MAX_PER_RUN}只下轮继续")
for code in batch:
try:
# LLM 重评冷启动 20-100sdeepseek-v4-pro 更慢 → 480s
for code in reassess_scripts:
r = subprocess.run(['python3', reassess_path, code],
capture_output=True, text=True, timeout=480)
capture_output=True, text=True, timeout=60)
out = r.stdout.strip()[:200] if r.stdout else ""
err = r.stderr.strip()[:200] if r.stderr else ""
print(f"{code}: exited={r.returncode} {out}")
except subprocess.TimeoutExpired:
print(f"{code}: 超时480s(LLM仍慢),下轮重试")
except Exception as e:
print(f"[AUTO_REASSESS FAIL] {e}")
# ----- 结束 自选股重评 -----
View File
+16
View File
@@ -282,3 +282,19 @@ slixmpp ClientXMPP的`auto_reconnect`属性默认为False。断线(connection_
- divergence_detector.py 手动运行正常输出
- macro_divergence_state.json 已更新到 2026-07-14 11:07,包含8个指数实时数据
- state 自动检测到科创50(-4.2%) vs 恒指(-0.7%) MEDIUM背离信号
## [2026-07-21 11:50] 小果误报清理——盘中自检脚本消除残留引用
### 发现问题
自愈执行器持续报"小果Gateway :8645 未监听"——小果已全线归档,此为残留引用导致的误报。
### 修改内容
- `/home/hmo/MoFin/scripts/intraday_health_check.py`: 用 deploy 版本的干净副本覆盖(移除 check_xiaoguo() 函数、xmpp-xiaoguo.service 检测、8645端口检测、xiaoguo信号堆积检测)
- DB中残留的TODO ID 125/126 已resolve为completed
### 根因
MoFin重构(2026-07-20)时 deploy/profile-scripts/ 已更新但 scripts/ 中源文件未同步,盘中自检写入了小果相关的TODO后,自愈执行器持续处理这些积压TODO。
### 验证
- 运行版本(profile-scripts/)与deploy版本一致,小果引用为零
- DB中小果相关pending/in_progress TODO已清空