现金冻结修复:price_monitor不再重算cash

根因:price_monitor每2分钟用av+fz重算cash,
但av/fz是旧数据(含法拉电子卖出前冻结),
覆盖了Dad交易截图后的正确现金92,679。

修复:
1. price_monitor只更新market_value,不碰cash
2. cash设回正确值92,678.85(含法拉电子+18,920)
3. 加cash_history追踪每次修改
This commit is contained in:
知微
2026-06-29 22:24:12 +08:00
parent 0b0323eb23
commit 5a2d616dfd
2 changed files with 25 additions and 26 deletions
+9 -19
View File
@@ -199,32 +199,22 @@ def refresh_data_prices():
json.dump(wl, open(WATCHLIST_PATH, 'w'), ensure_ascii=False, indent=2)
# --- 汇总值重算(2026-06-29 bugfix: 之前price_monitor只更新个股价,不更新汇总)---
# total_market_value / total_assets / cash / position_pct 来自import_holding_xls快照
# 价格更新后必须同步刷新汇总,否则报告使用过期汇总 → 现金/资产/仓位全错
try:
live_market_value = sum(
h.get('shares', 0) * h.get('price', 0)
for h in pf.get('holdings', [])
)
# 现金:优先用经过Dad截图确认的可用+冻结字段
# 2026-06-29 bugfix: 之前从strategy_staleness_report读现金(循环依赖→值被污染)
# 正确公式: 总现金 = 可用现金(截图确认) + 冻结资金(截图确认)
av = pf.get('available_cash', pf.get('_available_cash', 0))
fz = pf.get('frozen_cash', pf.get('_frozen_cash', 0))
if av > 0 or fz > 0:
total_cash = round(av + fz, 2)
else:
# fallback: 从 stale_report 读
try:
sr = json.load(open('/home/hmo/web-dashboard/data/strategy_staleness_report.json'))
total_cash = sr.get('portfolio', {}).get('cash', 0)
except:
total_cash = pf.get('cash', 0)
old_cash = pf.get('cash', 0)
if abs(old_cash - total_cash) > 0.01:
pf['cash'] = total_cash
# 现金:绝不重算。保留上次的值(来自截图/导入/手动修改)。
# 2026-06-29 bugfix v2: 之前price_monitor用available_cash+frozen_cash重算现金,
# 但截图确认的9.2万被旧冻结数据(3.9万)覆盖=113k,导致cash来回跳
# 修正:price_monitor只更新market_value,不碰cash
old_mv = pf.get('total_mv', 0)
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)
if pf['total_assets'] > 0:
pf['position_pct'] = round(live_market_value / pf['total_assets'] * 100, 2)