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

Method close_position

python/ccxt/async_support/bitget.py:9871–9938  ·  view source on GitHub ↗

closes an open position for a market https://www.bitget.com/api-doc/contract/trade/Flash-Close-Position https://www.bitget.com/api-doc/uta/trade/Close-All-Positions :param str symbol: unified CCXT market symbol :param str [side]: one-way mode: 'buy' or 'sel

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

Source from the content-addressed store, hash-verified

9869 }
9870
9871 async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
9872 """
9873 closes an open position for a market
9874
9875 https://www.bitget.com/api-doc/contract/trade/Flash-Close-Position
9876 https://www.bitget.com/api-doc/uta/trade/Close-All-Positions
9877
9878 :param str symbol: unified CCXT market symbol
9879 :param str [side]: one-way mode: 'buy' or 'sell', hedge-mode: 'long' or 'short'
9880 :param dict [params]: extra parameters specific to the exchange API endpoint
9881 :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
9882 :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
9883 """
9884 await self.load_markets()
9885 market = self.market(symbol)
9886 request = {
9887 'symbol': market['id'],
9888 }
9889 productType = None
9890 uta = None
9891 response = None
9892 productType, params = self.handle_product_type_and_params(market, params)
9893 uta, params = self.handle_option_and_params(params, 'closePosition', 'uta', False)
9894 if uta:
9895 if side is not None:
9896 request['posSide'] = side
9897 request['category'] = productType
9898 response = await self.privateUtaPostV3TradeClosePositions(self.extend(request, params))
9899 #
9900 # {
9901 # "code": "00000",
9902 # "msg": "success",
9903 # "requestTime": 1751020218384,
9904 # "data": {
9905 # "list": [
9906 # {
9907 # "orderId": "1322440134099320832",
9908 # "clientOid": "1322440134099320833"
9909 # }
9910 # ]
9911 # }
9912 # }
9913 #
9914 else:
9915 if side is not None:
9916 request['holdSide'] = side
9917 request['productType'] = productType
9918 response = await self.privateMixPostV2MixOrderClosePositions(self.extend(request, params))
9919 #
9920 # {
9921 # "code": "00000",
9922 # "msg": "success",
9923 # "requestTime": 1702975017017,
9924 # "data": {
9925 # "successList": [
9926 # {
9927 # "orderId": "1120923953904893955",
9928 # "clientOid": "1120923953904893956"

Callers

nothing calls this directly

Calls 10

parse_orderMethod · 0.95
safe_valueMethod · 0.80
safe_list_2Method · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected