总资产修正+购车图标联动

Fix1: 总资产错误 — HK市价被当人民币算
  portfolio.json已有正确 total_assets(含港币→人民币换算),
  改为直接读取该字段,不再手动累加持仓市值
  原代码用 h.get('currency')=='HKD' 判断但strategy_lifecycle
  格式不保存currency字段 → 所有HK持仓被当CNY计算 → 总资产多出6.8万

Fix2: 换仓推荐时显示🛒⚠️
  原来用 lots==0 判断→永远⚠️,换仓推荐可让操作变为可行
  改为 lots>0 OR swap_text 时用 🛒(可操作)
This commit is contained in:
知微
2026-06-24 13:02:30 +08:00
parent 9ba21fc3c0
commit b5b0f3d0e8
5 changed files with 113 additions and 97 deletions
+12 -8
View File
@@ -318,12 +318,16 @@ def main():
with open("/home/hmo/web-dashboard/data/portfolio.json") as f:
pf = json.load(f)
available_cash = pf.get("cash", 0) or 0
for h in pf.get("holdings", []):
mv = h.get("shares", 0) * h.get("price", 0)
if h.get("currency") == "HKD":
mv *= h.get("exchange_rate", 0.866)
total_assets += mv
total_assets += available_cash
# 直接取 portfolio.json 的总资产(导入时已做港币→人民币换算)
total_assets = pf.get("total_assets", 0) or 0
if total_assets <= 0:
# fallback: 手动算
for h in pf.get("holdings", []):
mv = h.get("shares", 0) * h.get("price", 0)
if len(str(h.get("code", ""))) <= 5: # 港股
mv *= 0.866
total_assets += mv
total_assets += available_cash
except Exception:
total_assets = available_cash * 5 # fallback
@@ -610,8 +614,6 @@ def main():
if cooled:
continue
action_tag = "⚠️" if lots == 0 else "🛒"
# 换仓评估:现金不足时评估是否卖差票换推荐股
swap_text = None
if lots == 0:
@@ -620,6 +622,8 @@ def main():
total_assets, available_cash, pf, code_data
)
action_tag = "🛒" if (lots > 0 or swap_text) else "⚠️"
lines.append(
f" {action_tag} {name}({code}) {pfx}{price:.2f} 买区{buy_low}~{buy_high} | "
f"1手{lot:,.0f}元 RR={rr:.1f}{sl}{tp}\n"