price_monitor 汇总值重算 + total_assets修正
问题:price_monitor每2分钟更新个股价,但不更新 total_market_value/total_assets/cash/position_pct, 这些字段停留在import_holding_xls快照值,已严重过期。 导致报告显示错误的总资产和仓位。 修复: - 每次更新个股价后,实时重算 total_market_value = sum(shares*price) - cash 从 stale_report(Dad截图确认的可用现金)同步 - total_assets = market_value + available_cash + freeze - 避免价格无变化时不触发更新(timeout fallback保留)
This commit is contained in:
+14
-1
@@ -116,7 +116,20 @@ def audit_advice(conn):
|
||||
# ── 5. 组合健康 ──
|
||||
def audit_portfolio(conn):
|
||||
try:
|
||||
pos = conn.execute("SELECT SUM(position_pct) FROM holdings WHERE is_active=1").fetchone()[0] or 0
|
||||
# 优先从 portfolio.json 读总仓位(更准确,基于实际市值/总资产)
|
||||
pj_path = WEB_DATA / "portfolio.json"
|
||||
if not pj_path.exists():
|
||||
pj_path = DATA_DIR / "portfolio.json"
|
||||
if pj_path.exists():
|
||||
pj = json.loads(pj_path.read_text())
|
||||
pos = pj.get("position_pct", 0)
|
||||
cash = pj.get("cash", 0)
|
||||
available = pj.get("available_cash", cash)
|
||||
else:
|
||||
# 兜底:SQLite position_pct 之和
|
||||
pos = conn.execute("SELECT SUM(position_pct) FROM holdings WHERE is_active=1").fetchone()[0] or 0
|
||||
available = 0
|
||||
|
||||
log_ok("组合", f"总仓位{pos:.1f}%")
|
||||
if pos > 90:
|
||||
log_issue("组合", "MEDIUM", f"仓位{pos:.1f}%超过90%,现金紧张")
|
||||
|
||||
Reference in New Issue
Block a user