补齐币本位期权开平仓微信推送:单位用ETH/BTC,手动/目标/翻倍平仓与翻倍提醒均必达。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -30,7 +30,11 @@ def build_profit_alert_message(
|
||||
upl: float,
|
||||
upl_ratio: float | None,
|
||||
bid: float | None,
|
||||
premium_ccy: str = "USDC",
|
||||
) -> str:
|
||||
from lib.options.options_notify_lib import resolve_premium_ccy
|
||||
|
||||
ccy = resolve_premium_ccy(premium_ccy, inst_id=inst_id)
|
||||
pct = f"{upl_ratio * 100:.1f}%" if upl_ratio is not None else "—"
|
||||
bid_txt = f"{bid:.4f}" if bid is not None else "—"
|
||||
return "\n".join(
|
||||
@@ -38,9 +42,9 @@ def build_profit_alert_message(
|
||||
"【OKX期权·翻倍提醒】",
|
||||
f"账户:{account_label}",
|
||||
f"合约:{inst_id}",
|
||||
f"已付权利金:{premium_paid:.4f} USDC",
|
||||
f"未实现盈亏:{upl:+.4f} USDC({pct})",
|
||||
f"当前买一:{bid_txt}(可考虑限价平仓锁利)",
|
||||
f"已付权利金:{premium_paid:.4f} {ccy}",
|
||||
f"未实现盈亏:{upl:+.4f} {ccy}({pct})",
|
||||
f"当前买一:{bid_txt} {ccy}(可考虑限价平仓锁利)",
|
||||
]
|
||||
)
|
||||
|
||||
@@ -60,14 +64,24 @@ def run_options_profit_alerts(
|
||||
"""
|
||||
sent = 0
|
||||
pos_by_inst = {str(p.get("inst_id") or p.get("instId") or ""): p for p in positions}
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, inst_id, premium_paid, profit_alert_sent
|
||||
FROM options_trades
|
||||
WHERE status = 'open'
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
).fetchall()
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, inst_id, premium_paid, profit_alert_sent, premium_ccy
|
||||
FROM options_trades
|
||||
WHERE status = 'open'
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
).fetchall()
|
||||
except Exception:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, inst_id, premium_paid, profit_alert_sent
|
||||
FROM options_trades
|
||||
WHERE status = 'open'
|
||||
ORDER BY id ASC
|
||||
"""
|
||||
).fetchall()
|
||||
# 同合约多腿加仓:按合约汇总权利金,整仓只告警一次
|
||||
by_inst: dict[str, dict[str, Any]] = {}
|
||||
for row in rows:
|
||||
@@ -76,13 +90,18 @@ def run_options_profit_alerts(
|
||||
continue
|
||||
bucket = by_inst.setdefault(
|
||||
inst_id,
|
||||
{"ids": [], "premium": 0.0, "all_sent": True, "has_prem": False},
|
||||
{"ids": [], "premium": 0.0, "all_sent": True, "has_prem": False, "premium_ccy": None},
|
||||
)
|
||||
bucket["ids"].append(int(row["id"]))
|
||||
prem = _safe_float(row["premium_paid"])
|
||||
if prem is not None:
|
||||
bucket["premium"] += float(prem)
|
||||
bucket["has_prem"] = True
|
||||
if not bucket.get("premium_ccy"):
|
||||
try:
|
||||
bucket["premium_ccy"] = row["premium_ccy"]
|
||||
except (KeyError, IndexError, TypeError):
|
||||
bucket["premium_ccy"] = None
|
||||
if not int(row["profit_alert_sent"] or 0):
|
||||
bucket["all_sent"] = False
|
||||
|
||||
@@ -111,6 +130,7 @@ def run_options_profit_alerts(
|
||||
upl=upl or 0.0,
|
||||
upl_ratio=ratio,
|
||||
bid=bid,
|
||||
premium_ccy=str(bucket.get("premium_ccy") or pos.get("premium_ccy") or ""),
|
||||
)
|
||||
try:
|
||||
send_wechat(msg)
|
||||
@@ -450,6 +470,9 @@ def options_monitor_loop(
|
||||
account_label=account_label,
|
||||
ticker_bid_fn=ticker_bid_fn,
|
||||
)
|
||||
pe_cfg = dict(profit_exit_cfg or {})
|
||||
pe_cfg.setdefault("send_wechat", send_wechat)
|
||||
pe_cfg.setdefault("account_label", account_label)
|
||||
if target_close_fn is not None:
|
||||
from lib.options.options_target_lib import run_options_target_closes
|
||||
|
||||
@@ -459,14 +482,11 @@ 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},
|
||||
cfg=pe_cfg,
|
||||
)
|
||||
if profit_exit_close_fn is not None:
|
||||
from lib.options.options_profit_exit_lib import run_options_profit_exits
|
||||
|
||||
pe_cfg = dict(profit_exit_cfg or {})
|
||||
pe_cfg.setdefault("send_wechat", send_wechat)
|
||||
pe_cfg.setdefault("account_label", account_label)
|
||||
run_options_profit_exits(
|
||||
conn,
|
||||
positions,
|
||||
|
||||
Reference in New Issue
Block a user