price_monitor港股币种修复+calc_total_mv汇兑处理

问题链:
  price_monitor 从东方财富/腾讯拿HK股价(HKD) → x0.87转CNY写portfolio
  → DB存CNY→下游混读→建滔显示-24%浮亏(实为-0.6%)
修复:
  price_monitor不转CNY,港股存HKD原值
  calc_total_mv()增加币种判断:HK股用get_hk_rate()转CNY再汇总
  portfolio.json/watchlist的HK股价全部HKD原值
  DB同步修正所有HK股价格为HKD
  price_monitor DB写入加3次重试+database locked timeout
验证:
  建滔 87.7 HKD 浮亏-0.6%(不是-24%)
  现金 132,121.93 总资产 956,714.68
This commit is contained in:
知微
2026-07-03 10:19:09 +08:00
parent 1bb83c715d
commit 24a73103ed
9 changed files with 765 additions and 1146 deletions
+11 -5
View File
@@ -87,11 +87,17 @@ def to_cny(price, code):
# ── 总资产计算(唯一公式) ────────────────────────────────────────────
def calc_total_mv(holdings):
"""计算持仓总市值(所有价格已为 CNY"""
return round(sum(
(h.get('shares', 0) or 0) * (h.get('price', 0) or 0)
for h in (holdings or [])
), 2)
"""计算持仓总市值。港股 price 为 HKD,需 × 汇率转 CNY"""
total = 0
rate = get_hk_rate()
for h in (holdings or []):
p = (h.get('price', 0) or 0)
s = (h.get('shares', 0) or 0)
if h.get('currency') == 'HKD' or (str(h.get('code','')).startswith(('0','1')) and len(str(h.get('code',''))) == 5):
total += s * p * rate
else:
total += s * p
return round(total, 2)
def calc_total_assets(pf):