Files
MoFin/docs/analyst-knowledge-log.md
T
知微 3e2f0315eb 完全DB版: 移除JSON写入/回退,所有操作直走SQLite
- price_monitor: 完全DB版,不再读写 portfolio.json/watchlist.json
  - holdings代码从DB读取(SELECT code FROM holdings WHERE is_active=1)
  - 价格写入DB holdings表 + portfolio_summary + live_prices
  - 3次重试+指数退避防锁
- server.py: 移除API的JSON回退,DB失败直接返回500
- mofin_db.py: execute_with_retry/commit_with_retry + 15s timeout + busy_timeout
- mo_data.py: 已是纯DB模式(无JSON fallback)

这是推进的完全DB化。下一步可删除 data/portfolio.json data/decisions.json data/watchlist.json 等遗留JSON。
2026-07-06 12:08:08 +08:00

22 lines
1.2 KiB
Markdown
Raw 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.
## 2026-07-06 DB锁+市值错误修复
### 发现的问题
1. **市值错误(586,191 vs 实际619,880+**`mo_data.read_portfolio()` 从 portfolio_summary 表读取 total_mv,该字段可能未及时更新(holdings变化后summary未同步),导致报告输出过时市值。
2. **DB并发锁** — mo_data.py 的 _get_db() 和多个脚本使用 bare sqlite3.connect(),无 timeout/WAL/busy_timeout。多个 cron 并发写入时触发 "database is locked" 错误。
### 修改内容
**mo_data.py:**
- _get_db(): sqlite3.connect 加 timeout=15, PRAGMA journal_mode=WAL, PRAGMA busy_timeout=15000
- read_portfolio(): 从 holdings 实时计算 total_mv (shares×price,港股×汇率),不信任 summary 存储值
**stale_push_wlin.py (2处), multi_timeframe.py (2处), strategy_lifecycle.py (3处), strategy_tree.py (1处):**
- 替换 bare sqlite3.connect() 为 mofin_db.get_conn()(已有 WAL+timeout+退避重试)
### 效果预期
- 市值永远从 holdings 实时计算,不再出现 stale summary 导致的错报
- DB "database is locked" 错误消除(WAL + timeout=15 + busy_timeout=15000
- 所有高频脚本统一走 get_conn(),连接参数一致