closes open positions for a contract market https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1958953a715 # USDT-M https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-lightning-close-order # Coin-M swap https://huobiapi.github.i
(self, symbol: str, side: OrderSide = None, params={})
| 9133 | }) |
| 9134 | |
| 9135 | async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order: |
| 9136 | """ |
| 9137 | closes open positions for a contract market |
| 9138 | |
| 9139 | https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1958953a715 # USDT-M |
| 9140 | https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-lightning-close-order # Coin-M swap |
| 9141 | https://huobiapi.github.io/docs/dm/v1/en/#place-flash-close-order # Coin-M futures |
| 9142 | |
| 9143 | :param str symbol: unified CCXT market symbol |
| 9144 | :param str side: 'buy' or 'sell', the side of the closing order, opposite side side |
| 9145 | :param dict [params]: extra parameters specific to the okx api endpoint |
| 9146 | :param str [params.clientOrderId]: client needs to provide unique API and have to maintain the API themselves afterwards. [1, 9223372036854775807] |
| 9147 | :param dict [params.marginMode]: 'cross' or 'isolated', required for linear markets |
| 9148 | |
| 9149 | EXCHANGE SPECIFIC PARAMETERS |
| 9150 | :param number [params.amount]: order quantity |
| 9151 | :param str [params.order_price_type]: 'lightning' by default, 'lightning_fok': lightning fok type, 'lightning_ioc': lightning ioc type 'market' by default, 'market': market order type, 'lightning_fok': lightning |
| 9152 | :param str [params.position_side]: linear swap supports 'long', 'short' and 'both', 'both' is the default |
| 9153 | :returns dict: `an order structure <https://docs.ccxt.com/?id=position-structure>` |
| 9154 | """ |
| 9155 | await self.load_markets() |
| 9156 | market = self.market(symbol) |
| 9157 | clientOrderId = self.safe_string(params, 'clientOrderId') |
| 9158 | if not market['contract']: |
| 9159 | raise BadRequest(self.id + ' closePosition() symbol supports contract markets only') |
| 9160 | request = { |
| 9161 | 'contract_code': market['id'], |
| 9162 | } |
| 9163 | if clientOrderId is not None: |
| 9164 | request['client_order_id'] = clientOrderId |
| 9165 | params = self.omit(params, 'clientOrderId') |
| 9166 | response = None |
| 9167 | if market['linear']: |
| 9168 | marginMode = None |
| 9169 | marginMode, params = self.handle_margin_mode_and_params('closePosition', params, 'cross') |
| 9170 | request['margin_mode'] = marginMode |
| 9171 | response = await self.contractPrivatePostV5TradePosition(self.extend(request, params)) |
| 9172 | # |
| 9173 | # { |
| 9174 | # "code": 200, |
| 9175 | # "message": "Success", |
| 9176 | # "data": { |
| 9177 | # "order_id": 1513557136321597440, |
| 9178 | # "client_order_id": "1513557136321597440" |
| 9179 | # }, |
| 9180 | # "ts": 1780901741840 |
| 9181 | # } |
| 9182 | # |
| 9183 | else: |
| 9184 | self.check_required_argument('closePosition', side, 'side') |
| 9185 | amount = self.safe_string_2(params, 'volume', 'amount') |
| 9186 | if amount is None: |
| 9187 | raise ArgumentsRequired(self.id + ' closePosition() requires an extra argument params["amount"] for inverse markets') |
| 9188 | request['volume'] = self.amount_to_precision(symbol, amount) |
| 9189 | request['direction'] = side |
| 9190 | params = self.omit(params, ['volume', 'amount']) |
| 9191 | if market['swap']: |
| 9192 | response = await self.contractPrivatePostSwapApiV1SwapLightningClosePosition(self.extend(request, params)) |
nothing calls this directly
no test coverage detected