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