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

Method close_position

python/ccxt/cryptocom.py:3192–3232  ·  view source on GitHub ↗

closes open positions for a market https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position :param str symbol: Unified CCXT market symbol :param str [side]: not used by cryptocom.closePositions :param dict [params]: extra param

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

Source from the content-addressed store, hash-verified

3190 return returnString
3191
3192 def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
3193 """
3194 closes open positions for a market
3195
3196 https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
3197
3198 :param str symbol: Unified CCXT market symbol
3199 :param str [side]: not used by cryptocom.closePositions
3200 :param dict [params]: extra parameters specific to the okx api endpoint
3201
3202 EXCHANGE SPECIFIC PARAMETERS
3203 :param str [params.type]: LIMIT or MARKET
3204 :param number [params.price]: for limit orders only
3205 :returns dict[]: `A list of position structures <https://docs.ccxt.com/?id=position-structure>`
3206 """
3207 self.load_markets()
3208 market = self.market(symbol)
3209 request = {
3210 'instrument_name': market['id'],
3211 'type': 'MARKET',
3212 }
3213 type = self.safe_string_upper(params, 'type')
3214 price = self.safe_string(params, 'price')
3215 if type is not None:
3216 request['type'] = type
3217 if price is not None:
3218 request['price'] = self.price_to_precision(market['symbol'], price)
3219 response = self.v1PrivatePostPrivateClosePosition(self.extend(request, params))
3220 #
3221 # {
3222 # "id" : 1700830813298,
3223 # "method" : "private/close-position",
3224 # "code" : 0,
3225 # "result" : {
3226 # "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
3227 # "order_id" : "6142909897021751347"
3228 # }
3229 # }
3230 #
3231 result = self.safe_dict(response, 'result')
3232 return self.parse_order(result, market)
3233
3234 def fetch_trading_fee(self, symbol: str, params={}) -> TradingFeeInterface:
3235 """

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected