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

Method close_position

python/ccxt/bingx.py:5952–6019  ·  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

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