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