#!/usr/bin/env python3 """fx_rate_daily.py — 每日汇率采集(收盘后锁定当日汇率) 调度:每日 16:35(收盘后) 写入:fx_rate 表(is_active=1 的最新记录) 逻辑:调 hk_rate.refresh_rate() → API → 写 fx_rate 表 + 缓存 """ import os, sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) try: from messenger import install_stdio_hook as _msh _msh() except Exception: pass def main(): print(f"[fx_rate_daily] {__import__('datetime').datetime.now():%Y-%m-%d %H:%M} 开始", flush=True) try: from hk_rate import refresh_rate rate = refresh_rate() print(f"[fx_rate_daily] 汇率刷新完成: HKD/CNY = {rate}", flush=True) # 验证 fx_rate 表已更新 import sqlite3 conn = sqlite3.connect("/home/hmo/MoFin/data/mofin.db", timeout=10) r = conn.execute( "SELECT rate, source, created_at FROM fx_rate " "WHERE currency_pair='HKD_CNY' AND is_active=1 ORDER BY id DESC LIMIT 1" ).fetchone() conn.close() if r: print(f"[fx_rate_daily] fx_rate 表确认: rate={r[0]} source={r[1]} {r[2]}", flush=True) else: print(f"[fx_rate_daily] ⚠️ fx_rate 表无 active 记录", flush=True) except Exception as e: print(f"[fx_rate_daily] ❌ 失败: {e}", flush=True) sys.exit(1) if __name__ == "__main__": main()