feat: mo_data.py unified read layer (DB-first, JSON fallback) + cash_log table + batch JSON→DB migration (16 files)

This commit is contained in:
知微
2026-07-01 23:45:30 +08:00
parent 864d924012
commit 6305204c7a
52 changed files with 16351 additions and 11643 deletions
+3 -2
View File
@@ -12,6 +12,7 @@
import json, sys
from datetime import datetime, timezone
from mo_data import read_portfolio, read_decisions, read_watchlist
DATA_DIR = "/home/hmo/web-dashboard/data"
PORTFOLIO_PATH = f"{DATA_DIR}/portfolio.json"
@@ -22,7 +23,7 @@ issues = []
# ── 1. 总资产校验 ────────────────────────────────────────────
try:
pf = json.load(open(PORTFOLIO_PATH))
pf = mo_data.read_portfolio()
mv_calc = sum(h["shares"] * h["price"] for h in pf.get("holdings", []) if h.get("price"))
stored_ta = pf.get("total_assets", 0)
cash = pf.get("cash", 0)
@@ -35,7 +36,7 @@ except Exception as e:
# ── 2. 持仓 vs 决策交叉检查 ──────────────────────────────────
try:
dec = json.load(open(DECISIONS_PATH))
dec = mo_data.read_decisions()
dec_codes = {}
for d in dec.get("decisions", []):
dec_codes[d["code"]] = d