fix: 币种normalize——holdings中文币种(人民币/港币)→CNY/HKD,price_monitor校验raise改normalize(脏数据raise杀死整个refresh循环,live_prices停滞70分钟根因)
This commit is contained in:
@@ -469,10 +469,16 @@ def refresh_data_prices():
|
||||
db_holdings.append(h)
|
||||
|
||||
# ── 写 holdings 表 ──
|
||||
# 2026-08-25 币种 normalize(holdings 里是中文"人民币/港币"——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:
|
||||
currency = str(h.get('currency', 'CNY')).upper()
|
||||
if currency not in ('CNY', 'HKD'):
|
||||
raise ValueError(f"非法币种: {currency}")
|
||||
_raw_cur = str(h.get('currency', 'CNY')).strip()
|
||||
currency = _CUR_MAP.get(_raw_cur) or _CUR_MAP.get(_raw_cur.upper())
|
||||
if not currency:
|
||||
print(f"[刷新] {h.get('code')} 币种'{_raw_cur}'无法识别,默认CNY", file=sys.stderr)
|
||||
currency = 'CNY'
|
||||
h['currency'] = currency # normalize 后写回, holdings 表自我修复
|
||||
conn.execute("""
|
||||
INSERT INTO holdings (code, name, shares, cost, price, market_value,
|
||||
change_pct, currency, position_pct, added_at, is_active)
|
||||
|
||||
Reference in New Issue
Block a user