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

Method create_contract_order_request

python/ccxt/kucoin.py:3998–4096  ·  view source on GitHub ↗
(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})

Source from the content-addressed store, hash-verified

3996 return self.parse_order(data, market)
3997
3998 def create_contract_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
3999 market = self.market(symbol)
4000 # required param, cannot be used twice
4001 clientOrderId = self.safe_string_2(params, 'clientOid', 'clientOrderId', self.uuid())
4002 params = self.omit(params, ['clientOid', 'clientOrderId'])
4003 request = {
4004 'clientOid': clientOrderId,
4005 'side': side,
4006 'symbol': market['id'],
4007 'type': type, # limit or market
4008 'leverage': 1,
4009 }
4010 marginModeUpper = self.safe_string_upper(params, 'marginMode')
4011 if marginModeUpper is not None:
4012 params = self.omit(params, 'marginMode')
4013 request['marginMode'] = marginModeUpper
4014 cost = self.safe_string(params, 'cost')
4015 params = self.omit(params, 'cost')
4016 if cost is not None:
4017 request['valueQty'] = self.cost_to_precision(symbol, cost)
4018 else:
4019 if amount < 1:
4020 raise InvalidOrder(self.id + ' createOrder() minimum contract order amount is 1')
4021 request['size'] = int(self.amount_to_precision(symbol, amount))
4022 triggerPrice, stopLossPrice, takeProfitPrice = self.handle_trigger_prices(params)
4023 stopLoss = self.safe_dict(params, 'stopLoss')
4024 takeProfit = self.safe_dict(params, 'takeProfit')
4025 hasStopLoss = stopLoss is not None
4026 hasTakeProfit = takeProfit is not None
4027 # isTpAndSl = stopLossPrice and takeProfitPrice
4028 triggerPriceTypes = {
4029 'mark': 'MP',
4030 'last': 'TP',
4031 'index': 'IP',
4032 }
4033 triggerPriceType = self.safe_string(params, 'triggerPriceType', 'mark')
4034 triggerPriceTypeValue = self.safe_string(triggerPriceTypes, triggerPriceType, triggerPriceType)
4035 params = self.omit(params, ['stopLossPrice', 'takeProfitPrice', 'triggerPrice', 'stopPrice', 'takeProfit', 'stopLoss'])
4036 if triggerPrice:
4037 request['stop'] = 'up' if (side == 'buy') else 'down'
4038 request['stopPrice'] = self.price_to_precision(symbol, triggerPrice)
4039 request['stopPriceType'] = triggerPriceTypeValue
4040 elif hasStopLoss or hasTakeProfit:
4041 priceType = triggerPriceTypeValue
4042 if hasStopLoss:
4043 slPrice = self.safe_string_2(stopLoss, 'triggerPrice', 'stopPrice')
4044 request['triggerStopDownPrice'] = self.price_to_precision(symbol, slPrice)
4045 priceType = self.safe_string(stopLoss, 'triggerPriceType', 'mark')
4046 priceType = self.safe_string(triggerPriceTypes, priceType, priceType)
4047 if hasTakeProfit:
4048 tpPrice = self.safe_string_2(takeProfit, 'triggerPrice', 'takeProfitPrice')
4049 request['triggerStopUpPrice'] = self.price_to_precision(symbol, tpPrice)
4050 priceType = self.safe_string(takeProfit, 'triggerPriceType', 'mark')
4051 priceType = self.safe_string(triggerPriceTypes, priceType, priceType)
4052 request['stopPriceType'] = priceType
4053 elif stopLossPrice or takeProfitPrice:
4054 if stopLossPrice:
4055 request['stop'] = 'up' if (side == 'buy') else 'down'

Callers 2

create_contract_orderMethod · 0.95

Calls 15

handle_trigger_pricesMethod · 0.95
InvalidOrderClass · 0.90
ArgumentsRequiredClass · 0.90
BadRequestClass · 0.90
safe_string_2Method · 0.80
safe_string_upperMethod · 0.80
safe_stringMethod · 0.80
safe_dictMethod · 0.80
handle_post_onlyMethod · 0.80
safe_valueMethod · 0.80
safe_boolMethod · 0.80
handle_param_boolMethod · 0.80

Tested by

no test coverage detected