总资产公式修复+数据模型文档

bugfix: price_monitor写total_assets时漏算frozen_cash
  公式修正: total_assets = market_value + cash + frozen_cash
  影响: price_monitor两处公式 + stale_push_wlin fallback路径

docs: portfolio-data-model.md 新增
  数据模型字段说明
  现金流更新规则
  常见错误清单
This commit is contained in:
知微
2026-06-29 22:35:07 +08:00
parent 5a2d616dfd
commit 7d49470aeb
3 changed files with 139 additions and 9 deletions
+10 -3
View File
@@ -167,7 +167,12 @@ def refresh_data_prices():
pf['total_mv'] = round(sum(
h.get('shares',0) * h.get('price',0) for h in pf.get('holdings',[])
), 2)
pf['total_assets'] = round(pf['total_mv'] + pf.get('cash',0), 2)
# total_assets = 持仓市值 + 可用现金 + 冻结资金(缺一不可!2026-06-29 bugfix
# cash = 可用资金(从截图/导入/成交记录来的,price_monitor不动它)
# frozen_cash = 冻结资金(T+2未交收/挂单占用)
available = float(pf.get('cash', 0) or 0)
frozen = float(pf.get('frozen_cash', 0) or 0)
pf['total_assets'] = round(pf['total_mv'] + available + frozen, 2)
json.dump(pf, open(PORTFOLIO_PATH, 'w'), ensure_ascii=False, indent=2)
elif pf.get('updated_at'):
# 即使价格无变化,每10分钟刷新一次updated_at,防健康检查误报
@@ -214,8 +219,10 @@ def refresh_data_prices():
if abs(old_mv - live_market_value) > 0.01:
pf['total_mv'] = round(live_market_value, 2)
total_cash = pf.get('cash', 0) # 保留上次的现金值,不重算
pf['total_assets'] = round(live_market_value + total_cash, 2)
# total_assets = 持仓市值 + 可用现金 + 冻结资金(重复!同步上一处公式)
available = float(pf.get('cash', 0) or 0)
frozen = float(pf.get('frozen_cash', 0) or 0)
pf['total_assets'] = round(live_market_value + available + frozen, 2)
if pf['total_assets'] > 0:
pf['position_pct'] = round(live_market_value / pf['total_assets'] * 100, 2)
pf['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M')