From a8d67958379973770d8a9856e4110451d3197b07 Mon Sep 17 00:00:00 2001 From: dekun Date: Wed, 12 Aug 2026 10:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E4=BB=93=E5=A4=8D=E5=88=A9=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E6=97=B6=E9=9A=90=E8=97=8F=E5=B9=B6=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E5=8D=95=E7=AC=94=E9=A2=84=E7=AE=97=EF=BC=9B=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=90=8E=E6=89=8D=E6=98=BE=E7=A4=BA=E5=8F=AF=E7=94=A8=E6=89=93?= =?UTF-8?q?=E6=BB=A1=E9=A2=84=E7=AE=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- crypto_monitor_okx/.env.example | 2 +- lib/common/static/instance_settings_prefs.js | 37 +++++++++++++++++- lib/common/static/options_panel.js | 21 ++++++---- lib/env/env_ui_manifest.py | 8 +++- lib/instance/templates/embed_shell.html | 2 +- lib/instance/templates/env_config_panel.html | 2 +- lib/instance/templates/index.html | 2 +- lib/options/options_register.py | 41 ++++++++++++++++++-- lib/options/templates/options_panel.html | 10 ++--- 9 files changed, 103 insertions(+), 22 deletions(-) diff --git a/crypto_monitor_okx/.env.example b/crypto_monitor_okx/.env.example index 53a63ba..c71bbae 100644 --- a/crypto_monitor_okx/.env.example +++ b/crypto_monitor_okx/.env.example @@ -115,7 +115,7 @@ OKX_OPTIONS_ENABLED=false OKX_OPTIONS_ACCOUNT_LABEL=账户·期权 OKX_OPTIONS_TRADE_BUDGET_USDC=10 OKX_OPTIONS_BUDGET_BUFFER=0.95 -# 全仓复利:开关控制下单页是否出现该模式;上限开关另控封顶额度 +# 全仓复利:开启时隐藏单笔预算且不可用打满;关闭后恢复单笔预算 OKX_OPTIONS_COMPOUND_FULL_ENABLED=true OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED=false OKX_OPTIONS_COMPOUND_FULL_CAP_USDC=300 diff --git a/lib/common/static/instance_settings_prefs.js b/lib/common/static/instance_settings_prefs.js index bd61802..f1acfb7 100644 --- a/lib/common/static/instance_settings_prefs.js +++ b/lib/common/static/instance_settings_prefs.js @@ -202,6 +202,7 @@ function renderEnvFieldRow(field) { const row = document.createElement("div"); row.className = "env-field-row" + (field.restart_required ? " env-field-row--restart" : ""); + row.dataset.envKey = field.key; const label = document.createElement("label"); label.className = "env-field-label"; label.htmlFor = "env-f-" + field.key; @@ -345,9 +346,40 @@ body.appendChild(panelsWrap); body.dataset.envModeSectionIdx = String(modeSectionIdx); bindTradeModeAutoRefresh(body); + bindCompoundBudgetVisibility(body); return body; } + function envFieldRowByKey(body, key) { + if (!body || !key) return null; + const byRow = body.querySelector('.env-field-row[data-env-key="' + key + '"]'); + if (byRow) return byRow; + const input = body.querySelector('.env-field-input[data-env-key="' + key + '"]'); + return input ? input.closest(".env-field-row") : null; + } + + function syncCompoundBudgetVisibility(body) { + if (!body) return; + const compoundSel = body.querySelector( + '.env-field-input[data-env-key="OKX_OPTIONS_COMPOUND_FULL_ENABLED"]' + ); + const budgetRow = envFieldRowByKey(body, "OKX_OPTIONS_TRADE_BUDGET_USDC"); + if (!budgetRow) return; + const compoundOn = !compoundSel || String(compoundSel.value || "").toLowerCase() === "true"; + budgetRow.hidden = compoundOn; + } + + function bindCompoundBudgetVisibility(body) { + if (!body) return; + syncCompoundBudgetVisibility(body); + const compoundSel = body.querySelector( + '.env-field-input[data-env-key="OKX_OPTIONS_COMPOUND_FULL_ENABLED"]' + ); + if (!compoundSel || compoundSel.dataset.compoundBudgetBound === "1") return; + compoundSel.dataset.compoundBudgetBound = "1"; + compoundSel.addEventListener("change", () => syncCompoundBudgetVisibility(body)); + } + function bindTradeModeAutoRefresh(body) { const modeSel = body.querySelector('.env-field-input[data-env-key="OKX_TRADE_MODE"]'); if (!modeSel || modeSel.dataset.modeRefreshBound === "1") return; @@ -542,7 +574,10 @@ loadEnvConfig(false); const root = envConfigRoot(); const body = root && root.querySelector("#env-config-body"); - if (body) bindTradeModeAutoRefresh(body); + if (body) { + bindTradeModeAutoRefresh(body); + bindCompoundBudgetVisibility(body); + } if (global.__INSTANCE_DISPLAY__) applyDisplayToNav(global.__INSTANCE_DISPLAY__); } diff --git a/lib/common/static/options_panel.js b/lib/common/static/options_panel.js index f1a6ca1..d1314c2 100644 --- a/lib/common/static/options_panel.js +++ b/lib/common/static/options_panel.js @@ -286,25 +286,32 @@ const ethEl = document.getElementById("opt-eth-amount"); const hint = document.getElementById("opt-budget-full-hint"); const compoundHint = document.getElementById("opt-compound-full-hint"); + const budgetWrap = document.getElementById("opt-size-mode-budget-wrap"); const compoundWrap = document.getElementById("opt-size-mode-compound-wrap"); const capEl = document.getElementById("opt-budget-full-cap"); const compoundCapLine = document.getElementById("opt-compound-cap-line"); const compoundOn = compoundFullEnabled(); + if (budgetWrap) { + budgetWrap.hidden = compoundOn; + const radio = budgetWrap.querySelector('input[name="opt-size-mode"]'); + if (radio) radio.disabled = compoundOn; + } if (compoundWrap) { compoundWrap.hidden = !compoundOn; const radio = compoundWrap.querySelector('input[name="opt-size-mode"]'); if (radio) radio.disabled = !compoundOn; - if (!compoundOn && mode === "compound_full") { - const sheetsRadio = document.querySelector('input[name="opt-size-mode"][value="sheets"]'); - if (sheetsRadio) { - sheetsRadio.checked = true; - } - } + } + if (compoundOn && mode === "budget_full") { + const compoundRadio = document.querySelector('input[name="opt-size-mode"][value="compound_full"]'); + if (compoundRadio) compoundRadio.checked = true; + } else if (!compoundOn && mode === "compound_full") { + const sheetsRadio = document.querySelector('input[name="opt-size-mode"][value="sheets"]'); + if (sheetsRadio) sheetsRadio.checked = true; } const modeNow = currentSizeMode(); if (sheetsEl) sheetsEl.style.display = modeNow === "sheets" ? "" : "none"; if (ethEl) ethEl.style.display = modeNow === "eth_amount" ? "" : "none"; - if (hint) hint.style.display = modeNow === "budget_full" ? "" : "none"; + if (hint) hint.style.display = modeNow === "budget_full" && !compoundOn ? "" : "none"; if (compoundHint) compoundHint.style.display = modeNow === "compound_full" && compoundOn ? "" : "none"; if (capEl && root && root.dataset.tradeBudget) { const n = Number(root.dataset.tradeBudget); diff --git a/lib/env/env_ui_manifest.py b/lib/env/env_ui_manifest.py index b288608..29c29b6 100644 --- a/lib/env/env_ui_manifest.py +++ b/lib/env/env_ui_manifest.py @@ -143,12 +143,16 @@ _OPTIONS_SECTION: dict[str, Any] = { "fields": [ ("OKX_OPTIONS_ENABLED", "启用期权模块", "与永续共用上方 OKX_API_*;不再单独配置期权密钥"), ("OKX_OPTIONS_ACCOUNT_LABEL", "期权账户备注", ""), - ("OKX_OPTIONS_TRADE_BUDGET_USDC", "单笔预算(USDC)", ""), + ( + "OKX_OPTIONS_TRADE_BUDGET_USDC", + "单笔预算(USDC)", + "仅全仓复利关闭时显示/生效;用于「按可用余额打满」及张数/币数上限", + ), ("OKX_OPTIONS_BUDGET_BUFFER", "预算缓冲比例", "如 0.95;打满/全仓复利共用"), ( "OKX_OPTIONS_COMPOUND_FULL_ENABLED", "全仓复利开关", - "默认 true;开启后下单页出现「全仓复利」模式;关闭则隐藏且拒绝该模式开仓", + "默认 true;开启时隐藏单笔预算且不可用打满预算,下单以全仓复利为主;关闭则恢复单笔预算并隐藏全仓复利", ), ( "OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED", diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 0accef1..7bd884b 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -170,7 +170,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj - + diff --git a/lib/instance/templates/env_config_panel.html b/lib/instance/templates/env_config_panel.html index 3b35269..1df3d1e 100644 --- a/lib/instance/templates/env_config_panel.html +++ b/lib/instance/templates/env_config_panel.html @@ -37,7 +37,7 @@ {% endif %}
{% for field in group.fields %} -
+