From 320859e48bee50e1eaee25ddf217d0b2f212ac10 Mon Sep 17 00:00:00 2001 From: xxm Date: Tue, 25 Aug 2026 14:27:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B8=81=E7=A7=8Dnormalize=E2=80=94?= =?UTF-8?q?=E2=80=94holdings=E4=B8=AD=E6=96=87=E5=B8=81=E7=A7=8D(=E4=BA=BA?= =?UTF-8?q?=E6=B0=91=E5=B8=81/=E6=B8=AF=E5=B8=81)=E2=86=92CNY/HKD,price=5F?= =?UTF-8?q?monitor=E6=A0=A1=E9=AA=8Craise=E6=94=B9normalize(=E8=84=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AEraise=E6=9D=80=E6=AD=BB=E6=95=B4=E4=B8=AArefr?= =?UTF-8?q?esh=E5=BE=AA=E7=8E=AF,live=5Fprices=E5=81=9C=E6=BB=9E70?= =?UTF-8?q?=E5=88=86=E9=92=9F=E6=A0=B9=E5=9B=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/price_monitor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/deploy/profile-scripts/price_monitor.py b/deploy/profile-scripts/price_monitor.py index a9105ff6..7ba00e24 100644 --- a/deploy/profile-scripts/price_monitor.py +++ b/deploy/profile-scripts/price_monitor.py @@ -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)