Fix option close reduceOnly flag and use position mark when quote has no bid.
OKX expects reduceOnly as the string true; target auto-close also falls back to the live position mark price on empty books. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -793,7 +793,7 @@ def place_option_limit_order(
|
||||
if pos_side:
|
||||
body["posSide"] = pos_side
|
||||
if reduce_only:
|
||||
body["reduceOnly"] = True
|
||||
body["reduceOnly"] = "true"
|
||||
try:
|
||||
resp = ex.private_post_trade_order(body)
|
||||
data = (resp or {}).get("data") or []
|
||||
@@ -829,7 +829,7 @@ def place_option_market_order(
|
||||
if pos_side:
|
||||
body["posSide"] = pos_side
|
||||
if reduce_only:
|
||||
body["reduceOnly"] = True
|
||||
body["reduceOnly"] = "true"
|
||||
try:
|
||||
resp = ex.private_post_trade_order(body)
|
||||
data = (resp or {}).get("data") or []
|
||||
|
||||
@@ -273,9 +273,18 @@ 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:
|
||||
# 无买盘时回退:报价买一 → 标记价 → 再查一次 quote
|
||||
# 无买盘时回退:报价买一 → 报价标记价 → 持仓标记价
|
||||
q2 = cfg["quote_option_contract"](ex, inst_id)
|
||||
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"))
|
||||
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"
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user