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

Method create_order_request

python/ccxt/async_support/bingx.py:2910–3096  ·  view source on GitHub ↗

@ignore helper function to build 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 currency

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

Source from the content-addressed store, hash-verified

2908 return await self.create_order(symbol, 'market', 'sell', cost, None, params)
2909
2910 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
2911 """
2912 @ignore
2913 helper function to build request
2914 :param str symbol: unified symbol of the market to create an order in
2915 :param str type: 'market' or 'limit'
2916 :param str side: 'buy' or 'sell'
2917 :param float amount: how much you want to trade in units of the base currency
2918 :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
2919 :param dict [params]: extra parameters specific to the exchange API endpoint
2920 :returns dict: request to be sent to the exchange
2921 """
2922 market = self.market(symbol)
2923 postOnly = None
2924 marketType = None
2925 marketType, params = self.handle_market_type_and_params('createOrder', market, params)
2926 type = type.upper()
2927 request = {
2928 'symbol': market['id'],
2929 'type': type,
2930 'side': side.upper(),
2931 }
2932 isMarketOrder = type == 'MARKET'
2933 isSpot = marketType == 'spot'
2934 isTwapOrder = type == 'TWAP'
2935 if isTwapOrder and isSpot:
2936 raise BadSymbol(self.id + ' createOrder() twap order supports swap contracts only')
2937 stopLossPrice = self.safe_string(params, 'stopLossPrice')
2938 takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
2939 triggerPrice = self.safe_string_2(params, 'stopPrice', 'triggerPrice')
2940 isTriggerOrder = triggerPrice is not None
2941 isStopLossPriceOrder = stopLossPrice is not None
2942 isTakeProfitPriceOrder = takeProfitPrice is not None
2943 exchangeClientOrderId = 'newClientOrderId' if isSpot else 'clientOrderID'
2944 clientOrderId = self.safe_string_2(params, exchangeClientOrderId, 'clientOrderId')
2945 if clientOrderId is not None:
2946 request[exchangeClientOrderId] = clientOrderId
2947 timeInForce = self.safe_string_upper(params, 'timeInForce')
2948 postOnly, params = self.handle_post_only(isMarketOrder, timeInForce == 'PostOnly', params)
2949 if postOnly or (timeInForce == 'PostOnly'):
2950 request['timeInForce'] = 'PostOnly'
2951 elif timeInForce == 'IOC':
2952 request['timeInForce'] = 'IOC'
2953 elif timeInForce == 'GTC':
2954 request['timeInForce'] = 'GTC'
2955 if isSpot:
2956 cost = self.safe_string_2(params, 'cost', 'quoteOrderQty')
2957 params = self.omit(params, 'cost')
2958 if cost is not None:
2959 request['quoteOrderQty'] = self.parse_to_numeric(self.cost_to_precision(symbol, cost))
2960 else:
2961 if isMarketOrder and (price is not None):
2962 # keep the legacy behavior, to avoid breaking the old spot-market-buying code
2963 calculatedCost = Precise.string_mul(self.number_to_string(amount), self.number_to_string(price))
2964 request['quoteOrderQty'] = self.parse_to_numeric(calculatedCost)
2965 else:
2966 request['quantity'] = self.parse_to_numeric(self.amount_to_precision(symbol, amount))
2967 if not isMarketOrder:

Callers 3

create_orderMethod · 0.95
create_ordersMethod · 0.95
edit_orderMethod · 0.95

Calls 15

BadSymbolClass · 0.90
ArgumentsRequiredClass · 0.90
safe_stringMethod · 0.80
safe_string_2Method · 0.80
safe_string_upperMethod · 0.80
handle_post_onlyMethod · 0.80
parse_to_numericMethod · 0.80
string_mulMethod · 0.80
safe_valueMethod · 0.80
safe_boolMethod · 0.80
string_divMethod · 0.80
marketMethod · 0.45

Tested by

no test coverage detected