fix: 币种normalize——holdings中文币种(人民币/港币)→CNY/HKD,price_monitor校验raise改normalize(脏数据raise杀死整个refresh循环,live_prices停滞70分钟根因)

This commit is contained in:
xxm
2026-08-25 14:27:39 +08:00
parent e781f7fe47
commit 320859e48b
+9 -3
View File
@@ -469,10 +469,16 @@ def refresh_data_prices():
db_holdings.append(h) db_holdings.append(h)
# ── 写 holdings 表 ── # ── 写 holdings 表 ──
# 2026-08-25 币种 normalizeholdings 里是中文"人民币/港币"——import_holding_xls/trade_capture
# 导入时写入的;旧校验 raise 杀死整个 refresh 循环,live_prices 停滞 70 分钟根因)
_CUR_MAP = {"人民币": "CNY", "港币": "HKD", "CNY": "CNY", "HKD": "HKD", "RMB": "CNY"}
for h in db_holdings: for h in db_holdings:
currency = str(h.get('currency', 'CNY')).upper() _raw_cur = str(h.get('currency', 'CNY')).strip()
if currency not in ('CNY', 'HKD'): currency = _CUR_MAP.get(_raw_cur) or _CUR_MAP.get(_raw_cur.upper())
raise ValueError(f"非法币种: {currency}") if not currency:
print(f"[刷新] {h.get('code')} 币种'{_raw_cur}'无法识别,默认CNY", file=sys.stderr)
currency = 'CNY'
h['currency'] = currency # normalize 后写回, holdings 表自我修复
conn.execute(""" conn.execute("""
INSERT INTO holdings (code, name, shares, cost, price, market_value, INSERT INTO holdings (code, name, shares, cost, price, market_value,
change_pct, currency, position_pct, added_at, is_active) change_pct, currency, position_pct, added_at, is_active)