Fetch option Delta from OKX opt-summary into the chain.

market/tickers has no greeks; merge public/opt-summary delta/gamma when building the strike table.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 22:02:25 +08:00
parent 37428c0bf9
commit 1d8c38e320
3 changed files with 47 additions and 2 deletions
+29 -1
View File
@@ -841,6 +841,27 @@ def fetch_option_tickers(ex: ccxt.okx, inst_family: str) -> dict[str, dict[str,
return out return out
def fetch_option_summary(ex: ccxt.okx, inst_family: str) -> dict[str, dict[str, Any]]:
"""期权希腊字母摘要(delta/gamma);tickers 接口无此字段."""
out: dict[str, dict[str, Any]] = {}
try:
from lib.exchange.okx_public_http_lib import fetch_option_summary_public
got = fetch_option_summary_public(inst_family)
if got:
return got
except Exception:
pass
try:
rows = ex.public_get_public_opt_summary({"instFamily": inst_family}).get("data") or []
for r in rows:
if isinstance(r, dict) and r.get("instId"):
out[str(r["instId"])] = r
except Exception:
pass
return out
def build_option_chain( def build_option_chain(
ex: ccxt.okx, ex: ccxt.okx,
underlying: str, underlying: str,
@@ -890,6 +911,8 @@ def build_option_chain(
except Exception as e2: except Exception as e2:
instruments_err = str(e2) or e2.__class__.__name__ instruments_err = str(e2) or e2.__class__.__name__
tickers = fetch_option_tickers(ex, family) tickers = fetch_option_tickers(ex, family)
# 希腊字母在 opt-summary,不在 market/tickers
summaries = fetch_option_summary(ex, family)
expiries: dict[str, list[dict[str, Any]]] = {} expiries: dict[str, list[dict[str, Any]]] = {}
skipped_no_index = 0 skipped_no_index = 0
for meta in instruments: for meta in instruments:
@@ -914,7 +937,12 @@ def build_option_chain(
): ):
continue continue
inst_id = str(meta.get("instId") or "") inst_id = str(meta.get("instId") or "")
t = tickers.get(inst_id) or {} t = dict(tickers.get(inst_id) or {})
sm = summaries.get(inst_id) or {}
# 合并摘要里的 delta/gamma(优先币本位 delta,回退 deltaBS)
for k in ("delta", "deltaBS", "gamma", "gammaBS", "lever", "markVol"):
if sm.get(k) not in (None, ""):
t[k] = sm.get(k)
q = _resolve_chain_quote( q = _resolve_chain_quote(
ticker=t, ticker=t,
meta=meta, meta=meta,
+17
View File
@@ -165,3 +165,20 @@ def fetch_option_tickers_public(inst_family: str) -> dict[str, dict[str, Any]]:
if isinstance(r, dict) and r.get("instId"): if isinstance(r, dict) and r.get("instId"):
out[str(r["instId"])] = r out[str(r["instId"])] = r
return out return out
def fetch_option_summary_public(inst_family: str) -> dict[str, dict[str, Any]]:
"""期权摘要(含 delta/gamma 等);market/tickers 不含希腊字母."""
family = str(inst_family or "").strip()
if not family:
return {}
payload = okx_public_get(
"/api/v5/public/opt-summary",
{"instFamily": family},
timeout_sec=12.0,
)
out: dict[str, dict[str, Any]] = {}
for r in payload.get("data") or []:
if isinstance(r, dict) and r.get("instId"):
out[str(r["instId"])] = r
return out
@@ -509,4 +509,4 @@
</div> </div>
</div> </div>
</div> </div>
<script src="/static/hedge_plan.js?v=69"></script> <script src="/static/hedge_plan.js?v=70"></script>