diff --git a/crypto_monitor_okx/app.py b/crypto_monitor_okx/app.py index 757ce21..708f89d 100644 --- a/crypto_monitor_okx/app.py +++ b/crypto_monitor_okx/app.py @@ -6791,6 +6791,7 @@ def render_main_page(page="trade", embed_mode=None): in ("1", "true", "yes", "on"), hedge_plan_oo_close_mode_enabled=os.getenv("HEDGE_PLAN_OO_CLOSE_MODE_ENABLED", "true").lower() in ("1", "true", "yes", "on"), + hedge_plan_budget_buffer=float(os.getenv("HEDGE_PLAN_BUDGET_BUFFER") or "0.95"), options_trade_budget=OKX_OPTIONS_TRADE_BUDGET_USDC, options_default_underly=OKX_OPTIONS_DEFAULT_UNDERLY, options_chain_ask_liq_filter=os.getenv( diff --git a/lib/common/static/hedge_plan.js b/lib/common/static/hedge_plan.js index cd36dff..d2b5f33 100644 --- a/lib/common/static/hedge_plan.js +++ b/lib/common/static/hedge_plan.js @@ -37,7 +37,11 @@ tradingUsdc: null, fundingUsdc: null, tradeBudgetUsdc: null, - budgetBuffer: 0.95, + budgetBuffer: (function () { + const raw = root.getAttribute("data-budget-buffer"); + const n = raw != null && raw !== "" ? Number(raw) : NaN; + return !Number.isNaN(n) && n > 0 ? n : 0.95; + })(), previewOk: false, canStart: false, previewPlanType: null, @@ -239,6 +243,15 @@ if (modal) modal.hidden = true; } + function applyBudgetBuffer(raw) { + if (raw == null || raw === "") return; + const buf = Number(raw); + if (Number.isNaN(buf) || buf <= 0) return; + state.budgetBuffer = buf; + const el = $("hp-oo-buf-ratio"); + if (el) el.textContent = fmt(buf, 2); + } + function setOptionsBalance(chain) { const acct = (chain && chain.options_account) || {}; const label = (chain && chain.account_label) || acct.label || "期权账户"; @@ -254,8 +267,7 @@ state.tradeBudgetUsdc = Number(chain.trade_budget_usdc); } if (chain && chain.budget_buffer != null && chain.budget_buffer !== "") { - const buf = Number(chain.budget_buffer); - if (!Number.isNaN(buf) && buf > 0) state.budgetBuffer = buf; + applyBudgetBuffer(chain.budget_buffer); } const line = label + @@ -528,6 +540,7 @@ if (d.oo_bias_ratio != null && Number(d.oo_bias_ratio) > 0 && Number(d.oo_bias_ratio) < 1) { state.ooBiasRatio = Number(d.oo_bias_ratio); } + if (d.budget_buffer != null) applyBudgetBuffer(d.budget_buffer); syncOoCloseModeUI(); setGateLine(d); if (state.mode === "options_options") autoFillOoSheets(); @@ -1824,6 +1837,7 @@ syncPoDirUI(); syncOoSizeModeUI(); syncOoCloseModeUI(); + applyBudgetBuffer(state.budgetBuffer); updateOoBudgetLine(null); bind(); void refreshAll(); diff --git a/lib/hedge_plan/hedge_plan_register.py b/lib/hedge_plan/hedge_plan_register.py index 5f7b6eb..a73e212 100644 --- a/lib/hedge_plan/hedge_plan_register.py +++ b/lib/hedge_plan/hedge_plan_register.py @@ -209,6 +209,7 @@ def _gates_public(cfg: dict[str, Any], plan_type: str) -> dict[str, Any]: g["oo_close_mode_default"] = "close_all" if _oo_close_mode_enabled() else "hold_expiry" g["oo_bias_split_by"] = _oo_bias_split_by() g["oo_bias_ratio"] = _oo_bias_ratio() + g["budget_buffer"] = float(cfg.get("budget_buffer") or 0.95) return g diff --git a/lib/hedge_plan/templates/hedge_plan_panel.html b/lib/hedge_plan/templates/hedge_plan_panel.html index fc49041..8db6a36 100644 --- a/lib/hedge_plan/templates/hedge_plan_panel.html +++ b/lib/hedge_plan/templates/hedge_plan_panel.html @@ -5,6 +5,7 @@ data-show-perp="{{ '1' if hedge_plan_show_perp_options | default(true) else '0' }}" data-show-oo="{{ '1' if hedge_plan_show_options_options | default(true) else '0' }}" data-oo-close-mode-enabled="{{ '1' if hedge_plan_oo_close_mode_enabled | default(true) else '0' }}" + data-budget-buffer="{{ hedge_plan_budget_buffer | default(0.95) }}" data-sizing-mode="{{ position_sizing_mode | default('risk') }}" data-is-full-margin="{{ '1' if position_sizing_mode == 'full_margin' else '0' }}"> {% if not hedge_plan_enabled %} @@ -132,7 +133,7 @@
规则说明
-

账户:两腿都在期权账户。可用预算 = min(交易 USDC × 对冲缓冲, 单笔预算);缓冲在 env「对冲预算缓冲比例」改。

+

账户:两腿都在期权账户。可用预算 = min(交易 USDC × 对冲缓冲 {{ '%.2f'|format(hedge_plan_budget_buffer|default(0.95)|float) }}, 单笔预算);可在 env「对冲预算缓冲比例」改。

下单:选 Call + Put 后「计算」再「启动」。启动会再拉卖一并按最新价重算张数,IOC 完全成交才算成功;资金不足可在右侧划转。

板块:左填上破/下破与张数模式(同张数/做多/做空);右 T 型选腿。「全平」= 盈利腿平后清另一腿;「到期平」= 另一腿持有至到期。

@@ -321,4 +322,4 @@ - +