Show live hedge budget buffer ratio in options-options rule tips.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-20 10:32:06 +08:00
parent c9229d64bf
commit 3ae7def999
4 changed files with 22 additions and 5 deletions
+1
View File
@@ -6791,6 +6791,7 @@ def render_main_page(page="trade", embed_mode=None):
in ("1", "true", "yes", "on"), in ("1", "true", "yes", "on"),
hedge_plan_oo_close_mode_enabled=os.getenv("HEDGE_PLAN_OO_CLOSE_MODE_ENABLED", "true").lower() hedge_plan_oo_close_mode_enabled=os.getenv("HEDGE_PLAN_OO_CLOSE_MODE_ENABLED", "true").lower()
in ("1", "true", "yes", "on"), 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_trade_budget=OKX_OPTIONS_TRADE_BUDGET_USDC,
options_default_underly=OKX_OPTIONS_DEFAULT_UNDERLY, options_default_underly=OKX_OPTIONS_DEFAULT_UNDERLY,
options_chain_ask_liq_filter=os.getenv( options_chain_ask_liq_filter=os.getenv(
+17 -3
View File
@@ -37,7 +37,11 @@
tradingUsdc: null, tradingUsdc: null,
fundingUsdc: null, fundingUsdc: null,
tradeBudgetUsdc: 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, previewOk: false,
canStart: false, canStart: false,
previewPlanType: null, previewPlanType: null,
@@ -239,6 +243,15 @@
if (modal) modal.hidden = true; 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) { function setOptionsBalance(chain) {
const acct = (chain && chain.options_account) || {}; const acct = (chain && chain.options_account) || {};
const label = (chain && chain.account_label) || acct.label || "期权账户"; const label = (chain && chain.account_label) || acct.label || "期权账户";
@@ -254,8 +267,7 @@
state.tradeBudgetUsdc = Number(chain.trade_budget_usdc); state.tradeBudgetUsdc = Number(chain.trade_budget_usdc);
} }
if (chain && chain.budget_buffer != null && chain.budget_buffer !== "") { if (chain && chain.budget_buffer != null && chain.budget_buffer !== "") {
const buf = Number(chain.budget_buffer); applyBudgetBuffer(chain.budget_buffer);
if (!Number.isNaN(buf) && buf > 0) state.budgetBuffer = buf;
} }
const line = const line =
label + label +
@@ -528,6 +540,7 @@
if (d.oo_bias_ratio != null && Number(d.oo_bias_ratio) > 0 && Number(d.oo_bias_ratio) < 1) { 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); state.ooBiasRatio = Number(d.oo_bias_ratio);
} }
if (d.budget_buffer != null) applyBudgetBuffer(d.budget_buffer);
syncOoCloseModeUI(); syncOoCloseModeUI();
setGateLine(d); setGateLine(d);
if (state.mode === "options_options") autoFillOoSheets(); if (state.mode === "options_options") autoFillOoSheets();
@@ -1824,6 +1837,7 @@
syncPoDirUI(); syncPoDirUI();
syncOoSizeModeUI(); syncOoSizeModeUI();
syncOoCloseModeUI(); syncOoCloseModeUI();
applyBudgetBuffer(state.budgetBuffer);
updateOoBudgetLine(null); updateOoBudgetLine(null);
bind(); bind();
void refreshAll(); void refreshAll();
+1
View File
@@ -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_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_split_by"] = _oo_bias_split_by()
g["oo_bias_ratio"] = _oo_bias_ratio() g["oo_bias_ratio"] = _oo_bias_ratio()
g["budget_buffer"] = float(cfg.get("budget_buffer") or 0.95)
return g return g
@@ -5,6 +5,7 @@
data-show-perp="{{ '1' if hedge_plan_show_perp_options | default(true) else '0' }}" 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-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-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-sizing-mode="{{ position_sizing_mode | default('risk') }}"
data-is-full-margin="{{ '1' if position_sizing_mode == 'full_margin' else '0' }}"> data-is-full-margin="{{ '1' if position_sizing_mode == 'full_margin' else '0' }}">
{% if not hedge_plan_enabled %} {% if not hedge_plan_enabled %}
@@ -132,7 +133,7 @@
<details class="tip-collapse hp-rule-collapse"> <details class="tip-collapse hp-rule-collapse">
<summary class="tip-collapse-summary">规则说明</summary> <summary class="tip-collapse-summary">规则说明</summary>
<div class="tip-collapse-body rule-tip"> <div class="tip-collapse-body rule-tip">
<p><strong>账户</strong>:两腿都在<strong>期权账户</strong>。可用预算 = min(交易 USDC × 对冲缓冲, 单笔预算);缓冲在 env「对冲预算缓冲比例」改。</p> <p><strong>账户</strong>:两腿都在<strong>期权账户</strong>。可用预算 = min(交易 USDC × 对冲缓冲 <strong id="hp-oo-buf-ratio">{{ '%.2f'|format(hedge_plan_budget_buffer|default(0.95)|float) }}</strong>, 单笔预算);在 env「对冲预算缓冲比例」改。</p>
<p><strong>下单</strong>:选 Call + Put 后「计算」再「启动」。启动会再拉卖一并按最新价重算张数,IOC 完全成交才算成功;资金不足可在右侧划转。</p> <p><strong>下单</strong>:选 Call + Put 后「计算」再「启动」。启动会再拉卖一并按最新价重算张数,IOC 完全成交才算成功;资金不足可在右侧划转。</p>
<p><strong>板块</strong>:左填上破/下破与张数模式(同张数/做多/做空);右 T 型选腿。「全平」= 盈利腿平后清另一腿;「到期平」= 另一腿持有至到期。</p> <p><strong>板块</strong>:左填上破/下破与张数模式(同张数/做多/做空);右 T 型选腿。「全平」= 盈利腿平后清另一腿;「到期平」= 另一腿持有至到期。</p>
</div> </div>
@@ -321,4 +322,4 @@
</div> </div>
</div> </div>
</div> </div>
<script src="/static/hedge_plan.js?v=32"></script> <script src="/static/hedge_plan.js?v=33"></script>