Sell residual options at latest bid via IOC limit, not market.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 14:25:03 +08:00
parent 62c91d4bd0
commit 640ecc9530
7 changed files with 89 additions and 13 deletions
+29
View File
@@ -201,6 +201,35 @@ class BinanceTradeClient:
data = self._signed(self._eapi, "POST", "/eapi/v1/order", params)
return self._fill_from_eapi(symbol, data)
def place_option_ioc(
self,
*,
symbol: str,
side: str, # BUY|SELL
quantity: float,
price: float,
reduce_only: bool = False,
) -> LiveFill:
"""期权限价 IOC:按买一/卖一价吃单,未成交部分取消。"""
qty = str(int(round(quantity)))
if qty == "0":
qty = "1"
px = f"{float(price):.8f}".rstrip("0").rstrip(".")
if not px or px == "0":
raise RuntimeError("币安期权 IOC 价格无效")
params: dict[str, Any] = {
"symbol": symbol,
"side": side.upper(),
"type": "LIMIT",
"timeInForce": "IOC",
"quantity": qty,
"price": px,
}
if reduce_only:
params["reduceOnly"] = "true"
data = self._signed(self._eapi, "POST", "/eapi/v1/order", params)
return self._fill_from_eapi(symbol, data)
def _fill_from_eapi(self, symbol: str, data: dict[str, Any]) -> LiveFill:
ord_id = str(data.get("orderId") or data.get("id") or "")
avg = safe_float(data.get("avgPrice")) or safe_float(data.get("price"))