修复期权到期结算漏推企业微信:页面同步与模拟盘结算一并通知。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -371,9 +371,47 @@ def sync_open_options_trades(
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if notify_cfg is not None:
|
||||
_notify_recent_unsent_expiry_closes(conn, notify_cfg)
|
||||
return updated
|
||||
|
||||
|
||||
def _notify_recent_unsent_expiry_closes(
|
||||
conn: sqlite3.Connection,
|
||||
notify_cfg: dict[str, Any],
|
||||
*,
|
||||
within_hours: float = 48.0,
|
||||
) -> None:
|
||||
"""页面同步曾漏推时,补发近期到期结算."""
|
||||
try:
|
||||
from lib.options.options_notify_lib import notify_options_close_trade_ids
|
||||
from lib.options.options_time_lib import options_wall_clock_to_ms
|
||||
|
||||
now_ms = int(time.time() * 1000)
|
||||
by_inst: dict[str, list[int]] = {}
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, inst_id, closed_at
|
||||
FROM options_trades
|
||||
WHERE status = 'closed'
|
||||
AND COALESCE(wechat_close_sent, 0) = 0
|
||||
AND COALESCE(signal_note, '') = '到期结算'
|
||||
ORDER BY id DESC
|
||||
LIMIT 20
|
||||
"""
|
||||
).fetchall()
|
||||
for r in rows:
|
||||
closed_ms = options_wall_clock_to_ms(r["closed_at"])
|
||||
if closed_ms is None or now_ms - int(closed_ms) > float(within_hours) * 3600 * 1000:
|
||||
continue
|
||||
inst = str(r["inst_id"] or "")
|
||||
by_inst.setdefault(inst, []).append(int(r["id"]))
|
||||
for ids in by_inst.values():
|
||||
notify_options_close_trade_ids(notify_cfg, conn, ids, reason="到期结算")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def reconcile_live_open_trades(
|
||||
conn: sqlite3.Connection,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user