Commit Graph

2 Commits

Author SHA1 Message Date
hmo 0924cf3124 refactor: 数据层重构 — 统一 SQLite 访问层 + 多脚本双写
新建 mofin_db.py 共享数据库模块:
- get_conn() 统一连接管理 (WAL + Row factory + 外键)
- init_all_tables() 幂等建表 (12张表: market/sector/stock/kline/fundamentals/sectors/holdings/strategies/watchlist/candidates/score_history/events/evaluations)
- write_market_snapshot() 市场快照双写
- write_klines() K线数据双写 (stocks + daily/weekly/monthly + fundamentals)
- write_price_event() 价格事件双写
- migrate_stock_sectors() 一次性迁移 stock_sector_map.json
- query_*() 通用查询函数 (sector_trend/top_inflow/consecutive_inflow/market_mood/db_stats)

重构现有脚本:
- market_watch.py: 删除内联 DB 代码,改用 mofin_db
- multi_timeframe.py: _save_local_history() 加 SQLite 双写
- price_monitor.py: record_event() 加 SQLite 双写
- mofin_query.py: 改用 mofin_db 查询函数

新增:
- migrate_sectors.py: 一次性迁移脚本

清理:
- get_realtime_prices.py: 死代码 (只读 portfolio.json,不调API)
2026-06-20 16:26:17 +08:00
hmo a293119a31 feat: 阶段1 — market_watch 双写 SQLite + 查询工具
- market_watch.py: 新增 init_db() 建表 + write_snapshot() 双写 SQLite
  - market_snapshots: 每次采集的元信息(时间、来源、涨跌比、情绪)
  - sector_snapshots: 每个板块的涨跌幅、资金流向、领涨股等
  - JSON 写入保留不变,SQLite 写入失败不影响 JSON 管道
- mofin_query.py: 通用查询工具
  - 板块趋势查询:「半导体最近5次采集的涨跌幅」
  - 资金流向排行:「净流入最多的5个板块」
  - 连续净流入检测:「最近3天连续净流入的板块」
  - 市场情绪趋势 + 数据库概览
  - 支持直接 SQL 查询
2026-06-20 12:51:02 +08:00