Use bid1-only option closes with hard-disabled market exits.
Manual close checks liquidity only; target auto still requires 2x recycle hold once, then reuses the shared bid1 executor. Add /options/guide doc and update hedge-plan refs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -166,12 +166,14 @@ def estimate_close_by_bids(
|
||||
mark_px: float | None = None,
|
||||
intrinsic_px: float | None = None,
|
||||
min_bid_ratio: float = BID_CLOSE_MIN_RATIO,
|
||||
max_levels: int = 1,
|
||||
) -> dict[str, Any]:
|
||||
"""按买一到买N逐档估算限价卖出可收回金额;残档买盘不参与估算与自动平仓."""
|
||||
"""按买盘估算限价卖出可收回金额;默认只估算买一(与实盘平仓一致);残档不参与."""
|
||||
target = max(0, int(float(sheets or 0)))
|
||||
remaining = target
|
||||
total_received = 0.0
|
||||
levels: list[dict[str, Any]] = []
|
||||
max_lv = max(1, int(max_levels or 1))
|
||||
empty = {
|
||||
"levels": [],
|
||||
"covered_sheets": 0,
|
||||
@@ -183,6 +185,7 @@ def estimate_close_by_bids(
|
||||
"bid_invalid": False,
|
||||
"bid_invalid_reason": None,
|
||||
"auto_close_blocked": False,
|
||||
"max_levels": max_lv,
|
||||
}
|
||||
if target <= 0 or ct_mult <= 0:
|
||||
return empty
|
||||
@@ -196,7 +199,7 @@ def estimate_close_by_bids(
|
||||
out["auto_close_blocked"] = True
|
||||
out["raw_bid_px"] = _safe_px((bids or [{}])[0].get("px")) if bids else None
|
||||
return out
|
||||
for i, level in enumerate(usable, start=1):
|
||||
for i, level in enumerate(usable[:max_lv], start=1):
|
||||
if remaining <= 0:
|
||||
break
|
||||
try:
|
||||
@@ -223,7 +226,7 @@ def estimate_close_by_bids(
|
||||
remaining -= take
|
||||
covered = target - remaining
|
||||
avg_px = (total_received / eth_amount_from_sheets(covered, ct_mult)) if covered > 0 else None
|
||||
# 净盈亏 = 按买盘可回收 − 全部权利金(与「可落袋」口径一致;买一不够会展开更多档)
|
||||
# 净盈亏 = 本轮买盘可回收 − 全部权利金(买一不够时剩余张数计入 uncovered)
|
||||
estimated_pnl = None
|
||||
estimated_pnl_ratio_pct = None
|
||||
if premium_paid is not None and covered > 0:
|
||||
@@ -242,6 +245,7 @@ def estimate_close_by_bids(
|
||||
"bid_invalid": False,
|
||||
"bid_invalid_reason": None,
|
||||
"auto_close_blocked": False,
|
||||
"max_levels": max_lv,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user