Add OKX trading-account USDC auto-swap and lock exit target while in position.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -320,12 +320,22 @@ def apply_risk_sizing_to_ledger(
|
||||
option_ask: float,
|
||||
db: Database | None = None,
|
||||
) -> RiskSizingResult:
|
||||
"""计算并写入 perp/option/exit;非以损定仓模式直接 ok 跳过。"""
|
||||
"""计算并写入 perp/option/exit;非以损定仓模式直接 ok 跳过。持仓中拒绝改写。"""
|
||||
database = db or get_db()
|
||||
ledger = Ledger(database)
|
||||
if not is_risk_based(ledger):
|
||||
return RiskSizingResult(ok=True, detail="manual_sizing_skip")
|
||||
|
||||
# 有活跃仓:本组成场参数已锁定,禁止重算覆盖
|
||||
pos = database.fetchone("SELECT status, group_id FROM positions WHERE id=1")
|
||||
if pos is not None:
|
||||
st = str(pos["status"] or "flat")
|
||||
if st in ("open", "half_open", "option_closed_perp_pending", "opening"):
|
||||
return RiskSizingResult(
|
||||
ok=False,
|
||||
detail="持仓中已锁定本组成交目标与名义,平仓后再自动计算",
|
||||
)
|
||||
|
||||
r = compute_risk_sizing(index_px=index_px, option_ask=option_ask, db=database)
|
||||
if not r.ok:
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user