closes open positions for a market https://docs.bitmex.com/api-explorer/order-new https://docs.bitmex.com/api-explorer/order-close-position :param str symbol: Unified CCXT market symbol :param str side: the buy or sell side of the closing order, if the posi
(self, symbol: str, side: OrderSide = None, params={})
| 3406 | } |
| 3407 | |
| 3408 | def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order: |
| 3409 | """ |
| 3410 | closes open positions for a market |
| 3411 | |
| 3412 | https://docs.bitmex.com/api-explorer/order-new |
| 3413 | https://docs.bitmex.com/api-explorer/order-close-position |
| 3414 | |
| 3415 | :param str symbol: Unified CCXT market symbol |
| 3416 | :param str side: the buy or sell side of the closing order, if the position is long set the side to sell, reduceOnly is implied |
| 3417 | :param dict [params]: extra parameters specific to the bingx api endpoint |
| 3418 | :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>` |
| 3419 | """ |
| 3420 | self.load_markets() |
| 3421 | market = self.market(symbol) |
| 3422 | request = { |
| 3423 | 'symbol': market['id'], |
| 3424 | 'side': self.capitalize(side), |
| 3425 | 'execInst': 'Close', |
| 3426 | } |
| 3427 | response = self.privatePostOrder(self.extend(request, params)) |
| 3428 | # |
| 3429 | # { |
| 3430 | # "account": 395724, |
| 3431 | # "avgPx": 66358.8, |
| 3432 | # "cumQty": 200, |
| 3433 | # "currency": "USDT", |
| 3434 | # "execInst": "Close", |
| 3435 | # "leavesQty": 0, |
| 3436 | # "ordStatus": "Filled", |
| 3437 | # "ordType": "Market", |
| 3438 | # "orderID": "4e1ef998-33c1-4736-b58b-9d8b4d085c49", |
| 3439 | # "orderQty": 200, |
| 3440 | # "pool": "Primary", |
| 3441 | # "settlCurrency": "USDt", |
| 3442 | # "side": "Sell", |
| 3443 | # "strategy": "OneWay", |
| 3444 | # "symbol": "XBTUSDT", |
| 3445 | # "text": "Submitted via API.", |
| 3446 | # "timeInForce": "ImmediateOrCancel", |
| 3447 | # "timestamp": "2026-04-02T05:20:26.607Z", |
| 3448 | # "transactTime": "2026-04-02T05:20:26.606Z", |
| 3449 | # "workingIndicator": False |
| 3450 | # } |
| 3451 | # |
| 3452 | return self.parse_order(response, market) |
| 3453 | |
| 3454 | def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody): |
| 3455 | if response is None: |
nothing calls this directly
no test coverage detected