全仓复利开启时隐藏并禁用单笔预算;关闭后才显示可用打满预算。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user