Improve hedge-plan option board: moneyness, px/sz, accounts, and denser UI.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -49,7 +49,7 @@ def install_hedge_plan(app: Flask, repo_root: str, app_module: Any) -> None:
|
||||
|
||||
|
||||
def _build_cfg(app_module: Any) -> dict[str, Any]:
|
||||
from lib.exchange.okx_options_lib import build_option_chain
|
||||
from lib.exchange.okx_options_lib import build_option_chain, options_header_balances
|
||||
|
||||
return {
|
||||
"get_db": app_module.get_db,
|
||||
@@ -62,6 +62,7 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
|
||||
"normalize_exchange_symbol": getattr(app_module, "normalize_exchange_symbol", None),
|
||||
"ensure_markets_loaded": getattr(app_module, "ensure_markets_loaded", None),
|
||||
"build_option_chain": build_option_chain,
|
||||
"options_header_balances": options_header_balances,
|
||||
"btc_leverage": int(getattr(app_module, "BTC_LEVERAGE", 10) or 10),
|
||||
"alt_leverage": int(getattr(app_module, "ALT_LEVERAGE", 5) or 5),
|
||||
"full_margin_buffer": float(getattr(app_module, "FULL_MARGIN_BUFFER_RATIO", 0.98) or 0.98),
|
||||
@@ -69,6 +70,8 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
|
||||
"options_enabled": _env_bool("OKX_OPTIONS_ENABLED", False),
|
||||
"default_underly": (os.getenv("OKX_OPTIONS_DEFAULT_UNDERLY") or "ETH").strip().upper(),
|
||||
"chain_max_dte": float(os.getenv("OKX_OPTIONS_CHAIN_MAX_DTE_DAYS") or os.getenv("OKX_OPTIONS_MAX_DTE_DAYS") or "14"),
|
||||
"perp_account_label": (os.getenv("OKX_ACCOUNT_LABEL") or "合约账户").strip(),
|
||||
"options_account_label": (os.getenv("OKX_OPTIONS_ACCOUNT_LABEL") or "期权账户").strip(),
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +135,9 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
**data,
|
||||
"gates": gates,
|
||||
"sizing_mode": sizing_mode,
|
||||
"account_kind": "perp",
|
||||
"account_label": cfg.get("perp_account_label") or "合约账户",
|
||||
"account_note": "永续腿使用合约(交易)账户可用 USDT",
|
||||
}
|
||||
return jsonify(out)
|
||||
|
||||
@@ -154,7 +160,19 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "msg": f"拉取期权链失败: {e}"}), 500
|
||||
return jsonify({"ok": True, **chain, "chain_max_dte_days": cfg.get("chain_max_dte")})
|
||||
opt_acct = _options_account_snapshot(cfg)
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
**chain,
|
||||
"underlying": u,
|
||||
"chain_max_dte_days": cfg.get("chain_max_dte"),
|
||||
"account_kind": "options",
|
||||
"account_label": cfg.get("options_account_label") or "期权账户",
|
||||
"account_note": "期权腿使用期权账户(交易 USDC)",
|
||||
"options_account": opt_acct,
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/api/hedge-plan/preview", methods=["POST"])
|
||||
@lr
|
||||
@@ -318,6 +336,34 @@ def _fetch_perp_market(cfg: dict[str, Any], base: str) -> tuple[dict[str, Any],
|
||||
}, None
|
||||
|
||||
|
||||
def _options_account_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
|
||||
"""期权账户资金快照(与期权页同源: exchange_options)."""
|
||||
out: dict[str, Any] = {
|
||||
"label": cfg.get("options_account_label") or "期权账户",
|
||||
"trading_usdc": None,
|
||||
"funding_usdc": None,
|
||||
"trading_usdt": None,
|
||||
"funding_usdt": None,
|
||||
}
|
||||
ex = cfg.get("exchange_options")
|
||||
hdr = cfg.get("options_header_balances")
|
||||
if ex is None or not callable(hdr):
|
||||
return out
|
||||
try:
|
||||
trading_usdc, funding_usdc, funding_usdt, trading_usdt = hdr(ex, force=False)
|
||||
out.update(
|
||||
{
|
||||
"trading_usdc": trading_usdc,
|
||||
"funding_usdc": funding_usdc,
|
||||
"trading_usdt": trading_usdt,
|
||||
"funding_usdt": funding_usdt,
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return out
|
||||
|
||||
|
||||
def _sf(v: Any) -> float | None:
|
||||
if v is None or v == "":
|
||||
return None
|
||||
|
||||
@@ -23,13 +23,14 @@
|
||||
<button type="button" class="hp-tab" role="tab" aria-selected="false" data-tab="stats">统计分析</button>
|
||||
</div>
|
||||
<p class="muted" id="hp-gate-line"></p>
|
||||
<p class="muted hp-acct-hint" id="hp-acct-hint">永续腿→合约账户 · 期权腿→期权账户</p>
|
||||
</div>
|
||||
|
||||
<div id="hp-tab-perp_options" class="hp-tab-panel" role="tabpanel">
|
||||
<div class="options-dual-grid" id="hp-po-layout">
|
||||
<div class="card">
|
||||
<h2>永续(列表行情)</h2>
|
||||
<div class="form-row">
|
||||
<h2>永续 · <span id="hp-perp-uly-label">ETH</span> <span class="muted hp-acct-tag" id="hp-perp-acct-tag">合约账户</span></h2>
|
||||
<div class="form-row hp-uly-row">
|
||||
<button type="button" class="btn-secondary hp-uly-btn active" data-uly="ETH">ETH</button>
|
||||
<button type="button" class="btn-secondary hp-uly-btn" data-uly="BTC">BTC</button>
|
||||
<select id="hp-direction">
|
||||
@@ -37,7 +38,7 @@
|
||||
<option value="short">做空</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="hp-perp-quote" class="muted" style="margin:8px 0;line-height:1.6">加载中…</div>
|
||||
<div id="hp-perp-quote" class="muted hp-quote-line">加载中…</div>
|
||||
<div class="form-row" style="flex-wrap:wrap">
|
||||
<label>开仓价 <input type="number" step="any" id="hp-entry" /></label>
|
||||
<label>止盈 <input type="number" step="any" id="hp-tp" /></label>
|
||||
@@ -47,20 +48,27 @@
|
||||
<p class="muted" id="hp-sizing-line"></p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>期权(列表) · <span id="hp-opt-type-label">Put</span></h2>
|
||||
<h2>期权(列表) · <span id="hp-opt-type-label">Put</span> <span class="muted hp-acct-tag" id="hp-opt-acct-tag">期权账户</span></h2>
|
||||
<div class="form-row">
|
||||
<select id="hp-exp-select"><option value="">选择到期日</option></select>
|
||||
<button type="button" class="btn-secondary" id="hp-load-chain">刷新链</button>
|
||||
</div>
|
||||
<div id="hp-index-line" class="muted"></div>
|
||||
<div class="form-row hp-money-row">
|
||||
<button type="button" class="btn-secondary hp-money-btn active" data-money="all">全部</button>
|
||||
<button type="button" class="btn-secondary hp-money-btn" data-money="itm">实值</button>
|
||||
<button type="button" class="btn-secondary hp-money-btn" data-money="otm">虚值</button>
|
||||
<span class="muted hp-money-hint">实值含平值</span>
|
||||
</div>
|
||||
<div id="hp-index-line" class="muted hp-quote-line"></div>
|
||||
<div id="hp-opt-bal-line" class="muted hp-quote-line"></div>
|
||||
<div class="options-strike-table-wrap">
|
||||
<table class="options-strike-table" id="hp-strike-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>行权价</th>
|
||||
<th>类型</th>
|
||||
<th>实虚值</th>
|
||||
<th>卖一/张</th>
|
||||
<th>买一</th>
|
||||
<th>买一/张</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -108,13 +116,14 @@
|
||||
<div id="hp-tab-options_options" class="hp-tab-panel hidden" role="tabpanel" hidden>
|
||||
<div class="options-dual-grid" id="hp-oo-layout">
|
||||
<div class="card">
|
||||
<h2>期期参数</h2>
|
||||
<div class="form-row">
|
||||
<h2>期期参数 · <span id="hp-oo-uly-label">ETH</span> <span class="muted hp-acct-tag">期权账户</span></h2>
|
||||
<div class="form-row hp-uly-row">
|
||||
<button type="button" class="btn-secondary hp-uly-btn-oo active" data-uly="ETH">ETH</button>
|
||||
<button type="button" class="btn-secondary hp-uly-btn-oo" data-uly="BTC">BTC</button>
|
||||
<label>目标价 S* <input type="number" step="any" id="hp-target" /></label>
|
||||
</div>
|
||||
<div id="hp-oo-index" class="muted"></div>
|
||||
<div id="hp-oo-index" class="muted hp-quote-line"></div>
|
||||
<div id="hp-oo-bal-line" class="muted hp-quote-line"></div>
|
||||
<div id="hp-oo-legs" class="muted" style="margin-top:8px;line-height:1.6">尚未选用两腿</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
@@ -127,18 +136,18 @@
|
||||
<table class="options-strike-table options-strike-table--t" id="hp-oo-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" class="opt-t-head-call">Call</th>
|
||||
<th colspan="3" class="opt-t-head-call">Call</th>
|
||||
<th class="opt-t-head-mid">行权</th>
|
||||
<th colspan="2" class="opt-t-head-put">Put</th>
|
||||
<th colspan="3" class="opt-t-head-put">Put</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>卖一</th><th>选用</th>
|
||||
<th>卖一/张</th><th>实虚值</th><th>选用</th>
|
||||
<th>K</th>
|
||||
<th>卖一</th><th>选用</th>
|
||||
<th>实虚值</th><th>卖一/张</th><th>选用</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="hp-oo-tbody">
|
||||
<tr><td colspan="5" class="muted">请刷新期权链</td></tr>
|
||||
<tr><td colspan="7" class="muted">请刷新期权链</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -186,4 +195,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/hedge_plan.js?v=3"></script>
|
||||
<script src="/static/hedge_plan.js?v=4"></script>
|
||||
|
||||
Reference in New Issue
Block a user