MCPcopy Create free account
hub / github.com/ccxt/ccxt / close_position

Method close_position

python/ccxt/bitmex.py:3408–3452  ·  view source on GitHub ↗

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={})

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 6

parse_orderMethod · 0.95
privatePostOrderMethod · 0.65
load_marketsMethod · 0.45
marketMethod · 0.45
capitalizeMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected