178 lines
11 KiB
Markdown
178 lines
11 KiB
Markdown
# MoFin 系统架构梳理 + 查漏补缺报告
|
||
|
||
> 创建:2026-08-12 | 梳理人:小小莫(Sisyphus)
|
||
> 依据:Dashboard「开发原则 → F健康」5 个子 Tab(功能树/Cron/数据实体/数据流/自检体系)+ mofin_health.json 实证
|
||
> 目的:先理解系统底层,发现问题查漏补缺,再谈新策略接入
|
||
|
||
---
|
||
|
||
## 一、系统架构全貌(F健康 5 子 Tab 维度)
|
||
|
||
### 1. 🌳 功能树(5 大功能域)
|
||
|
||
| 功能域 | 子模块 | 核心 cron |
|
||
|--------|--------|-----------|
|
||
| **数据采集** | 市场快照/宏观新闻/价格监控/小果扫描/资金流/宏观上下文 | market_watch(*/10)、price_monitor(*/2)、capital_flow_collector、refresh_macro_context |
|
||
| **策略分析** | 策略重评/新鲜度检查/自选买入区提醒/策略评估/分支自成长/元自成长/分支剪枝/盘前全量重评 | per_stock_reassess、strategy_evaluator、branch_scanner、meta_growth、prune_branches、premarket_full_review |
|
||
| **推荐推送** | 盘前中监控/午后监控/XMPP推送/开盘收盘简报/市场精选推荐/系统体检 | opening_brief、closing_brief、cron_to_xmpp、morning_health_check、preflight_verify |
|
||
| **风险监控** | 宏观风险扫描/信号消费/跨市场背离检测 | 宏观风险扫描(PROMPT)、macro_signal_consumer、divergence_detector |
|
||
| **自检/审计** | 系统审计/cron健康监控/重评管道审计/健康采集/硬编码扫描/盘中自检/数据治理/记忆守卫 | system_audit、mofin_health、verify_reassess_pipeline、intraday_health_check、data_governance、memory_guardian |
|
||
|
||
**关键洞察**:功能树显示系统有完整的"采集→分析→推送→监控→自检"闭环,但**数据采集域缺"全市场日K采集"这一环**(见后述缺口 1)。
|
||
|
||
### 2. 🔧 全部流程/Cron(66 个脚本)
|
||
|
||
按职责分类:
|
||
|
||
| 类别 | 数量 | 代表 |
|
||
|------|------|------|
|
||
| 数据采集类 | 8 | market_watch、price_monitor、capital_flow_collector、refresh_macro_context、macro_context_collector、collect_evaluation_data、refresh_mtf_cache、fundamentals_refresh |
|
||
| 策略扫描类 | 5 | accumulation_scanner、mr_scanner(v_weak)、s2_scanner、**predictive_oversold_scanner**、market_screener |
|
||
| 候选管道类 | 3 | candidate_filter、promote_candidates、watchlist_auto_exit |
|
||
| 策略评估/重评类 | 9 | per_stock_reassess、strategy_evaluator、stale_detector、strategy_review、premarket_full_review、strategy-staleness-check、batch_reassess、review_needed_watchdog、stale_push_wlin |
|
||
| 简报推送类 | 5 | opening_brief、closing_brief、cron_to_xmpp、market_insight、市场精选推荐(PROMPT) |
|
||
| 风险监控类 | 4 | 宏观风险扫描(PROMPT×3)、macro_signal_consumer、divergence_detector |
|
||
| 自成长类 | 3 | branch_scanner、meta_growth、prune_branches |
|
||
| 健康自检类 | 11 | morning_health_check、preflight_verify、system_health_check、intraday_health_check、mofin_health、functional_health_check、system_audit、system_hygiene_audit、hardcode_scanner、verify_reassess_pipeline、data_governance |
|
||
| 元监控/修复类 | 5 | meta_watchdog、self_repair、agent_spiral_watchdog、deploy_guard、self_todo_executor_v2 |
|
||
| 运维类 | 6 | db_daily_backup、vacuum_state_db、memory_guardian、fix_gateway_port、clean_watchlist、monitor_300308×2 |
|
||
|
||
**关键洞察**:**predictive_oversold_scanner 已在 cron**(`35 9 * * 1-5`,2026-08-11 09:18 注册,enabled,last_status ok,今日 09:36 已跑)——调度方式已定为独立 cron,但**数据源有问题**(见后述)。
|
||
|
||
### 3. 🗃️ 数据实体(46 表)
|
||
|
||
核心数据表分类:
|
||
|
||
| 类别 | 表 | 新鲜度 |
|
||
|------|-----|--------|
|
||
| 行情数据 | stock_daily(919万行) / live_prices(394) / mtf_cache / price_events | ⚠️ stock_daily 8月每天仅 122 只更新 |
|
||
| 基本面 | stock_fundamentals(5546) / stock_fundamentals_history(911万) | ✅ 8/11 最新 |
|
||
| 新闻 | stock_news(403万行) | ❌ **8/4 停更(3天前)** |
|
||
| 行业 | sector_index_daily(57.9万) / sector_snapshots / stock_sectors | ❌ **8/4 停更(3天前)** |
|
||
| 市场快照 | market_snapshots / market_regime / macro_context_log | ✅ 8/11 最新 |
|
||
| 资金流 | stock_capital_flow / capital_flow_cache | ✅ 盘中采集 |
|
||
| 策略候选 | candidates(428) / holding_strategies(52) / holdings(18) | ✅ accumulation 活跃 |
|
||
| 回测研究 | strategy_research / strategy_analysis / strategy_health / strategy_lessons / strategy_evolution | ✅ v_weak/v_oversold 已存 |
|
||
| 系统健康 | health_check_log / accuracy_stats / advice_timeline | ✅ 正常 |
|
||
|
||
**关键洞察**:**stock_news 和 sector_index_daily 8/4 停更是硬伤**——直接影响 p_oversold 的 news3 和 sec_ret20 信号质量(用 3 天前数据)。
|
||
|
||
### 4. 🔀 数据流
|
||
|
||
- **价格**:price_monitor → live_prices → 全系统(mo_data.get_price 唯一入口)
|
||
- **持仓**:import_holding_xls → holdings → 策略分析/推送
|
||
- **候选**:scanner → candidates → candidate_filter → promote_candidates → holding_strategies
|
||
- **市场**:market_watch → market_snapshots + market_regime → dashboard/策略门控
|
||
- **板块**:sector_enrich_cninfo → sector_snapshots(但 **sector_index_daily 无采集者**)
|
||
|
||
### 5. 🩺 自检体系(5 层)
|
||
|
||
| 层 | 状态 | 问题 |
|
||
|----|------|------|
|
||
| functional(功能健康) | ❌ **fail** | premarket summary.json 206.5h 未更新 |
|
||
| meta_watchdog(元看门狗) | ✅ ok | - |
|
||
| hygiene(卫生审计) | ⚠️ **warn(13 issues)** | 9 个"指令冻结 session"(旧 SOUL.md 运行的常驻 session)+ 1 个 auto_archive |
|
||
| recent_repairs | - | 指令冻结 session 修复中 |
|
||
| llm_health | ✅ ok | - |
|
||
|
||
---
|
||
|
||
## 二、发现的架构缺失(核心问题)
|
||
|
||
### 🔴 缺口 1:stock_daily 无全市场日K采集 cron
|
||
|
||
**现状**:stock_daily 共 919 万行 / 4272 只 distinct,但分月分布暴露根因——
|
||
- 2026-01~06:每月 4255-4268 只(历史回填撑着)
|
||
- **2026-07:529 只(骤降)**
|
||
- **2026-08:122 只(再降)**
|
||
|
||
**根因**(2026-08-12 实证修正):**从来就没有"全市场日K采集"cron**。stock_daily 唯一 INSERT 写入者是 `migrate_all.py`(一次性数据迁移脚本),`market_screener`/`accumulation_scanner` 均不写,`fetch_tx_klines` 只读不写。6 月的 4268 只是历史回填数据,7 月起只剩 scanner 顺带写的扫描池(529→122 只,在缩)。
|
||
|
||
**影响**:
|
||
- p_oversold 扫描器个股 K 线只能 `fetch_tx_klines` 自己拉腾讯行情(不能读本地)
|
||
- 回测/策略用旧 K 线数据,最新行情缺失
|
||
|
||
**修复建议**:新建全市场日K采集 cron(收盘后 `10 16 * * 1-5`),fetch_tx_klines 批量刷 4000+ 只到 stock_daily(限速+分批+单例守卫+600s 护栏)。
|
||
|
||
### 🔴 缺口 2:stock_news 无采集 cron(8/4 停更)
|
||
|
||
**现状**:stock_news 403 万行(2016-01~2026-08-04),**8/4 停更 3 天**。
|
||
|
||
**根因**:news_collector.py(东财翻页)和 ths_news.py(同花顺)写入者存在且可用(支持 --backfill/--daily),但**均未注册 cron**(66 个 cron 里无 news 相关)。
|
||
|
||
**影响**:p_oversold 的 news3 因子用 3 天前新闻数据,信号质量下降。
|
||
|
||
**修复建议**:注册 news_collector cron(盘前 `0 9 * * 1-5 --daily` 增量 + 周末 `--backfill` 回填),恢复新闻采集。
|
||
|
||
### 🔴 缺口 3:sector_index_daily 无采集 cron(8/4 停更)
|
||
|
||
**现状**:sector_index_daily 57.9 万行(2016-07~2026-08-04),分月分布——
|
||
- 2026-01~06:每月 296 行业(回填撑着)
|
||
- **2026-07:137 行业(腰斩)**
|
||
- **2026-08:8 行业(崩溃)**
|
||
|
||
**根因**:**从未有 INSERT 写入者**(grep insert/executemany/replace/to_sql/append 全无结果)——57.9 万行纯历史回填,之后无人维护,7 月彻底停。
|
||
|
||
**影响**:p_oversold 的 sec_ret20 因子用 3 天前行业数据。
|
||
|
||
**修复建议**:新建 sector_index_daily 采集 cron(收盘后跑),akshare/东财拉 296 行业指数写入(ak.stock_board_industry_summary_ths 已有用法参考 market_watch.py)。
|
||
|
||
### 🟡 缺口 4:functional 自检 premarket fail
|
||
|
||
**现状**:盘前全量重评 premarket summary.json 206.5h 未更新(阈值 1560min),且 premarket_full_review cron last_status=error。
|
||
|
||
**影响**:盘前重评管道断。
|
||
|
||
### 🟡 缺口 5:多个 cron error / hygiene 13 issues
|
||
|
||
- 策略评估-每日(stale_detector)8/6 起 error
|
||
- 市场精选推荐-每日(PROMPT)7/31 起停摆
|
||
- LLM修复循环-L3(self_repair)error
|
||
- 9 个"指令冻结 session"(旧 SOUL.md 常驻 session 需 bump/重启)
|
||
|
||
### 🟢 缺口 6:market.json 残留混乱
|
||
|
||
**现状**:market.json 已标注"已迁移到 DB market_snapshots 表"(7/20),但 server.py 695/798 行 + inject_xiaoguo_insight.py 仍在读写它。
|
||
|
||
**修复建议**:server.py 改读 market_snapshots 表,删除 market.json 残留引用。
|
||
|
||
---
|
||
|
||
## 三、p_oversold 扫描器现状评估
|
||
|
||
**调度**:✅ 已在 cron(独立 9:35 交易日,昨天注册今天已跑,status ok)——事项一已实施
|
||
|
||
**数据源问题**:
|
||
|
||
| 数据 | 当前来源 | 应该来源 | 问题 |
|
||
|------|---------|---------|------|
|
||
| 股票池 | stock_daily distinct(4272 全量) | 同左 | ✅ OK |
|
||
| 个股K线 | fetch_tx_klines 腾讯 | stock_daily | ⚠️ 因缺口1被迫自己拉 |
|
||
| 基本面 | stock_fundamentals | 同左 | ✅ 8/11 最新 |
|
||
| 新闻 news3 | stock_news(8/4 旧) | 同左(需新) | ❌ 因缺口2用旧数据 |
|
||
| 行业 sec_ret20 | sector_index_daily(8/4 旧) | 同左(需新) | ❌ 因缺口3用旧数据 |
|
||
|
||
**结论**:扫描器框架正确(读本地为主),但**缺口 1/2/3 导致 K 线被迫自己拉 + 新闻/行业用旧数据**。修复数据采集层后,扫描器 K 线可改读 stock_daily,信号质量恢复。
|
||
|
||
---
|
||
|
||
## 四、修复优先级建议
|
||
|
||
| 优先级 | 修复项 | 影响 |
|
||
|--------|--------|------|
|
||
| **P0** | 缺口 2/3:注册 stock_news + sector_index_daily 采集 cron | p_oversold 信号质量直接恢复 |
|
||
| **P0** | 缺口 1:注册全市场日K采集 cron(盘后) | p_oversold K线改读本地,摆脱外部依赖 |
|
||
| **P1** | 缺口 4:修 premarket_full_review error | 盘前重评管道恢复 |
|
||
| **P1** | 缺口 6:清理 market.json 残留(server.py 改读 DB) | 数据一致性 |
|
||
| **P2** | 缺口 5:停/修 error cron + 处理 9 个冻结 session | 系统卫生 |
|
||
|
||
---
|
||
|
||
## 五、对 p_oversold 上线的修正结论
|
||
|
||
**之前讨论的事项一(调度方式)**:已实施(独立 cron 9:35),但**时间点需商榷**——若数据采集层修复为盘后跑,扫描器可考虑盘后(用当天完整数据),而非 9:35(用前一天数据)。
|
||
|
||
**先决条件**:**先修复数据采集层 3 大缺口**,再谈 p_oversold 信号质量和上线验证——否则扫描器用的 K线自己拉(不稳定)+ 新闻/行业 3 天前数据(信号失真)。
|
||
|
||
> 本报告基于 mofin_health.json(2026-08-11 22:45 生成)+ 66 cron jobs.json + 46 表实证梳理。
|