Add T-shaped options chain view with straddle metrics (phase A).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-11 15:00:50 +08:00
parent c9c8388250
commit 6f6545ce52
5 changed files with 443 additions and 19 deletions
+46
View File
@@ -358,3 +358,49 @@ def equivalent_contract_leverage(
if eth_amount <= 0 or total_premium <= 0:
return None
return round(float(index_px) * float(eth_amount) / float(total_premium), 1)
def straddle_ask_per_unit(
call_ask: float | None,
put_ask: float | None,
) -> float | None:
"""跨式双买:每 1 标的币的卖一报价之和."""
if call_ask is None or put_ask is None:
return None
if float(call_ask) <= 0 or float(put_ask) <= 0:
return None
return round(float(call_ask) + float(put_ask), 4)
def straddle_premium_total(
call_ask: float | None,
put_ask: float | None,
eth_amount: float | None,
) -> float | None:
"""跨式双买权利金总额(USDC)."""
per = straddle_ask_per_unit(call_ask, put_ask)
if per is None or eth_amount is None or float(eth_amount) <= 0:
return None
return round(per * float(eth_amount), 2)
def straddle_breakeven_band(
strike: float | None,
combined_ask_per_unit: float | None,
) -> tuple[float | None, float | None]:
"""跨式到期平衡带:下平衡 ~ 上平衡(按双卖一报价和)."""
if strike is None or combined_ask_per_unit is None:
return None, None
k = float(strike)
d = float(combined_ask_per_unit)
return round(k - d, 2), round(k + d, 2)
def format_straddle_band(
strike: float | None,
combined_ask_per_unit: float | None,
) -> str:
lo, hi = straddle_breakeven_band(strike, combined_ask_per_unit)
if lo is None or hi is None:
return ""
return f"{lo:.0f} ~ {hi:.0f}"
+31 -6
View File
@@ -7,23 +7,32 @@
<div class="options-dual-grid">
<div class="card options-order-card">
<h2>期权下单</h2>
<p class="muted options-hint">报价单位为每 1 ETH/BTC;1 张 = 0.01.卖一/买一列为 <strong>价格/张数</strong>;卖一无挂单时以标记价估算并标 <strong>~</strong>.链展示近 <span id="opt-chain-dte">14</span> 日到期,标注实值/虚值;<strong>到期平衡</strong>按卖一预估(无卖一按标记价).资金划转与 USDT/USDC 兑换见「系统设置 → 期权设置」.</p>
<p class="muted options-hint">报价单位为每 1 ETH/BTC;1 张 = 0.01.<strong>列表</strong>卖一/买一;<strong>T 型</strong>仅卖一(买方开仓),中间为跨式双买测算.卖一无挂单时以标记价估算并标 <strong>~</strong>.链展示近 <span id="opt-chain-dte">14</span> 日到期.<strong>T 型</strong>默认 ATM ±5 档,可展开全部.</p>
<div class="form-row options-chain-toolbar">
<button type="button" class="btn-secondary opt-uly-btn active" data-uly="ETH">ETH</button>
<button type="button" class="btn-secondary opt-uly-btn" data-uly="BTC">BTC</button>
<select id="opt-exp-select"><option value="">选择到期日</option></select>
<button type="button" class="btn-secondary opt-type-btn active" data-type="C">看涨 Call</button>
<button type="button" class="btn-secondary opt-type-btn" data-type="P">看跌 Put</button>
<span class="opt-chain-view-group">
<button type="button" class="btn-secondary opt-view-btn active" data-view="list">列表</button>
<button type="button" class="btn-secondary opt-view-btn" data-view="t">T 型</button>
</span>
<span id="opt-type-btn-group" class="opt-type-btn-group">
<button type="button" class="btn-secondary opt-type-btn active" data-type="C">看涨 Call</button>
<button type="button" class="btn-secondary opt-type-btn" data-type="P">看跌 Put</button>
</span>
<button type="button" class="btn-secondary opt-money-btn active" data-money="all">全部</button>
<button type="button" class="btn-secondary opt-money-btn" data-money="itm">实值</button>
<button type="button" class="btn-secondary opt-money-btn" data-money="otm">虚值</button>
<label id="opt-strike-expand-wrap" class="opt-strike-expand-label" hidden>
<input type="checkbox" id="opt-strike-expand-all"> 展开全部
</label>
<button type="button" class="btn-secondary" id="opt-load-chain">刷新链</button>
</div>
<div id="opt-index-line" class="muted"></div>
<div class="options-strike-table-wrap">
<div class="options-strike-table-wrap" id="opt-strike-table-wrap">
<table class="options-strike-table" id="opt-strike-table">
<thead>
<tr>
<tr id="opt-strike-head-list">
<th>行权价</th>
<th>类型</th>
<th>合约</th>
@@ -33,6 +42,22 @@
<th>距平衡</th>
<th>操作</th>
</tr>
<tr id="opt-strike-head-t" class="hidden">
<th colspan="3" class="opt-t-head-call">Call</th>
<th colspan="3" class="opt-t-head-mid">跨式</th>
<th colspan="3" class="opt-t-head-put">Put</th>
</tr>
<tr id="opt-strike-head-t-cols" class="hidden">
<th>卖一/张</th>
<th>类型</th>
<th>操作</th>
<th>行权价</th>
<th title="Call卖一+Put卖一(每1币)">双买/币</th>
<th title="到期测算平衡带">平衡带</th>
<th>类型</th>
<th>卖一/张</th>
<th>操作</th>
</tr>
</thead>
<tbody id="opt-strike-tbody">
<tr><td colspan="8" class="muted">请选择到期日</td></tr>
@@ -215,4 +240,4 @@
</div>
</div>
<script src="/static/options_expiry_countdown.js?v=1"></script>
<script src="/static/options_panel.js?v=27"></script>
<script src="/static/options_panel.js?v=28"></script>