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

Method close_position

python/ccxt/async_support/bingx.py:5953–6020  ·  view source on GitHub ↗

closes open positions for a market https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20All%20Positions https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20position%20by%20position%20ID https://bingx-api.github.io/docs-v3/#/e

(self, symbol: str, side: OrderSide = None, params={})

Source from the content-addressed store, hash-verified

5951 })
5952
5953 async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
5954 """
5955 closes open positions for a market
5956
5957 https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20All%20Positions
5958 https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20position%20by%20position%20ID
5959 https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Close%20all%20positions%20in%20bulk
5960
5961 :param str symbol: Unified CCXT market symbol
5962 :param str [side]: not used by bingx
5963 :param dict [params]: extra parameters specific to the bingx api endpoint
5964 :param str|None [params.positionId]: the id of the position you would like to close
5965 :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
5966 """
5967 await self.load_markets()
5968 market = self.market(symbol)
5969 positionId = self.safe_string(params, 'positionId')
5970 request = {}
5971 response: dict
5972 if positionId is not None:
5973 response = await self.swapV1PrivatePostTradeClosePosition(self.extend(request, params))
5974 #
5975 # {
5976 # "code": 0,
5977 # "msg": "",
5978 # "timestamp": 1710992264190,
5979 # "data": {
5980 # "orderId": 1770656007907930112,
5981 # "positionId": "1751667128353910784",
5982 # "symbol": "LTC-USDT",
5983 # "side": "Ask",
5984 # "type": "MARKET",
5985 # "positionSide": "Long",
5986 # "origQty": "0.2"
5987 # }
5988 # }
5989 #
5990 else:
5991 request['symbol'] = market['id']
5992 if market['inverse']:
5993 response = await self.cswapV1PrivatePostTradeCloseAllPositions(self.extend(request, params))
5994 #
5995 # {
5996 # "code": 0,
5997 # "msg": "",
5998 # "timestamp": 1720771601428,
5999 # "data": {
6000 # "success": ["1811673520637231104"],
6001 # "failed": null
6002 # }
6003 # }
6004 #
6005 else:
6006 response = await self.swapV2PrivatePostTradeCloseAllPositions(self.extend(request, params))
6007 #
6008 # {
6009 # "code": 0,
6010 # "msg": "",

Callers

nothing calls this directly

Calls 9

parse_orderMethod · 0.95
safe_stringMethod · 0.80
safe_dictMethod · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected