feat: restructure OKX options UI with header funds, settings card, and dual-column layout
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -85,11 +85,18 @@ def profit_loss_ratio_from_trades(trades: list[dict[str, Any]] | None) -> float
|
||||
return profit_loss_ratio_from_averages(avg_win, avg_loss)
|
||||
|
||||
|
||||
def total_funds_usdt(funding_usdt: float | None, trading_usdt: float | None) -> float | None:
|
||||
def total_funds_usdt(
|
||||
funding_usdt: float | None,
|
||||
trading_usdt: float | None,
|
||||
options_trading_usdc: float | None = None,
|
||||
) -> float | None:
|
||||
if funding_usdt is None:
|
||||
return None
|
||||
try:
|
||||
return round(float(funding_usdt) + float(trading_usdt or 0), 2)
|
||||
total = float(funding_usdt) + float(trading_usdt or 0)
|
||||
if options_trading_usdc is not None:
|
||||
total += float(options_trading_usdc)
|
||||
return round(total, 2)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
@@ -139,18 +139,21 @@ def build_instance_settings_view(
|
||||
opt_key = (os.getenv("OKX_OPTIONS_API_KEY") or "").strip()
|
||||
sections.append(
|
||||
{
|
||||
"title": "期权账户(主账户)",
|
||||
"title": "期权设置",
|
||||
"rows": [
|
||||
_row("期权模块", "已启用"),
|
||||
_row(
|
||||
"期权 API",
|
||||
f"已配置(…{opt_key[-4:]})" if len(opt_key) >= 4 else "未配置",
|
||||
),
|
||||
_row("单笔权利金上限", f"{_env_float('OKX_OPTIONS_TRADE_BUDGET_USDC', 10):g} USDC"),
|
||||
_row(
|
||||
"资金说明",
|
||||
"资金账户 USDT 兑换 USDC 后划转到交易账户",
|
||||
"期权页操作;与永续子账户资金分开",
|
||||
"子账户",
|
||||
(os.getenv("OKX_SUB_ACCOUNT_NAME") or "").strip() or "未配置 OKX_SUB_ACCOUNT_NAME",
|
||||
"主/子账户划转用",
|
||||
),
|
||||
_row(
|
||||
"说明",
|
||||
"币种兑换与账户划转到右侧「期权设置」卡片操作",
|
||||
),
|
||||
],
|
||||
}
|
||||
@@ -169,6 +172,9 @@ def build_instance_settings_view(
|
||||
"sections": sections,
|
||||
"data_export_version": int(data_export_version),
|
||||
"show_transfer": (exchange_key or "").strip().lower() in ("gate", "binance", "okx"),
|
||||
"options_settings_enabled": (exchange_key or "").strip().lower() == "okx"
|
||||
and _env_bool("OKX_OPTIONS_ENABLED", False),
|
||||
"options_sub_account": (os.getenv("OKX_SUB_ACCOUNT_NAME") or "").strip(),
|
||||
"auto_transfer_enabled": auto_transfer_on,
|
||||
"auto_transfer_bj_hour": _env_int("AUTO_TRANSFER_BJ_HOUR", 8),
|
||||
"auto_transfer_amount": _env_float("AUTO_TRANSFER_AMOUNT", 30),
|
||||
|
||||
@@ -1061,6 +1061,11 @@ function refreshAccountSnapshot(){
|
||||
const el = document.getElementById("current-capital");
|
||||
if(el) el.innerText = `${Number(data.current_capital).toFixed(2)}U`;
|
||||
}
|
||||
if (typeof data.options_trading_usdc !== "undefined") {
|
||||
const el = document.getElementById("options-trading-usdc");
|
||||
if (el) el.innerText = (data.options_trading_usdc === null || data.options_trading_usdc === undefined)
|
||||
? "—" : `${Number(data.options_trading_usdc).toFixed(2)} USDC`;
|
||||
}
|
||||
if (typeof data.unrealized_pnl !== "undefined") {
|
||||
paintRealtimePnl(data.unrealized_pnl);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
</div>
|
||||
{% with msg=get_flashed_messages() %}{% if msg %}<div class="flash">{{ msg[0] }}</div>{% endif %}{% endwith %}
|
||||
|
||||
{% if page != 'settings' and page != 'options' %}
|
||||
{% if page != 'settings' %}
|
||||
{% include 'instance_header_panel.html' %}
|
||||
{% endif %}
|
||||
{% if page != 'settings' and page != 'options' %}
|
||||
@@ -1612,6 +1612,11 @@ function refreshAccountSnapshot(){
|
||||
const el = document.getElementById("current-capital");
|
||||
if(el) el.innerText = `${Number(data.current_capital).toFixed(2)}U`;
|
||||
}
|
||||
if (typeof data.options_trading_usdc !== "undefined") {
|
||||
const el = document.getElementById("options-trading-usdc");
|
||||
if (el) el.innerText = (data.options_trading_usdc === null || data.options_trading_usdc === undefined)
|
||||
? "—" : `${Number(data.options_trading_usdc).toFixed(2)} USDC`;
|
||||
}
|
||||
if (typeof data.unrealized_pnl !== "undefined") {
|
||||
paintRealtimePnl(data.unrealized_pnl);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,12 @@
|
||||
<div class="label">交易账户</div>
|
||||
<div class="value" id="current-capital">{{ funds_fmt(current_capital) }}U</div>
|
||||
</div>
|
||||
{% if options_enabled %}
|
||||
<div class="stat-strip-item">
|
||||
<div class="label">期权交易账户</div>
|
||||
<div class="value" id="options-trading-usdc">{% if options_trading_usdc is not none %}{{ funds_fmt(options_trading_usdc) }} USDC{% else %}—{% endif %}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="stat-strip-item stat-strip-item--pnl">
|
||||
<div class="label">实时盈亏</div>
|
||||
<div class="value" id="realtime-pnl">—</div>
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-side-col">
|
||||
{% if instance_settings.options_settings_enabled %}
|
||||
<div class="card settings-card">
|
||||
<h2>期权设置</h2>
|
||||
<p class="settings-card-desc">主账户期权资金:现货市价兑换 USDT/USDC;主账户与子账户(永续)之间划转。</p>
|
||||
{% include 'options_settings_panel.html' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if instance_settings.show_transfer %}
|
||||
<div class="card settings-card">
|
||||
<h2>资金划转</h2>
|
||||
|
||||
Reference in New Issue
Block a user