Files
MoFin/deploy/profile-scripts/premarket_full_review.py

84 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""premarket_full_review.py — 盘前全量重评
执行顺序:
1. regenerate_all() 全量技术参数重评(持仓+自选)
2. batch_reassess.py --type holding --today 持仓12维LLM分析(每日强制刷新)
3. watchlist_auto_exit() 自选退出检查
4. 输出摘要
调度:交易日 08:10A股09:30开盘)
"""
import sys, os, json
sys.path.insert(0, '/home/hmo/MoFin')
# Step 0: 持仓对账兜底(每日重评前确认 holdings 与 holding_strategies 对齐)
print("=" * 50)
print("🔄 Step 0: 持仓对账兜底")
print("=" * 50)
try:
from holdings_reconciliation import main as _recon
_recon()
print("✅ 持仓对账完成")
except Exception as e:
print(f"⚠️ 持仓对账失败: {e}(继续重评)")
# Step 1: 全量技术参数重评
print("=" * 50)
print("📊 盘前全量重评开始")
print("=" * 50)
from strategy_lifecycle import regenerate_all
result = regenerate_all(stdout=True)
print(f"\n重评完成: {result.get('ok',0)}/{result.get('total',0)}成功")
# Step 1.5: 持仓 12 维 LLM 深度分析——后台分离执行(12-40分钟,不能阻塞 cron 的 120s 超时)
print("\n" + "=" * 50)
print("🧠 持仓12维LLM分析(后台分离启动)")
print("=" * 50)
import subprocess as _sp
analysis_result = {"mode": "detached"}
try:
_log = open("/tmp/holdings_12d_daily.log", "a")
# 2026-08-19 修复:老莫第4类重评要求"所有池子(自选+持仓)一一重评"
# 原只启动 holding 12维LLM,自选池无盘前LLM重评 → 现在同时启动 holding + watchlist
_sp.Popen(
["python3", "/home/hmo/.hermes/profiles/position-analyst/scripts/batch_reassess.py",
"--type", "holding", "--today"],
stdout=_log, stderr=_log, start_new_session=True)
_sp.Popen(
["python3", "/home/hmo/.hermes/profiles/position-analyst/scripts/batch_reassess.py",
"--type", "watchlist", "--today"],
stdout=_log, stderr=_log, start_new_session=True)
print(" ✅ 持仓+自选12维LLM分析已后台启动(各自落DB,不阻塞盘前流程)")
except Exception as e:
print(f" ⚠️ 12维分析启动失败: {e}")
analysis_result = {"mode": "detached", "error": str(e)[:100]}
# Step 2: 自选退出
print("\n" + "=" * 50)
print("🔍 自选退出检查")
print("=" * 50)
from watchlist_auto_exit import main as auto_exit
# ── 消息通道统一路由(broadcast/xmpp by delivery) ──
try:
from messenger import install_stdio_hook as _msh
_msh()
except Exception:
pass
exited = auto_exit(dry_run=False)
# Step 3: 写入摘要供开盘简报引用
summary = {
"premarket_at": __import__('datetime').datetime.now().isoformat(),
"reassess": result,
"llm_analysis_12d": analysis_result,
"auto_exit": [{"code": c, "name": n, "reason": r} for c, n, s, r in exited],
"total_kept": result.get('total', 0) - len(exited),
}
os.makedirs("/tmp/mofin_premarket", exist_ok=True)
with open("/tmp/mofin_premarket/summary.json", "w") as f:
json.dump(summary, f, ensure_ascii=False, indent=2)
print(f"\n✅ 盘前重评完毕")