Use bid-only limit closes when option index targets hit.
Target price is only for monitoring; auto flat waits for 买一 instead of falling back to mark. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -866,10 +866,12 @@
|
||||
return (
|
||||
'<div class="opt-target-row">' +
|
||||
'<span class="opt-target-row-label">委托</span>' +
|
||||
'<input type="number" class="opt-pos-target-input" data-inst="' + inst + '" step="0.1" min="0" placeholder="目标指数价" value="' + tgt + '">' +
|
||||
'<input type="number" class="opt-pos-target-input" data-inst="' + inst + '" step="0.1" min="0" placeholder="监控目标指数" value="' + tgt + '">' +
|
||||
'<button type="button" class="btn-secondary opt-target-set-btn" data-inst="' + inst + '">设定</button>' +
|
||||
'<button type="button" class="btn-secondary opt-target-cancel-btn" data-inst="' + inst + '"' + (armed ? "" : " disabled") + ">取消</button>" +
|
||||
'<span class="muted opt-target-row-hint">' + (armed ? "监控中 · 达价限价平 · 无止损" : "达价限价平 · 无止损 · 到期即止损") + "</span>" +
|
||||
'<span class="muted opt-target-row-hint">' +
|
||||
(armed ? "监控中 · 到位按买一限价平 · 无止损" : "目标=监控指数 · 到位按买一限价平 · 到期即止损") +
|
||||
"</span>" +
|
||||
"</div>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@
|
||||
'<div class="pos-cell opt-pos-cell--close"><span class="pos-label">按买盘回收</span><span class="pos-value">' + fmtClosePreview(closePreview, p.premium_paid, hub) + "</span></div>" +
|
||||
"</div>" +
|
||||
(p.target_index != null
|
||||
? '<div class="opt-target-row opt-target-row--ro"><span class="opt-target-row-label">委托</span><span class="pos-value">目标指数 ' + fmt(p.target_index, 1) + "</span><span class="muted opt-target-row-hint">监控中 · 达价限价平</span></div>"
|
||||
? '<div class="opt-target-row opt-target-row--ro"><span class="opt-target-row-label">委托</span><span class="pos-value">目标指数 ' + fmt(p.target_index, 1) + "</span><span class="muted opt-target-row-hint">监控中 · 到位按买一限价平</span></div>"
|
||||
: "")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""期权目标位委托:指数达价后限价平仓(无止损,到期由结算收口)."""
|
||||
"""期权目标位委托:指数目标价仅用于监控触发;触发后按买一限价平仓(无止损,到期结算)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
@@ -214,7 +214,7 @@ def close_option_by_bid_depth(
|
||||
*,
|
||||
sheets: int | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""按买盘拆分限价卖出(最多5档),供目标位自动平仓复用."""
|
||||
"""目标触发后仅用买一/买盘限价卖出(最多5档);无买一则等待下次轮询,不用标记价."""
|
||||
from lib.exchange.okx_options_lib import (
|
||||
_pos_side_from_position,
|
||||
invalidate_option_positions_cache,
|
||||
@@ -301,22 +301,13 @@ def close_option_by_bid_depth(
|
||||
preview = estimate_close_by_bids(book.get("bids") or [], remaining, ct_mult=ct_mult)
|
||||
levels = preview.get("levels") or []
|
||||
if not levels:
|
||||
# 无买盘时回退:报价买一 → 报价标记价 → 持仓标记价
|
||||
# 无买盘深度时仅允许真实买一价,不用标记价挂单
|
||||
q2 = cfg["quote_option_contract"](ex, inst_id)
|
||||
cur_mark = _safe_float(cur_pos.get("markPx")) if cur_pos else None
|
||||
pos_mark = _safe_float(pos.get("markPx"))
|
||||
fallback_px = (
|
||||
_safe_float(q2.get("bid"))
|
||||
or _safe_float(q2.get("mark_px"))
|
||||
or _safe_float(q.get("bid"))
|
||||
or _safe_float(q.get("mark_px"))
|
||||
or cur_mark
|
||||
or pos_mark
|
||||
)
|
||||
if fallback_px is None or fallback_px <= 0:
|
||||
stopped_reason = "no_bid_depth"
|
||||
bid_px = _safe_float(q2.get("bid")) or _safe_float(q.get("bid"))
|
||||
if bid_px is None or bid_px <= 0:
|
||||
stopped_reason = "no_bid"
|
||||
break
|
||||
levels = [{"sheets": remaining, "px": fallback_px, "fallback": True}]
|
||||
levels = [{"sheets": remaining, "px": bid_px}]
|
||||
level = levels[0]
|
||||
level_sheets = int(level.get("sheets") or 0)
|
||||
level_px = float(level.get("px") or 0)
|
||||
@@ -386,7 +377,11 @@ def close_option_by_bid_depth(
|
||||
"fully_closed": True,
|
||||
}
|
||||
return {"ok": False, "msg": mkt.get("msg") or "市价平仓失败", "stopped_reason": stopped_reason}
|
||||
return {"ok": False, "msg": "暂无可用买盘深度,无法限价平仓", "stopped_reason": stopped_reason}
|
||||
return {
|
||||
"ok": False,
|
||||
"msg": "暂无买一,等待盘口后按买一限价平仓",
|
||||
"stopped_reason": stopped_reason or "no_bid",
|
||||
}
|
||||
|
||||
avg_bid = (total_received / (submitted_sheets * ct_mult)) if submitted_sheets > 0 and ct_mult > 0 else 0
|
||||
prem_recv = round(total_received, 4)
|
||||
|
||||
@@ -87,7 +87,7 @@
|
||||
<span id="opt-est-profit" class="v">—</span>
|
||||
<span class="k">目标杠杆</span>
|
||||
<span id="opt-est-leverage" class="v" title="目标位名义价值÷权利金">—</span>
|
||||
<span class="muted opt-est-note">填写后进入右侧监控;达价限价平仓,无止损,到期即止损</span>
|
||||
<span class="muted opt-est-note">目标价=监控指数;到位后按买一限价平仓;无止损,到期即止损</span>
|
||||
</div>
|
||||
<div class="form-row options-order-mode-row">
|
||||
<label><input type="radio" name="opt-size-mode" value="sheets" checked> 指定张数</label>
|
||||
|
||||
Reference in New Issue
Block a user