全仓复利开启时隐藏并禁用单笔预算;关闭后才显示可用打满预算。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-12 10:00:50 +08:00
parent 51e454b0f6
commit a8d6795837
9 changed files with 103 additions and 22 deletions
+1 -1
View File
@@ -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
+36 -1
View File
@@ -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__);
}
+14 -7
View File
@@ -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);
+6 -2
View File
@@ -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",
+1 -1
View File
@@ -170,7 +170,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj
<script>
window.__INSTANCE_DISPLAY__ = {{ display | tojson }};
</script>
<script src="/static/instance_settings_prefs.js?v=19"></script>
<script src="/static/instance_settings_prefs.js?v=20"></script>
<script src="/static/instance_live.js?v=6"></script>
<script src="/static/instance_embed.js?v=31"></script>
<script src="/static/instance_mobile_nav.js?v=2"></script>
+1 -1
View File
@@ -37,7 +37,7 @@
{% endif %}
<div class="env-form-grid">
{% for field in group.fields %}
<div class="env-field-row{% if field.restart_required %} env-field-row--restart{% endif %}">
<div class="env-field-row{% if field.restart_required %} env-field-row--restart{% endif %}" data-env-key="{{ field.key }}">
<label class="env-field-label" for="env-f-{{ field.key }}">
{{ field.label or field.key }}
{% if field.restart_required %}<span class="env-restart-mark" title="需重启">*</span>{% endif %}
+1 -1
View File
@@ -2045,6 +2045,6 @@ document.addEventListener("DOMContentLoaded", function () {
});
{% endif %}
</script>
<script src="/static/instance_settings_prefs.js?v=19"></script>
<script src="/static/instance_settings_prefs.js?v=20"></script>
</body>
</html>
+38 -3
View File
@@ -181,6 +181,25 @@ def _compound_full_enabled() -> bool:
return _env_bool("OKX_OPTIONS_COMPOUND_FULL_ENABLED", True)
def _budget_full_blocked_by_compound_msg() -> str | None:
if _compound_full_enabled():
return "全仓复利已开启,不可使用单笔预算/打满;请关闭全仓复利或改用全仓复利模式"
return None
def _size_mode_budget_cap(
cfg: dict[str, Any], mode: str, budget_cap: float | None
) -> float | None:
"""全仓复利开启时禁用单笔预算封顶(sheets/eth 也不再受 trade_budget 限制)."""
if mode in ("budget_full", "compound_full"):
return budget_cap
if mode in ("sheets", "eth_amount"):
if _compound_full_enabled():
return None
return budget_cap
return None
def _compound_full_usdc(cfg: dict[str, Any], ex: Any) -> tuple[float | None, str]:
"""全仓复利 = 期权交易户可用(可选上限封顶);再由 calc_order_size × budget_buffer."""
if not _compound_full_enabled():
@@ -471,6 +490,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
budget_cap = cfg["trade_budget"]
available_usdc = None
if mode == "budget_full":
blocked = _budget_full_blocked_by_compound_msg()
if blocked:
return jsonify({"ok": False, "msg": blocked})
budget, budget_err = _budget_full_usdc(cfg, ex)
if budget is None:
return jsonify({"ok": False, "msg": budget_err})
@@ -488,6 +510,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
from lib.exchange.okx_options_lib import fetch_options_trading_usdc
available_usdc = fetch_options_trading_usdc(ex)
elif mode in ("sheets", "eth_amount") and _compound_full_enabled():
budget_cap = None
eth_amount = None
try:
if request.args.get("eth_amount"):
@@ -648,7 +672,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
budget_buffer=cfg["budget_buffer"],
eth_amount=eth_amount if mode == "eth_amount" else None,
sheets=sheet_count if mode == "sheets" else None,
budget_cap=budget_cap if mode in ("budget_full", "compound_full", "sheets", "eth_amount") else None,
budget_cap=_size_mode_budget_cap(cfg, mode, budget_cap)
if mode in ("budget_full", "compound_full", "sheets", "eth_amount")
else None,
)
if sizing.get("ok"):
capped, cap_msg = cap_option_buy_sheets_to_ask_depth(
@@ -670,7 +696,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
ct_mult=float(ct_mult),
min_sz=int(min_sz),
sheets=capped,
budget_cap=budget_cap if mode in ("budget_full", "compound_full", "sheets", "eth_amount") else None,
budget_cap=_size_mode_budget_cap(cfg, mode, budget_cap)
if mode in ("budget_full", "compound_full", "sheets", "eth_amount")
else None,
)
if sizing.get("ok"):
sizing["ask_depth_capped"] = True
@@ -789,6 +817,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
budget = cfg["trade_budget"]
budget_cap = cfg["trade_budget"]
if mode == "budget_full":
blocked = _budget_full_blocked_by_compound_msg()
if blocked:
return jsonify({"ok": False, "msg": blocked})
budget, budget_err = _budget_full_usdc(cfg, ex)
if budget is None:
return jsonify({"ok": False, "msg": budget_err})
@@ -800,6 +831,8 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
if budget is None:
return jsonify({"ok": False, "msg": budget_err})
budget_cap = budget
elif mode in ("sheets", "eth_amount") and _compound_full_enabled():
budget_cap = None
sizing = calc_order_size(
quote_per_unit=float(ask),
ct_mult=ct_mult,
@@ -808,7 +841,9 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
budget_buffer=cfg["budget_buffer"],
eth_amount=eth_amount,
sheets=sheet_count,
budget_cap=budget_cap if mode in ("budget_full", "compound_full", "sheets", "eth_amount") else None,
budget_cap=_size_mode_budget_cap(cfg, mode, budget_cap)
if mode in ("budget_full", "compound_full", "sheets", "eth_amount")
else None,
)
if not sizing.get("ok"):
return jsonify({"ok": False, "msg": sizing.get("msg") or "张数计算失败", "sizing": sizing})
+5 -5
View File
@@ -126,17 +126,17 @@
<div class="form-row options-order-mode-row">
<div class="opt-size-mode-bar">
<label class="btn-secondary opt-order-chip opt-size-mode-chip">
<input type="radio" name="opt-size-mode" value="sheets" checked>
<input type="radio" name="opt-size-mode" value="sheets"{% if not (options_compound_full_enabled if options_compound_full_enabled is defined else true) %} checked{% endif %}>
<span>指定张数</span>
</label>
<input type="number" id="opt-sheets-amount" min="1" step="1" value="1" placeholder="张数"
autocomplete="off" inputmode="numeric" data-lpignore="true" data-1p-ignore="true" data-form-type="other">
<label class="btn-secondary opt-order-chip opt-size-mode-chip">
<input type="radio" name="opt-size-mode" value="budget_full">
<label class="btn-secondary opt-order-chip opt-size-mode-chip" id="opt-size-mode-budget-wrap"{% if options_compound_full_enabled if options_compound_full_enabled is defined else true %} hidden{% endif %}>
<input type="radio" name="opt-size-mode" value="budget_full"{% if options_compound_full_enabled if options_compound_full_enabled is defined else true %} disabled{% endif %}>
<span>按可用余额打满</span>
</label>
<label class="btn-secondary opt-order-chip opt-size-mode-chip" id="opt-size-mode-compound-wrap"{% if options_compound_full_enabled is defined and not options_compound_full_enabled %} hidden{% endif %}>
<input type="radio" name="opt-size-mode" value="compound_full"{% if options_compound_full_enabled is defined and not options_compound_full_enabled %} disabled{% endif %}>
<input type="radio" name="opt-size-mode" value="compound_full"{% if options_compound_full_enabled if options_compound_full_enabled is defined else true %} checked{% endif %}{% if options_compound_full_enabled is defined and not options_compound_full_enabled %} disabled{% endif %}>
<span>全仓复利</span>
</label>
<label class="btn-secondary opt-order-chip opt-size-mode-chip">
@@ -335,4 +335,4 @@
</div>
</div>
<script src="/static/options_expiry_countdown.js?v=1"></script>
<script src="/static/options_panel.js?v=58"></script>
<script src="/static/options_panel.js?v=59"></script>