Show bid/ask liquidity as price per sheet in options chain.
Display OKX askSz and bidSz beside top-of-book prices in the chain table and order panel using price/sheets format. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -116,18 +116,27 @@ def format_option_px(px: float, tick_sz: Any) -> str:
|
||||
|
||||
|
||||
def _fetch_book_bid_ask(ex: ccxt.okx, inst_id: str) -> tuple[float | None, float | None]:
|
||||
bid, ask, _, _ = _fetch_book_top(ex, inst_id)
|
||||
return bid, ask
|
||||
|
||||
|
||||
def _fetch_book_top(
|
||||
ex: ccxt.okx, inst_id: str
|
||||
) -> tuple[float | None, float | None, float | None, float | None]:
|
||||
try:
|
||||
rows = ex.public_get_market_books({"instId": inst_id, "sz": "1"}).get("data") or []
|
||||
if not rows:
|
||||
return None, None
|
||||
return None, None, None, None
|
||||
row = rows[0]
|
||||
asks = row.get("asks") or []
|
||||
bids = row.get("bids") or []
|
||||
ask = _safe_float(asks[0][0]) if asks else None
|
||||
bid = _safe_float(bids[0][0]) if bids else None
|
||||
return bid, ask
|
||||
ask_sz = _safe_float(asks[0][1]) if asks and len(asks[0]) > 1 else None
|
||||
bid_sz = _safe_float(bids[0][1]) if bids and len(bids[0]) > 1 else None
|
||||
return bid, ask, bid_sz, ask_sz
|
||||
except Exception:
|
||||
return None, None
|
||||
return None, None, None, None
|
||||
|
||||
|
||||
def _pos_side_from_position(pos: dict[str, Any] | None) -> str | None:
|
||||
@@ -338,6 +347,8 @@ def build_option_chain(
|
||||
ask = _safe_float(t.get("askPx"))
|
||||
bid = _safe_float(t.get("bidPx"))
|
||||
mark = _safe_float(t.get("markPx"))
|
||||
ask_sz = _safe_float(t.get("askSz"))
|
||||
bid_sz = _safe_float(t.get("bidSz"))
|
||||
if ask is None and bid is None and mark is None:
|
||||
continue
|
||||
expiry_be = expiry_breakeven_from_ask(
|
||||
@@ -356,6 +367,8 @@ def build_option_chain(
|
||||
"exp_time": exp_ms,
|
||||
"ask": ask,
|
||||
"bid": bid,
|
||||
"ask_sz": ask_sz,
|
||||
"bid_sz": bid_sz,
|
||||
"mark_px": mark,
|
||||
"expiry_be_px": expiry_be,
|
||||
"dist_expiry_be": idx_distance_to_be(idx, expiry_be),
|
||||
@@ -385,12 +398,18 @@ def quote_option_contract(ex: ccxt.okx, inst_id: str) -> dict[str, Any]:
|
||||
t = t_rows[0] if t_rows else {}
|
||||
ask = _safe_float(t.get("askPx"))
|
||||
bid = _safe_float(t.get("bidPx"))
|
||||
if ask is None or bid is None:
|
||||
book_bid, book_ask = _fetch_book_bid_ask(ex, inst_id)
|
||||
ask_sz = _safe_float(t.get("askSz"))
|
||||
bid_sz = _safe_float(t.get("bidSz"))
|
||||
if ask is None or bid is None or ask_sz is None or bid_sz is None:
|
||||
book_bid, book_ask, book_bid_sz, book_ask_sz = _fetch_book_top(ex, inst_id)
|
||||
if ask is None:
|
||||
ask = book_ask
|
||||
if bid is None:
|
||||
bid = book_bid
|
||||
if ask_sz is None:
|
||||
ask_sz = book_ask_sz
|
||||
if bid_sz is None:
|
||||
bid_sz = book_bid_sz
|
||||
mark = _safe_float(t.get("markPx"))
|
||||
tick_sz = meta.get("tickSz")
|
||||
if ask is None and mark is not None:
|
||||
@@ -413,6 +432,8 @@ def quote_option_contract(ex: ccxt.okx, inst_id: str) -> dict[str, Any]:
|
||||
"meta": meta,
|
||||
"ask": ask,
|
||||
"bid": bid,
|
||||
"ask_sz": ask_sz,
|
||||
"bid_sz": bid_sz,
|
||||
"mark": mark,
|
||||
"index_px": idx,
|
||||
"expiry_be_px": expiry_be,
|
||||
|
||||
Reference in New Issue
Block a user