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

Method create_contract_order

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

Source from the content-addressed store, hash-verified

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

Callers 1

create_orderMethod · 0.95

Tested by

no test coverage detected