永期改为市价选约:左同期权人工选,右去掉选约条件.
左侧到期/CallPut/全部实虚值/展开全部;右侧仅资金杠杆与出场;下单走已选合约立即开仓而非条件盯盘. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -266,7 +266,10 @@ def validate_option_primary_moneyness(
|
||||
return "行权价或指数无效"
|
||||
m_want = (moneyness or "atm").strip().lower()
|
||||
m_got = classify_moneyness(opt_type=o, strike=k, index_px=s)
|
||||
if m_want == "itm":
|
||||
if m_want in ("all", "any", ""):
|
||||
# 市价人工选约:不限制虚实值
|
||||
pass
|
||||
elif m_want == "itm":
|
||||
if not is_itm_or_atm(opt_type=o, strike=k, index_px=s):
|
||||
return "所选须为实值或平值"
|
||||
elif m_want == "atm":
|
||||
@@ -280,17 +283,27 @@ def validate_option_primary_moneyness(
|
||||
else:
|
||||
return "期权类型(实/平/虚)无效"
|
||||
|
||||
interval = float(_sf(strike_interval) or DEFAULT_STRIKE_INTERVAL)
|
||||
# 间隔/最短到期/杠杆门槛:仅条件单使用;传 0 表示市价下单跳过
|
||||
interval_raw = _sf(strike_interval)
|
||||
if interval_raw is None:
|
||||
interval_raw = DEFAULT_STRIKE_INTERVAL
|
||||
interval = float(interval_raw)
|
||||
if interval > 0 and abs(k - s) > interval + 1e-9:
|
||||
return f"行权价偏离指数 {abs(k - s):.1f} > 间隔 {interval:.0f}"
|
||||
|
||||
min_h = float(_sf(min_hours) or DEFAULT_MIN_HOURS)
|
||||
min_h_raw = _sf(min_hours)
|
||||
if min_h_raw is None:
|
||||
min_h_raw = DEFAULT_MIN_HOURS
|
||||
min_h = float(min_h_raw)
|
||||
h = _sf(hours_to_expiry)
|
||||
if min_h > 0 and h is not None and h < min_h:
|
||||
return f"剩余到期约 {h:.1f}h,低于最短 {min_h:.0f}h"
|
||||
|
||||
a = _sf(ask)
|
||||
min_lev = effective_min_opt_leverage(m_want if m_want != "atm" else m_got or "atm", min_opt_leverage)
|
||||
lev_cfg = _sf(min_opt_leverage)
|
||||
if lev_cfg is not None and lev_cfg <= 0:
|
||||
return None
|
||||
min_lev = effective_min_opt_leverage(m_want if m_want not in ("atm", "all", "any", "") else (m_got or "atm"), min_opt_leverage)
|
||||
if min_lev > 0 and a is not None and a > 0:
|
||||
lev = s / a
|
||||
if lev < min_lev:
|
||||
@@ -336,24 +349,27 @@ def validate_option_primary_watch(body: dict[str, Any]) -> Optional[str]:
|
||||
|
||||
|
||||
def validate_option_primary_start(body: dict[str, Any]) -> Optional[str]:
|
||||
market = body.get("market_order") in (True, 1, "1", "true", "yes", "on")
|
||||
need = (
|
||||
"direction",
|
||||
"contracts",
|
||||
"opt_inst_id",
|
||||
"sheets",
|
||||
"exchange_symbol",
|
||||
"premium_budget",
|
||||
"option_target_points",
|
||||
"perp_target_points",
|
||||
"option_perp_ratio",
|
||||
)
|
||||
if not market:
|
||||
need = need + ("premium_budget",)
|
||||
for k in need:
|
||||
if body.get(k) in (None, ""):
|
||||
return f"缺少字段: {k}"
|
||||
try:
|
||||
if float(body["contracts"]) <= 0 or float(body["sheets"]) <= 0:
|
||||
return "张数必须大于 0"
|
||||
if float(body["premium_budget"]) <= 0:
|
||||
prem = _sf(body.get("premium_budget"))
|
||||
if not market and (prem is None or prem <= 0):
|
||||
return "权利金须大于 0"
|
||||
if float(body["option_target_points"]) <= 0 or float(body["perp_target_points"]) <= 0:
|
||||
return "目标位点数须大于 0"
|
||||
@@ -374,6 +390,9 @@ def validate_option_primary_start(body: dict[str, Any]) -> Optional[str]:
|
||||
want = opt_type_for_view(direction)
|
||||
if opt_type != want:
|
||||
return f"以期权为主时做{'多' if direction == 'long' else '空'}须用 {'Call' if want == 'C' else 'Put'}"
|
||||
# 市价下单:左侧人工选约,跳过条件单(间隔/最短到期/杠杆门槛)
|
||||
if market:
|
||||
return None
|
||||
moneyness = str(body.get("moneyness") or body.get("option_moneyness") or "otm").strip().lower()
|
||||
from lib.hedge_plan.hedge_plan_moneyness_lib import parse_strike_from_inst
|
||||
|
||||
|
||||
@@ -45,47 +45,55 @@
|
||||
|
||||
<div id="hp-tab-perp_options" class="hp-tab-panel" role="tabpanel">
|
||||
<div class="options-dual-grid" id="hp-po-layout">
|
||||
<!-- 左:期权选择 -->
|
||||
<!-- 左:市价选约(与期权下单同风格,人工选) -->
|
||||
<div class="card hp-po-left-card hp-po-select-card">
|
||||
<div class="hp-po-left-stack">
|
||||
<div class="hp-po-inner-card hp-opt-card">
|
||||
<h2>期权选择 · <span id="hp-opt-type-label">Call</span> <span class="muted hp-acct-tag" id="hp-opt-acct-tag">币本位</span></h2>
|
||||
<div class="form-row hp-uly-row">
|
||||
<h2>市价选约 · <span id="hp-opt-type-label">Call</span> <span class="muted hp-acct-tag" id="hp-opt-acct-tag">币本位</span></h2>
|
||||
<div class="form-row hp-opt-toolbar hp-po-opt-toolbar options-chain-toolbar">
|
||||
<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>
|
||||
</div>
|
||||
<div class="hp-po-top">
|
||||
<div class="hp-oo-seg hp-po-dir-seg" role="group" aria-label="期权类型">
|
||||
<button type="button" class="btn-secondary hp-po-dir is-selected" data-dir="long" title="买 Call → 永续空"><span class="hp-oo-check" aria-hidden="true">✓</span>Call</button>
|
||||
<button type="button" class="btn-secondary hp-po-dir" data-dir="short" title="买 Put → 永续多"><span class="hp-oo-check" aria-hidden="true">✓</span>Put</button>
|
||||
</div>
|
||||
<span class="muted hp-po-pair-hint" id="hp-po-pair-hint">买 Call + 永续空</span>
|
||||
</div>
|
||||
<div class="form-row hp-opt-toolbar hp-po-opt-toolbar">
|
||||
<select id="hp-exp-select"><option value="">选择到期日</option></select>
|
||||
<span class="hp-oo-seg hp-po-dir-seg" role="group" aria-label="期权类型">
|
||||
<button type="button" class="btn-secondary hp-po-dir is-selected" data-dir="long" title="买 Call → 永续空"><span class="hp-oo-check" aria-hidden="true">✓</span>看涨 Call</button>
|
||||
<button type="button" class="btn-secondary hp-po-dir" data-dir="short" title="买 Put → 永续多"><span class="hp-oo-check" aria-hidden="true">✓</span>看跌 Put</button>
|
||||
</span>
|
||||
<span class="hp-po-ins-money" id="hp-po-ins-money" hidden>
|
||||
<button type="button" class="btn-secondary hp-money-btn active" data-money="itm" title="实值+平值">实值/平值</button>
|
||||
<button type="button" class="btn-secondary hp-money-btn" data-money="atm" title="仅平值">仅平值</button>
|
||||
</span>
|
||||
<button type="button" class="btn-secondary" id="hp-recommend-opt" title="按当前类型自动匹配最近合约">自动匹配</button>
|
||||
<span class="hp-po-mkt-money" id="hp-po-mkt-money">
|
||||
<button type="button" class="btn-secondary hp-money-btn active" data-money="all" title="全部行权价(默认窗口)">全部</button>
|
||||
<button type="button" class="btn-secondary hp-money-btn" data-money="itm" title="实值(含平值)">实值</button>
|
||||
<button type="button" class="btn-secondary hp-money-btn" data-money="otm" title="虚值">虚值</button>
|
||||
</span>
|
||||
<label class="opt-strike-expand-label hp-po-expand-label" title="展开该到期全部行权价">
|
||||
<input type="checkbox" id="hp-strike-expand-all"> 展开全部
|
||||
</label>
|
||||
<button type="button" class="btn-secondary" id="hp-load-chain">刷新链</button>
|
||||
<span id="hp-index-line" class="hp-po-index" aria-live="polite">指数 —</span>
|
||||
</div>
|
||||
<p class="muted hp-po-chain-hint">点「选择」填入右侧下单;比例默认 2(期权名义:永续名义),如期权 1 BTC → 永续约 0.5 BTC。</p>
|
||||
<p class="muted hp-po-chain-hint" id="hp-po-pair-hint">买 Call + 永续空 · 点「选择」填入右侧市价下单;比例默认 2(期权 1 → 永续 0.5)。</p>
|
||||
{# 条件单残留字段:隐藏,市价下单不用 #}
|
||||
<input type="hidden" id="hp-min-hours" value="0" />
|
||||
<input type="hidden" id="hp-strike-interval" value="0" />
|
||||
<input type="hidden" id="hp-opt-leverage" value="0" />
|
||||
<input type="hidden" id="hp-money-select" value="all" />
|
||||
<div class="options-strike-table-wrap hp-strike-table-wrap--6">
|
||||
<table class="options-strike-table" id="hp-strike-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>行权价</th>
|
||||
<th>实虚值</th>
|
||||
<th title="指数÷卖一">杠杆</th>
|
||||
<th>类型</th>
|
||||
<th>合约</th>
|
||||
<th>卖一/张</th>
|
||||
<th title="指数÷卖一">杠杆</th>
|
||||
<th>买一/张</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="hp-strike-tbody">
|
||||
<tr><td colspan="6" class="muted">请刷新期权链</td></tr>
|
||||
<tr><td colspan="7" class="muted">请刷新期权链</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -98,10 +106,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 右:下单参数 -->
|
||||
<!-- 右:市价下单参数(无选约条件;条件单另议) -->
|
||||
<div class="card hp-po-right-card hp-po-order-card">
|
||||
<h2>
|
||||
<span id="hp-po-mode-badge" class="hp-po-mode-badge">以期权为主</span>
|
||||
<span id="hp-po-mode-badge" class="hp-po-mode-badge">市价下单</span>
|
||||
<span id="hp-po-card-title">下单</span>
|
||||
· <span id="hp-perp-uly-label">ETH</span>
|
||||
<span class="muted hp-acct-tag" id="hp-perp-acct-tag">合约账户</span>
|
||||
@@ -109,9 +117,9 @@
|
||||
<details class="tip-collapse hp-rule-collapse">
|
||||
<summary class="tip-collapse-summary">规则说明</summary>
|
||||
<div class="tip-collapse-body rule-tip">
|
||||
<p><strong>市价下单</strong>:左侧人工选约(同期权页:到期/Call·Put/实虚值),点「选择」后右侧下单;非条件盯盘。</p>
|
||||
<p><strong>组合</strong>:买 Call → 永续空;买 Put → 永续多。</p>
|
||||
<p><strong>比例</strong>:期权:永续默认 <strong>2</strong>(期权名义 ÷ 比例 = 永续名义)。例:期权 1 BTC → 永续 0.5 BTC。</p>
|
||||
<p><strong>账户</strong>:永续腿合约账户(USDT);期权腿币本位(交易账户 USDT 买币)。</p>
|
||||
</div>
|
||||
</details>
|
||||
<div class="hp-po-inner-card hp-po-perp-quote-card">
|
||||
@@ -152,37 +160,12 @@
|
||||
<span class="hp-po-field-lab">永续杠杆 <em>开仓</em></span>
|
||||
<input type="number" step="1" id="hp-perp-leverage" value="{{ hedge_plan_eth_leverage | default(5) }}" autocomplete="off" inputmode="numeric" data-lpignore="true" data-1p-ignore="true" data-form-type="other" title="默认取 env 永期·永续杠杆" />
|
||||
</label>
|
||||
<label class="hp-po-field">
|
||||
<span class="hp-po-field-lab">期权杠杆 <em>校验</em></span>
|
||||
<input type="number" step="1" id="hp-opt-leverage" value="100" autocomplete="off" inputmode="numeric" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
||||
</label>
|
||||
<label class="hp-po-field">
|
||||
<span class="hp-po-field-lab">比例 <em>期权:永续</em></span>
|
||||
<input type="number" step="any" min="0.1" id="hp-opt-perp-ratio" value="2" autocomplete="off" inputmode="decimal" data-lpignore="true" data-1p-ignore="true" data-form-type="other" title="默认2:期权名义÷比例=永续名义" />
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section class="hp-po-section" aria-labelledby="hp-po-sec-select">
|
||||
<h3 id="hp-po-sec-select" class="hp-po-section-title">选约过滤</h3>
|
||||
<div class="hp-po-fields hp-po-fields--section hp-po-fields--select">
|
||||
<label class="hp-po-field">
|
||||
<span class="hp-po-field-lab">到期最短 <em>h</em></span>
|
||||
<input type="number" step="1" id="hp-min-hours" value="36" autocomplete="off" inputmode="numeric" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
||||
</label>
|
||||
<label class="hp-po-field">
|
||||
<span class="hp-po-field-lab">行权间隔 <em>点</em></span>
|
||||
<input type="number" step="any" id="hp-strike-interval" value="15" autocomplete="off" inputmode="decimal" data-lpignore="true" data-1p-ignore="true" data-form-type="other" />
|
||||
</label>
|
||||
<label class="hp-po-field hp-po-field--type">
|
||||
<span class="hp-po-field-lab">虚实值</span>
|
||||
<select id="hp-money-select" aria-label="虚实值类型">
|
||||
<option value="otm" selected>虚值</option>
|
||||
<option value="itm">实值/平值</option>
|
||||
<option value="atm">仅平值</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</section>
|
||||
<section class="hp-po-section" aria-labelledby="hp-po-sec-exit">
|
||||
<h3 id="hp-po-sec-exit" class="hp-po-section-title">出场条件</h3>
|
||||
<div class="hp-po-fields hp-po-fields--section">
|
||||
@@ -203,7 +186,7 @@
|
||||
</div>
|
||||
<div class="form-row hp-action-row hp-po-action-row">
|
||||
<span id="hp-po-strategy-status" class="hp-po-strategy-status" aria-live="polite"></span>
|
||||
<button type="button" class="primary" id="hp-preview-btn" title="以期权为主=盯盘启动">策略启动</button>
|
||||
<button type="button" class="primary" id="hp-preview-btn" title="按左侧已选合约市价开仓(期权+永续)">市价下单</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user