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

Method create_order_request

python/ccxt/binance.py:6362–6630  ·  view source on GitHub ↗

@ignore helper function to build the request :param str symbol: unified symbol of the market to create an order in :param str type: 'market' or 'limit' :param str side: 'buy' or 'sell' :param float amount: how much you want to trade in units of the base curr

(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})

Source from the content-addressed store, hash-verified

6360 return self.parse_order(response, market)
6361
6362 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
6363 """
6364 @ignore
6365 helper function to build the request
6366 :param str symbol: unified symbol of the market to create an order in
6367 :param str type: 'market' or 'limit'
6368 :param str side: 'buy' or 'sell'
6369 :param float amount: how much you want to trade in units of the base currency
6370 :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
6371 :param dict [params]: extra parameters specific to the exchange API endpoint
6372 :returns dict: request to be sent to the exchange
6373 """
6374 market = self.market(symbol)
6375 marketType = self.safe_string(params, 'type', market['type'])
6376 clientOrderId = self.safe_string_n(params, ['clientAlgoId', 'newClientOrderId', 'clientOrderId'])
6377 initialUppercaseType = type.upper()
6378 isMarketOrder = initialUppercaseType == 'MARKET'
6379 isLimitOrder = initialUppercaseType == 'LIMIT'
6380 upperCaseSide = side.upper()
6381 request = {
6382 'symbol': market['id'],
6383 'side': upperCaseSide,
6384 }
6385 isPortfolioMargin = None
6386 isPortfolioMargin, params = self.handle_option_and_params_2(params, 'createOrder', 'papi', 'portfolioMargin', False)
6387 marginMode = None
6388 marginMode, params = self.handle_margin_mode_and_params('createOrder', params)
6389 reduceOnly = self.safe_bool(params, 'reduceOnly', False)
6390 if reduceOnly:
6391 if marketType == 'margin' or (not market['contract'] and (marginMode is not None)):
6392 params = self.omit(params, 'reduceOnly')
6393 request['sideEffectType'] = 'AUTO_REPAY'
6394 triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
6395 stopLossPrice = self.safe_string(params, 'stopLossPrice', triggerPrice) # fallback to stopLoss
6396 takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
6397 trailingDelta = self.safe_string(params, 'trailingDelta')
6398 trailingTriggerPrice = self.safe_string_2(params, 'trailingTriggerPrice', 'activationPrice')
6399 trailingPercent = self.safe_string_n(params, ['trailingPercent', 'callbackRate', 'trailingDelta'])
6400 priceMatch = self.safe_string(params, 'priceMatch')
6401 isTrailingPercentOrder = trailingPercent is not None
6402 isStopLoss = stopLossPrice is not None or trailingDelta is not None
6403 isTakeProfit = takeProfitPrice is not None
6404 isTriggerOrder = triggerPrice is not None
6405 isConditional = isTriggerOrder or isTrailingPercentOrder or isStopLoss or isTakeProfit
6406 isPortfolioMarginConditional = (isPortfolioMargin and isConditional)
6407 isPriceMatch = priceMatch is not None
6408 priceRequiredForTrailing = True
6409 uppercaseType = type.upper()
6410 stopPrice = None
6411 if isTrailingPercentOrder:
6412 if market['swap']:
6413 uppercaseType = 'TRAILING_STOP_MARKET'
6414 request['callbackRate'] = trailingPercent
6415 if trailingTriggerPrice is not None:
6416 request['activationPrice'] = self.price_to_precision(symbol, trailingTriggerPrice)
6417 else:
6418 if (uppercaseType != 'STOP_LOSS') and (uppercaseType != 'TAKE_PROFIT') and (uppercaseType != 'STOP_LOSS_LIMIT') and (uppercaseType != 'TAKE_PROFIT_LIMIT'):
6419 stopLossOrTakeProfit = self.safe_string(params, 'stopLossOrTakeProfit')

Callers 2

create_ordersMethod · 0.95
create_orderMethod · 0.95

Calls 15

marketMethod · 0.95
InvalidOrderClass · 0.90
NotSupportedClass · 0.90
safe_stringMethod · 0.80
safe_string_nMethod · 0.80
safe_boolMethod · 0.80
safe_string_2Method · 0.80
string_mulMethod · 0.80
safe_listMethod · 0.80
in_arrayMethod · 0.80
safe_dictMethod · 0.80

Tested by

no test coverage detected