diff --git a/crypto_monitor_okx/.env.example b/crypto_monitor_okx/.env.example index 36607f7..8d3ebba 100644 --- a/crypto_monitor_okx/.env.example +++ b/crypto_monitor_okx/.env.example @@ -112,6 +112,8 @@ OKX_OPTIONS_ACCOUNT_LABEL=主账户·期权 OKX_OPTIONS_TRADE_BUDGET_USDC=10 OKX_OPTIONS_BUDGET_BUFFER=0.95 OKX_OPTIONS_DEFAULT_UNDERLY=ETH +# 期权链仅显示卖一深度≥1张的合约(估算卖一/无深度不显示);false 则显示全部 +OKX_OPTIONS_CHAIN_ASK_LIQ_FILTER_ENABLED=true OKX_OPTIONS_MAX_DTE_DAYS=2 OKX_OPTIONS_CHAIN_MAX_DTE_DAYS=14 OKX_SUB_ACCOUNT_NAME= diff --git a/crypto_monitor_okx/app.py b/crypto_monitor_okx/app.py index d0ef7d7..f3ec0f8 100644 --- a/crypto_monitor_okx/app.py +++ b/crypto_monitor_okx/app.py @@ -6793,6 +6793,10 @@ def render_main_page(page="trade", embed_mode=None): in ("1", "true", "yes", "on"), options_trade_budget=OKX_OPTIONS_TRADE_BUDGET_USDC, options_default_underly=OKX_OPTIONS_DEFAULT_UNDERLY, + options_chain_ask_liq_filter=os.getenv( + "OKX_OPTIONS_CHAIN_ASK_LIQ_FILTER_ENABLED", "true" + ).lower() + in ("1", "true", "yes", "on"), risk_status=risk_status, max_active_positions=MAX_ACTIVE_POSITIONS, manual_min_planned_rr=MANUAL_MIN_PLANNED_RR, diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js index c17b165..ca7d080 100644 --- a/lib/common/static/options_panel.js +++ b/lib/common/static/options_panel.js @@ -14,6 +14,8 @@ moneyFilter: "all", chainView: "list", strikeExpandAll: false, + /** 环境 OKX_OPTIONS_CHAIN_ASK_LIQ_FILTER_ENABLED;链接口可热更新 */ + askLiqFilter: root.dataset.askLiqFilter !== "0", chain: panelCache.chain || null, selectedInst: null, orderQuote: null, @@ -361,21 +363,41 @@ return ""; } + function askLiqFilterOn() { + return !!state.askLiqFilter; + } + + function hasAskLiquidity(c) { + if (!c) return false; + if (c.ask_estimated) return false; + const a = Number(c.ask); + const s = Number(c.ask_sz); + return Number.isFinite(a) && a > 0 && Number.isFinite(s) && s >= 1; + } + + function syncAskLiqFilterFromChain(d) { + if (!d || d.ask_liq_filter_enabled == null) return; + state.askLiqFilter = !!d.ask_liq_filter_enabled; + root.dataset.askLiqFilter = state.askLiqFilter ? "1" : "0"; + } + function countContractsForType(contracts) { if (state.chainView === "t") { return countStraddleStrikes(contracts); } return (contracts || []).filter(function (c) { - return c.opt_type === state.optType; + if (c.opt_type !== state.optType) return false; + if (askLiqFilterOn() && !hasAskLiquidity(c)) return false; + return true; }).length; } function countStraddleStrikes(contracts) { - const strikes = new Set(); - (contracts || []).forEach(function (c) { - if (c.strike != null) strikes.add(String(c.strike)); + const rows = buildStraddleRows(contracts).filter(function (row) { + if (!askLiqFilterOn()) return true; + return hasAskLiquidity(row.call) || hasAskLiquidity(row.put); }); - return strikes.size; + return rows.length; } function buildStraddleRows(contracts) { @@ -418,7 +440,11 @@ function filterStraddleRows(rows, indexPx) { const atmStrike = findAtmStrike(rows, indexPx); return rows.filter(function (row) { - return matchesStrikeRowFilter(row.strike, indexPx, atmStrike); + if (!matchesStrikeRowFilter(row.strike, indexPx, atmStrike)) return false; + if (askLiqFilterOn() && !hasAskLiquidity(row.call) && !hasAskLiquidity(row.put)) { + return false; + } + return true; }); } @@ -479,7 +505,10 @@ function filterChainContracts(contracts) { return (contracts || []).filter(function (c) { - return c.opt_type === state.optType && matchesMoneyFilter(c.moneyness); + if (c.opt_type !== state.optType) return false; + if (!matchesMoneyFilter(c.moneyness)) return false; + if (askLiqFilterOn() && !hasAskLiquidity(c)) return false; + return true; }); } @@ -536,11 +565,32 @@ } const line = document.getElementById("opt-index-line"); if (line) { + const liqHint = askLiqFilterOn() ? "仅显示卖一深度≥1张" : "显示全部卖一(含估算~)"; line.textContent = - "指数 " + state.underlying + " ≈ " + fmt(idx, 2) + " · 默认显示全部 · 实值含平值 · 虚值=价外"; + "指数 " + state.underlying + " ≈ " + fmt(idx, 2) + + " · 默认最近一期 · " + liqHint + " · 实值含平值 · 虚值=价外"; } } + function pickNearestExpiry(exps) { + if (!exps || !exps.length) return ""; + const now = Date.now(); + let best = null; + let bestDelta = Infinity; + exps.forEach(function (e) { + const t = Number(e.exp_time); + if (!Number.isFinite(t)) return; + const delta = t - now; + if (delta < -60000) return; + if (delta < bestDelta) { + bestDelta = delta; + best = e; + } + }); + if (best) return String(best.exp_time); + return String(exps[0].exp_time); + } + function renderExpiryOptions(preserveSelection) { const sel = document.getElementById("opt-exp-select"); if (!sel) return; @@ -555,6 +605,8 @@ }); if (prev && exps.some(function (e) { return String(e.exp_time) === String(prev); })) { sel.value = prev; + } else if (exps.length) { + sel.value = pickNearestExpiry(exps); } } @@ -852,7 +904,8 @@ if (!list.length) { const label = moneyFilterLabel(); const suffix = label ? label : optTypeLabel(state.optType); - tbody.innerHTML = '