币本位期权开仓/翻倍提醒/翻倍平仓/目标平仓/手动平仓微信推送:按ETH/BTC计价并补齐全平必发
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -309,6 +309,11 @@ def _notify_target_close(
|
||||
conn: Any = None,
|
||||
) -> None:
|
||||
"""目标位平仓推送:优先走统一平仓必发(幂等);无 cfg 时回退旧文案."""
|
||||
from lib.options.options_notify_lib import resolve_options_premium_ccy
|
||||
|
||||
ccy = resolve_options_premium_ccy(inst_id=inst_id)
|
||||
d = 6 if ccy in ("ETH", "BTC") else 4
|
||||
mode = "币本位" if ccy != "USDC" else "USDC"
|
||||
if result.get("fully_closed") or result.get("already_flat"):
|
||||
if cfg is not None:
|
||||
try:
|
||||
@@ -324,23 +329,28 @@ def _notify_target_close(
|
||||
close_quote=result.get("locked_bid_px") or result.get("bid"),
|
||||
target_index=target,
|
||||
trigger_idx=idx,
|
||||
premium_ccy=ccy,
|
||||
)
|
||||
# 无论首次/幂等跳过,全平路径不再走下方 fallback,避免重复推
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
if not send_wechat:
|
||||
return
|
||||
try:
|
||||
recv = result.get("premium_received")
|
||||
recv_txt = f"{float(recv):.{d}f} {ccy}" if recv is not None else f"— {ccy}"
|
||||
send_wechat(
|
||||
"\n".join(
|
||||
[
|
||||
"【OKX期权·目标位平仓】",
|
||||
f"账户:{account_label}",
|
||||
f"本位:{mode}",
|
||||
f"合约:{inst_id}",
|
||||
f"目标指数:{target:g}",
|
||||
f"触发指数:{idx:g}",
|
||||
f"提交张数:{result.get('submitted_sheets') or '—'}",
|
||||
f"预估收回:{result.get('premium_received') if result.get('premium_received') is not None else '—'} USDC",
|
||||
f"预估收回:{recv_txt}",
|
||||
f"状态:{'已全平' if (result.get('fully_closed') or result.get('already_flat')) else '挂单中/部分'}",
|
||||
]
|
||||
)
|
||||
@@ -391,7 +401,7 @@ def run_options_target_closes(
|
||||
cancel_orphans_without_position(conn, live_inst_ids=live_ids)
|
||||
_commit_monitor(conn)
|
||||
|
||||
# 先处理已挂单等待成交的,绝不再发微信
|
||||
# 先处理已挂单等待成交的;首次触发已推过「挂单中」,此处仅在全平时走幂等平仓推送
|
||||
for mon in list_closing_targets(conn):
|
||||
inst_id = str(mon.get("inst_id") or "")
|
||||
if not inst_id:
|
||||
@@ -408,6 +418,18 @@ def run_options_target_closes(
|
||||
if inst_id not in pos_by_inst:
|
||||
mark_monitor(conn, int(mon["id"]), status="expired", message="持仓已平")
|
||||
_commit_monitor(conn)
|
||||
target = _safe_float(mon.get("target_index"))
|
||||
idx = _safe_float(mon.get("trigger_idx"))
|
||||
_notify_target_close(
|
||||
cfg,
|
||||
send_wechat,
|
||||
account_label=account_label,
|
||||
inst_id=inst_id,
|
||||
target=float(target) if target is not None else 0.0,
|
||||
idx=float(idx) if idx is not None else 0.0,
|
||||
result={"already_flat": True, "fully_closed": True, "ok": True},
|
||||
conn=conn,
|
||||
)
|
||||
continue
|
||||
result = close_fn(inst_id)
|
||||
idx = _safe_float(pos_by_inst[inst_id].get("idx_px") or pos_by_inst[inst_id].get("idxPx"))
|
||||
@@ -421,6 +443,17 @@ def run_options_target_closes(
|
||||
message="目标位限价平仓完成",
|
||||
)
|
||||
_commit_monitor(conn)
|
||||
target = _safe_float(mon.get("target_index"))
|
||||
_notify_target_close(
|
||||
cfg,
|
||||
send_wechat,
|
||||
account_label=account_label,
|
||||
inst_id=inst_id,
|
||||
target=float(target) if target is not None else 0.0,
|
||||
idx=float(idx) if idx is not None else 0.0,
|
||||
result={**result, "fully_closed": True},
|
||||
conn=conn,
|
||||
)
|
||||
continue
|
||||
mark_monitor(
|
||||
conn,
|
||||
@@ -464,6 +497,17 @@ def run_options_target_closes(
|
||||
if result.get("already_flat"):
|
||||
mark_monitor(conn, int(mon["id"]), status="expired", trigger_idx=idx, message="持仓已平")
|
||||
_commit_monitor(conn)
|
||||
triggered += 1
|
||||
_notify_target_close(
|
||||
cfg,
|
||||
send_wechat,
|
||||
account_label=account_label,
|
||||
inst_id=inst_id,
|
||||
target=target,
|
||||
idx=idx,
|
||||
result=result,
|
||||
conn=conn,
|
||||
)
|
||||
continue
|
||||
if not result.get("ok"):
|
||||
mark_monitor(
|
||||
|
||||
Reference in New Issue
Block a user