完全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。
This commit is contained in:
知微
2026-07-06 12:08:08 +08:00
parent e185b4e4dc
commit 3e2f0315eb
10 changed files with 55 additions and 85 deletions
+2 -20
View File
@@ -140,25 +140,7 @@ def api_overview():
"updated_at": summary.get("updated_at", ""),
})
except Exception:
pass
portfolio = read_portfolio()
market = _load_json(DATA_DIR / "market.json", {})
alerts = _load_json(DATA_DIR / "alerts.json", [])
total_assets = portfolio.get("total_assets", 0)
stock_value = portfolio.get("stock_value", 0)
cash = portfolio.get("cash", 0)
position_pct = portfolio.get("position_pct", 0)
total_pnl = portfolio.get("total_pnl", 0)
holdings = portfolio.get("holdings", [])
top_movers = sorted(
[h for h in holdings if abs(h.get("change_pct", 0)) >= 3],
key=lambda x: abs(x.get("change_pct", 0)), reverse=True)[:5]
return jsonify({
"total_assets": total_assets, "stock_value": stock_value,
"cash": cash, "position_pct": position_pct, "total_pnl": total_pnl,
"top_movers": top_movers, "market": market, "alerts": alerts[:10],
"updated_at": portfolio.get("updated_at", ""),
})
return jsonify({"error": "数据库查询失败"}), 500
@app.route("/api/reports")
@@ -1058,7 +1040,7 @@ def update_realtime():
# 也更新 watchlist.json
wl = read_watchlist()
wl_stocks = {s["code"]: s for s in wl.get("stocks", [])}
wl_stocks = {s["code"]: s for s in wl.get("stocks", [])}
for s in stocks:
code = s.get("code", "")