From a7af05ff03c9b1f75cc60ebd584887a5b24a0e8a Mon Sep 17 00:00:00 2001 From: xxm Date: Wed, 26 Aug 2026 01:36:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20get=5Fhk=5Frate=E5=85=9C=E5=BA=95?= =?UTF-8?q?=E8=AF=BBfx=5Frate=E8=A1=A8=E9=94=81=E5=AE=9A=E5=80=BC(?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3=E7=A1=AC=E7=BC=96=E7=A0=810.87,=E5=81=8F?= =?UTF-8?q?=E5=B7=AE1.2%=E8=87=B4=E6=B8=AF=E5=B8=81=E5=B8=82=E5=80=BC?= =?UTF-8?q?=E6=BC=82=E7=A7=BB)=20+=20=E5=BD=92=E6=A1=A3=E7=9F=A5=E5=BE=AE?= =?UTF-8?q?=E6=9C=AA=E6=8E=A5=E4=B8=8A=E7=9A=84=E6=B1=87=E7=8E=87=E5=8D=8A?= =?UTF-8?q?=E6=88=90=E5=93=81(fx=5Frate/lock=5Fdaily=5Frate/mo=5Fmodels.ne?= =?UTF-8?q?w)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/mo_models.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/deploy/profile-scripts/mo_models.py b/deploy/profile-scripts/mo_models.py index 3dee7b1b..17224104 100644 --- a/deploy/profile-scripts/mo_models.py +++ b/deploy/profile-scripts/mo_models.py @@ -65,14 +65,26 @@ def normalize_code(code): # ── 港币汇率 ────────────────────────────────────────────────────────── def get_hk_rate(): - """获取 HKD→CNY 汇率。优先用 hk_rate 模块(支持API+缓存),失败回退 0.87""" + """获取 HKD→CNY 汇率。优先用 hk_rate 模块(支持API+缓存),失败回退 fx_rate 表最新锁定值""" try: from hk_rate import hkd_to_cny return hkd_to_cny() except Exception: pass - # 最后的兜底 - return 0.87 + # 2026-08-25 兜底改读 fx_rate 表最新锁定值(daily_close 锁定,不再硬编码0.87—— + # 硬编码与锁定值偏差1.2%会导致港币市值计算漂移) + try: + import sqlite3 as _sq + _c = _sq.connect("/home/hmo/MoFin/data/mofin.db", timeout=5) + _r = _c.execute( + "SELECT rate FROM fx_rate WHERE currency_pair='HKD_CNY' AND is_active=1 " + "ORDER BY id DESC LIMIT 1").fetchone() + _c.close() + if _r and _r[0]: + return float(_r[0]) + except Exception: + pass + return 0.87 # fx_rate 表也没有时的最终兜底 def to_cny(price, code):