Require real ask depth for options and hedge opens.
Block mark-as-ask opens, show reference mark when no depth, cap sheets to ask size; leave close paths unchanged. Document in docs/更新文档.md. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -77,6 +77,11 @@ def _buy_option(
|
||||
sheets: float,
|
||||
dry_run: bool,
|
||||
) -> dict[str, Any]:
|
||||
from lib.exchange.okx_options_lib import (
|
||||
cap_option_buy_sheets_to_ask_depth,
|
||||
option_buy_liquidity_ok,
|
||||
)
|
||||
|
||||
ex = cfg.get("exchange_options")
|
||||
quote_fn = cfg.get("quote_option_contract")
|
||||
place_fn = cfg.get("place_option_limit_order")
|
||||
@@ -89,9 +94,22 @@ def _buy_option(
|
||||
if not q.get("ok"):
|
||||
return {"ok": False, "msg": q.get("msg") or "期权报价失败", "quote": q}
|
||||
ask = q.get("ask")
|
||||
if ask is None or float(ask) <= 0:
|
||||
return {"ok": False, "msg": "暂无卖一价,无法买入"}
|
||||
ask_sz = q.get("ask_sz")
|
||||
can_open, block_msg = option_buy_liquidity_ok(ask, ask_sz)
|
||||
if not can_open:
|
||||
return {
|
||||
"ok": False,
|
||||
"msg": block_msg or q.get("open_block_msg") or "暂无卖一深度,无法买入",
|
||||
"quote": q,
|
||||
"mark": q.get("mark"),
|
||||
"ref_ask": q.get("ref_ask"),
|
||||
"can_open": False,
|
||||
}
|
||||
sheets_i = max(1, int(round(float(sheets))))
|
||||
capped, cap_msg = cap_option_buy_sheets_to_ask_depth(sheets_i, ask_sz, min_sz=1)
|
||||
if capped is None:
|
||||
return {"ok": False, "msg": cap_msg or "卖一深度不足,无法买入", "quote": q}
|
||||
sheets_i = capped
|
||||
ct_mult = float(q.get("ct_mult") or 0.01)
|
||||
premium = float(ask) * sheets_i * ct_mult
|
||||
if dry_run:
|
||||
@@ -101,6 +119,7 @@ def _buy_option(
|
||||
"inst_id": inst_id,
|
||||
"sheets": sheets_i,
|
||||
"ask": float(ask),
|
||||
"ask_sz": float(ask_sz),
|
||||
"premium": premium,
|
||||
"ct_mult": ct_mult,
|
||||
"tick_sz": q.get("tick_sz"),
|
||||
@@ -108,6 +127,7 @@ def _buy_option(
|
||||
"strike": q.get("strike"),
|
||||
"exp_time": q.get("exp_time"),
|
||||
"opt_type": (q.get("meta") or {}).get("optType") or q.get("opt_type"),
|
||||
"can_open": True,
|
||||
}
|
||||
if not callable(place_fn):
|
||||
return {"ok": False, "msg": "期权限价下单未注入"}
|
||||
@@ -130,6 +150,7 @@ def _buy_option(
|
||||
"inst_id": inst_id,
|
||||
"sheets": sheets_i,
|
||||
"ask": float(ask),
|
||||
"ask_sz": float(ask_sz),
|
||||
"premium": premium,
|
||||
"ct_mult": ct_mult,
|
||||
"tick_sz": q.get("tick_sz"),
|
||||
@@ -139,6 +160,7 @@ def _buy_option(
|
||||
"opt_type": (q.get("meta") or {}).get("optType") or q.get("opt_type"),
|
||||
"exchange_ord_id": (order.get("data") or {}).get("ordId"),
|
||||
"order": order,
|
||||
"can_open": True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<label>张数 <span class="hp-unit">期权张</span> <input type="number" step="1" min="1" id="hp-sheets" value="1" /></label>
|
||||
<span class="muted" id="hp-premium-line"></span>
|
||||
</div>
|
||||
<p class="muted hp-unit-hint">单位说明:权利金结算币=<strong>USDC</strong> · 张数=期权张(整张) · 卖一/买一=价格/张</p>
|
||||
<p class="muted hp-unit-hint">单位说明:权利金结算币=<strong>USDC</strong> · 张数=期权张(整张) · 卖一/买一=价格/张.期权买入仅认真实卖一价且卖一深度>0;无深度不可开仓(链上~为参考估算).</p>
|
||||
<div id="hp-opt-bal-line" class="muted hp-quote-line hp-opt-bal-line"></div>
|
||||
<div class="form-row hp-action-row">
|
||||
<button type="button" class="primary" id="hp-preview-btn">计算</button>
|
||||
|
||||
Reference in New Issue
Block a user