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

Method create_order_request

python/ccxt/gate.py:4271–4484  ·  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

4269 return self.parse_orders(response)
4270
4271 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4272 market = self.market(symbol)
4273 contract = market['contract']
4274 trigger = self.safe_value(params, 'trigger')
4275 triggerPrice = self.safe_value_2(params, 'triggerPrice', 'stopPrice')
4276 stopLossPrice = self.safe_value(params, 'stopLossPrice', triggerPrice)
4277 takeProfitPrice = self.safe_value(params, 'takeProfitPrice')
4278 isStopLossOrder = stopLossPrice is not None
4279 isTakeProfitOrder = takeProfitPrice is not None
4280 isTpsl = isStopLossOrder or isTakeProfitOrder
4281 if isStopLossOrder and isTakeProfitOrder:
4282 raise ExchangeError(self.id + ' createOrder() stopLossPrice and takeProfitPrice cannot both be defined')
4283 reduceOnly = self.safe_value(params, 'reduceOnly')
4284 exchangeSpecificTimeInForce = self.safe_string_lower_n(params, ['timeInForce', 'tif', 'time_in_force'])
4285 postOnly = None
4286 postOnly, params = self.handle_post_only(type == 'market', exchangeSpecificTimeInForce == 'poc', params)
4287 timeInForce = self.handle_time_in_force(params)
4288 if postOnly:
4289 timeInForce = 'poc'
4290 # we only omit the unified params here
4291 # self is because the other params will get extended into the request
4292 clientOrderId = self.safe_string_2(params, 'text', 'clientOrderId')
4293 params = self.omit(params, ['stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'reduceOnly', 'timeInForce', 'postOnly', 'clientOrderId'])
4294 isLimitOrder = (type == 'limit')
4295 isMarketOrder = (type == 'market')
4296 if isLimitOrder and price is None:
4297 raise ArgumentsRequired(self.id + ' createOrder() requires a price argument for ' + type + ' orders')
4298 if isMarketOrder:
4299 if (timeInForce == 'poc') or (timeInForce == 'gtc'):
4300 raise ExchangeError(self.id + ' createOrder() timeInForce for market order can only be "FOK" or "IOC"')
4301 else:
4302 if timeInForce is None:
4303 defaultTif = self.safe_string(self.options, 'defaultTimeInForce', 'IOC')
4304 exchangeSpecificTif = self.safe_string(self.options['timeInForce'], defaultTif, 'ioc')
4305 timeInForce = exchangeSpecificTif
4306 if contract:
4307 price = 0
4308 if contract:
4309 isClose = self.safe_value(params, 'close')
4310 if isClose:
4311 amount = 0
4312 else:
4313 amountToPrecision = self.amount_to_precision(symbol, amount)
4314 signedAmount = Precise.string_neg(amountToPrecision) if (side == 'sell') else amountToPrecision
4315 amount = int(signedAmount)
4316 request = None
4317 nonTriggerOrder = not isTpsl and (trigger is None)
4318 if nonTriggerOrder:
4319 if contract:
4320 # contract order
4321 request = {
4322 'contract': market['id'], # filled in prepareRequest above
4323 'size': amount, # int64, positive = bid, negative = ask
4324 # 'iceberg': 0, # int64, display size for iceberg order, 0 for non-iceberg, note that you will have to pay the taker fee for the hidden size
4325 # 'close': False, # True to close the position, with size set to 0
4326 # 'reduce_only': False, # St to be reduce-only order
4327 # 'tif': 'gtc', # gtc, ioc, poc PendingOrCancelled == postOnly order
4328 # 'text': clientOrderId, # 't-abcdef1234567890',

Callers 2

create_orderMethod · 0.95
create_orders_requestMethod · 0.95

Calls 15

get_margin_modeMethod · 0.95
ExchangeErrorClass · 0.90
ArgumentsRequiredClass · 0.90
InvalidOrderClass · 0.90
BadRequestClass · 0.90
NotSupportedClass · 0.90
safe_valueMethod · 0.80
safe_value_2Method · 0.80
safe_string_lower_nMethod · 0.80
handle_post_onlyMethod · 0.80
handle_time_in_forceMethod · 0.80
safe_string_2Method · 0.80

Tested by

no test coverage detected