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

Method create_contract_order

python/ccxt/async_support/xt.py:2438–2502  ·  view source on GitHub ↗
(self, symbol: str, type, side, amount, price=None, params={})

Source from the content-addressed store, hash-verified

2436 return self.parse_order(order, market)
2437
2438 async def create_contract_order(self, symbol: str, type, side, amount, price=None, params={}):
2439 await self.load_markets()
2440 market = self.market(symbol)
2441 request = {
2442 'symbol': market['id'],
2443 'origQty': self.amount_to_precision(symbol, amount),
2444 }
2445 timeInForce = self.safe_string_upper(params, 'timeInForce')
2446 if timeInForce is not None:
2447 request['timeInForce'] = timeInForce
2448 reduceOnly = self.safe_value(params, 'reduceOnly', False)
2449 if side == 'buy':
2450 requestType = 'SHORT' if (reduceOnly) else 'LONG'
2451 request['positionSide'] = requestType
2452 else:
2453 requestType = 'LONG' if (reduceOnly) else 'SHORT'
2454 request['positionSide'] = requestType
2455 response = None
2456 triggerPrice = self.safe_number_2(params, 'triggerPrice', 'stopPrice')
2457 stopLoss = self.safe_number_2(params, 'stopLoss', 'triggerStopPrice')
2458 takeProfit = self.safe_number_2(params, 'takeProfit', 'triggerProfitPrice')
2459 isTrigger = (triggerPrice is not None)
2460 isStopLoss = (stopLoss is not None)
2461 isTakeProfit = (takeProfit is not None)
2462 if price is not None:
2463 if not (isStopLoss) and not (isTakeProfit):
2464 request['price'] = self.price_to_precision(symbol, price)
2465 if isTrigger:
2466 request['timeInForce'] = self.safe_string_upper(params, 'timeInForce', 'GTC')
2467 request['triggerPriceType'] = self.safe_string(params, 'triggerPriceType', 'LATEST_PRICE')
2468 request['orderSide'] = side.upper()
2469 request['stopPrice'] = self.price_to_precision(symbol, triggerPrice)
2470 entrustType = 'STOP_MARKET' if (type == 'market') else 'STOP'
2471 request['entrustType'] = entrustType
2472 params = self.omit(params, 'triggerPrice')
2473 if market['linear']:
2474 response = await self.privateLinearPostFutureTradeV1EntrustCreatePlan(self.extend(request, params))
2475 elif market['inverse']:
2476 response = await self.privateInversePostFutureTradeV1EntrustCreatePlan(self.extend(request, params))
2477 elif isStopLoss or isTakeProfit:
2478 if isStopLoss:
2479 request['triggerStopPrice'] = self.price_to_precision(symbol, stopLoss)
2480 else:
2481 request['triggerProfitPrice'] = self.price_to_precision(symbol, takeProfit)
2482 params = self.omit(params, ['stopLoss', 'takeProfit'])
2483 if market['linear']:
2484 response = await self.privateLinearPostFutureTradeV1EntrustCreateProfit(self.extend(request, params))
2485 elif market['inverse']:
2486 response = await self.privateInversePostFutureTradeV1EntrustCreateProfit(self.extend(request, params))
2487 else:
2488 request['orderSide'] = side.upper()
2489 request['orderType'] = type.upper()
2490 if market['linear']:
2491 response = await self.privateLinearPostFutureTradeV1OrderCreate(self.extend(request, params))
2492 elif market['inverse']:
2493 response = await self.privateInversePostFutureTradeV1OrderCreate(self.extend(request, params))
2494 #
2495 # {

Callers 1

create_orderMethod · 0.95

Tested by

no test coverage detected