fix: get_hk_rate兜底读fx_rate表锁定值(替代硬编码0.87,偏差1.2%致港币市值漂移) + 归档知微未接上的汇率半成品(fx_rate/lock_daily_rate/mo_models.new)

This commit is contained in:
xxm
2026-08-26 01:36:38 +08:00
parent 3b3ba0e56e
commit a7af05ff03
+15 -3
View File
@@ -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):