cash/总资产循环依赖修复
问题:price_monitor从strategy_staleness_report读cash→ stale_report由stale_push_wlin从portfolio.json写cash→ 循环依赖导致cash值被污染(92,678→正确的应是113,240) 修复: 1. price_monitor改成优先用available_cash+frozen_cash字段 (来自Dad截图确认值),不再从stale_report读 2. portfolio.json清理重复字段,统一用available_cash+frozen_cash 3. total_assets = total_market_value + available + frozen 4. 正确的数:市值835,552+可用73,758+冻结39,481=总资产948,792
This commit is contained in:
+17
-15
@@ -206,24 +206,26 @@ def refresh_data_prices():
|
||||
h.get('shares', 0) * h.get('price', 0)
|
||||
for h in pf.get('holdings', [])
|
||||
)
|
||||
# 从 stale_report 读可用现金(Dad截图确认值)
|
||||
stale_cash = 0
|
||||
try:
|
||||
sr = json.load(open('/home/hmo/web-dashboard/data/strategy_staleness_report.json'))
|
||||
fallback_cash = pf.get('cash', 0) or 0
|
||||
stale_cash = sr.get('portfolio', {}).get('cash', fallback_cash)
|
||||
except:
|
||||
stale_cash = pf.get('cash', 0) or 0
|
||||
|
||||
old_mv = pf.get('total_market_value', 0)
|
||||
if abs(old_mv - live_market_value) > 0.01:
|
||||
pf['total_market_value'] = round(live_market_value, 2)
|
||||
# 现金:优先用经过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 - stale_cash) > 0.01:
|
||||
pf['cash'] = stale_cash
|
||||
if abs(old_cash - total_cash) > 0.01:
|
||||
pf['cash'] = total_cash
|
||||
|
||||
pf['total_assets'] = round(live_market_value + stale_cash, 2)
|
||||
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)
|
||||
pf['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
Reference in New Issue
Block a user