Add option close liquidity gate with 30% bid/mark cap.

Block new opens while flat legs wait; emergency close bypasses the check.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-25 09:05:04 +08:00
parent 8c14759e78
commit 9fd2a842af
11 changed files with 136 additions and 28 deletions
+6
View File
@@ -20,6 +20,7 @@ KEYS = (
"leverage",
"min_option_hours",
"min_option_leverage",
"close_bid_mark_max_pct",
"perp_qty_eth",
"option_qty_eth",
)
@@ -33,6 +34,7 @@ class StrategySettingsBody(BaseModel):
leverage: float | None = Field(default=None, ge=1, le=125)
min_option_hours: float | None = Field(default=None, ge=1, le=720)
min_option_leverage: float | None = Field(default=None, ge=1, le=10000)
close_bid_mark_max_pct: float | None = Field(default=None, ge=1, le=100)
perp_qty_eth: float | None = Field(default=None, ge=0.01, le=100)
option_qty_eth: float | None = Field(default=None, ge=0.01, le=100)
@@ -60,6 +62,10 @@ def _read_settings() -> dict:
db.get_setting("min_option_leverage", str(s.min_option_leverage))
or s.min_option_leverage
),
"close_bid_mark_max_pct": float(
db.get_setting("close_bid_mark_max_pct", str(s.close_bid_mark_max_pct))
or s.close_bid_mark_max_pct
),
"perp_qty_eth": float(
db.get_setting("perp_qty_eth", str(s.perp_qty_eth)) or s.perp_qty_eth
),
+2
View File
@@ -37,6 +37,8 @@ async def sim_open_group(
_user: Annotated[str, Depends(require_user)],
body: ManualOpenBody | None = None,
) -> dict:
if Matcher().has_open_position():
raise HTTPException(status_code=409, detail="有未平仓,禁止开下一组")
gw = get_gateway()
pick = await gw.pick_for_open_async()
if pick is None: