Extend semi-auto with ITM/ATM/OTM, offset, and 1:4 sizing.
Moneyness and perp:option units are plan-only; OTM enforces leverage >=180. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -428,12 +428,18 @@ def compute_risk_sizing(
|
||||
index_px: float,
|
||||
option_ask: float,
|
||||
db: Database | None = None,
|
||||
perp_unit: float | None = None,
|
||||
option_unit: float | None = None,
|
||||
) -> RiskSizingResult:
|
||||
database = db or get_db()
|
||||
ledger = Ledger(database)
|
||||
s = get_settings()
|
||||
fee_rate = ledger.get_setting_float("fee_rate", s.fee_rate)
|
||||
perp_u, opt_u, exit_u = read_risk_units(ledger)
|
||||
if perp_unit is not None and float(perp_unit) > 0:
|
||||
perp_u = float(perp_unit)
|
||||
if option_unit is not None and float(option_unit) > 0:
|
||||
opt_u = float(option_unit)
|
||||
basis_raw = ledger.get_setting_str(
|
||||
"risk_leverage_basis", s.risk_leverage_basis
|
||||
) or s.risk_leverage_basis
|
||||
@@ -682,6 +688,8 @@ def apply_risk_sizing_to_ledger(
|
||||
index_px: float,
|
||||
option_ask: float,
|
||||
db: Database | None = None,
|
||||
perp_unit: float | None = None,
|
||||
option_unit: float | None = None,
|
||||
) -> RiskSizingResult:
|
||||
"""计算并写入 perp/option/exit;非以损定仓模式直接 ok 跳过。持仓中拒绝改写。"""
|
||||
database = db or get_db()
|
||||
@@ -699,7 +707,13 @@ def apply_risk_sizing_to_ledger(
|
||||
detail="持仓中已锁定本组成交目标与名义,平仓后再自动计算",
|
||||
)
|
||||
|
||||
r = compute_risk_sizing(index_px=index_px, option_ask=option_ask, db=database)
|
||||
r = compute_risk_sizing(
|
||||
index_px=index_px,
|
||||
option_ask=option_ask,
|
||||
db=database,
|
||||
perp_unit=perp_unit,
|
||||
option_unit=option_unit,
|
||||
)
|
||||
if not r.ok:
|
||||
return r
|
||||
|
||||
|
||||
Reference in New Issue
Block a user