Send WeChat alerts on OKX options open and close.

Cover manual, target, and exchange/expiry sync with idempotent sent flags.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-24 00:48:15 +08:00
parent 54f1857fa2
commit ca499c6104
7 changed files with 475 additions and 2 deletions
+20
View File
@@ -237,6 +237,7 @@ def sync_open_options_trades(
*,
live_inst_ids: set[str],
fetch_history_fn: Callable[[str], list[dict[str, Any]]],
notify_cfg: dict[str, Any] | None = None,
) -> int:
"""
交易所已无持仓时,将本地 open 记录同步为 closed.
@@ -319,6 +320,24 @@ def sync_open_options_trades(
),
)
updated += 1
if notify_cfg is not None:
try:
from lib.options.options_notify_lib import notify_options_close
reason = "到期结算" if close_reason == "expired" else "交易所平仓"
notify_options_close(
notify_cfg,
conn,
inst_id=inst_id,
reason=reason,
trade_id=int(row["id"]),
premium_paid=paid,
premium_received=prem_recv,
realized_pnl=realized_pnl,
close_quote=close_quote,
)
except Exception:
pass
return updated
@@ -414,6 +433,7 @@ def options_monitor_loop(
close_fn=target_close_fn,
send_wechat=send_wechat,
account_label=account_label,
cfg={"send_wechat": send_wechat, "account_label": account_label},
)
if sync_trades_fn is not None:
sync_trades_fn(conn)