现金更正:20230元(Dad截图确认) + strategy_lifecycle写回保护

截图显示可用(含天添利)=20,230.10元。之前80,476是错误数据。
strategy_lifecycle.regenerate_all 写portfolio.json时改为 merge现有字段,
不再清空 cash/total_assets/total_pl 等非holdings字段。
这样下次regenerate_all运行时不会丢数据。

现状:
  现金 20,230元 | 市值 930,200元 | 总资产 950,430元
  仓位 97.9% | 累计盈亏 -164,810元
  25只持仓(14A/11H)
This commit is contained in:
知微
2026-06-24 11:33:51 +08:00
parent eb294f05a5
commit b145dd47c3
6 changed files with 1521 additions and 832 deletions
+8 -2
View File
@@ -1716,8 +1716,14 @@ def regenerate_all(stdout=True):
if stdout:
print(f"{name}({code}): {e}")
# 写回数据文件
json.dump(pf, open(PORTFOLIO_PATH, "w"), ensure_ascii=False, indent=2)
# 写回数据文件 — 保留现有字段(现金、总资产等)不丢
try:
existing_pf = json.load(open(PORTFOLIO_PATH))
except Exception:
existing_pf = {}
existing_pf["holdings"] = pf.get("holdings", [])
existing_pf["updated_at"] = datetime.now().strftime('%Y-%m-%d %H:%M')
json.dump(existing_pf, open(PORTFOLIO_PATH, "w"), ensure_ascii=False, indent=2)
json.dump(wl, open(WATCHLIST_PATH, "w"), ensure_ascii=False, indent=2)
# 写 decisions.json