price_monitor 汇总值重算 + total_assets修正

问题:price_monitor每2分钟更新个股价,但不更新
total_market_value/total_assets/cash/position_pct,
这些字段停留在import_holding_xls快照值,已严重过期。
导致报告显示错误的总资产和仓位。

修复:
- 每次更新个股价后,实时重算 total_market_value = sum(shares*price)
- cash 从 stale_report(Dad截图确认的可用现金)同步
- total_assets = market_value + available_cash + freeze
- 避免价格无变化时不触发更新(timeout fallback保留)
This commit is contained in:
知微
2026-06-29 20:20:24 +08:00
parent d82de939ff
commit a8d5418726
3 changed files with 59 additions and 4 deletions
+11 -3
View File
@@ -423,12 +423,17 @@ def batch_fetch_prices(codes):
def get_price_tencent(code):
"""获取实时价格,自动识别A股/港股"""
"""获取实时价格,港股转CNY统一存CNY"""
try:
from currency_utils import to_cny, is_hk_stock
except ImportError:
to_cny = lambda v, r=None: v
is_hk_stock = lambda c: len(str(c).strip()) == 5 and str(c).strip().isdigit()
try:
raw_code = code.split('_')[0]
if not raw_code:
return None
if len(raw_code) == 5 and raw_code.isdigit():
if is_hk_stock(raw_code):
prefix = "hk"
elif raw_code.startswith("6") or raw_code.startswith("5"):
prefix = "sh"
@@ -442,8 +447,11 @@ def get_price_tencent(code):
return float(fields[i]) if fields[i].strip() else 0.0
except:
return 0.0
price = f(3)
if is_hk_stock(raw_code) and price > 0:
price = to_cny(price)
return {
"price": f(3), "close": f(4), "high": f(33), "low": f(34),
"price": price, "close": f(4), "high": f(33), "low": f(34),
"code": raw_code,
}
except Exception as e: