Options: default nearest expiry and env ask-liquidity chain filter.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-20 08:37:39 +08:00
parent 7eb098def6
commit ed1ec6f14a
7 changed files with 96 additions and 15 deletions
+12 -1
View File
@@ -108,6 +108,7 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
"default_underly": (os.getenv("OKX_OPTIONS_DEFAULT_UNDERLY") or "ETH").strip().upper(),
"max_dte_days": _env_float("OKX_OPTIONS_MAX_DTE_DAYS", 2.0),
"chain_max_dte_days": _env_float("OKX_OPTIONS_CHAIN_MAX_DTE_DAYS", 14.0),
"chain_ask_liq_filter": _env_bool("OKX_OPTIONS_CHAIN_ASK_LIQ_FILTER_ENABLED", True),
"itm_max_dist": _env_float("OKX_OPTIONS_ITM_MAX_DIST_USD", 30.0),
"td_mode": (os.getenv("OKX_OPTIONS_TD_MODE") or "isolated").strip(),
# 市价平仓已硬关闭(忽略 env),仅买一限价
@@ -370,6 +371,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
return jsonify({"ok": False, "msg": f"加载期权链失败: {e}"})
expiries = chain.get("expiries") or []
chain_err = chain.get("chain_error")
# 热更新:每次读 env,保存配置后刷新链即可生效
ask_liq_filter = _env_bool("OKX_OPTIONS_CHAIN_ASK_LIQ_FILTER_ENABLED", True)
if not expiries:
return jsonify(
{
@@ -377,9 +380,17 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
"msg": chain_err or "暂无到期日,请稍后点「刷新链」",
**chain,
"chain_max_dte_days": cfg["chain_max_dte_days"],
"ask_liq_filter_enabled": ask_liq_filter,
}
)
return jsonify({"ok": True, **chain, "chain_max_dte_days": cfg["chain_max_dte_days"]})
return jsonify(
{
"ok": True,
**chain,
"chain_max_dte_days": cfg["chain_max_dte_days"],
"ask_liq_filter_enabled": ask_liq_filter,
}
)
@app.route("/api/options/quote")
@lr