def create_order(self, symbol, type, side, amount, price=None, params={}):
    self.load_markets()
    market = self.market(symbol)
    request = {'instrument_id': market['id']}
    clientOrderId = self.safe_string_2(params, 'client_oid', 'clientOrderId')
    if (clientOrderId is not None):
        request['client_oid'] = clientOrderId
        params = self.omit(params, ['client_oid', 'clientOrderId'])
    method = None
    if (market['futures'] or market['swap']):
        size = (self.number_to_string(amount) if market['futures'] else self.amount_to_precision(symbol, amount))
        request = self.extend(request, {'type': type, 'size': size})
        orderType = self.safe_string(params, 'order_type')
        isMarketOrder = ((type == 'market') or (orderType == '4'))
        if isMarketOrder:
            request['order_type'] = '4'
        else:
            request['price'] = self.price_to_precision(symbol, price)
        if market['futures']:
            request['leverage'] = '10'
        method = (market['type'] + 'PostOrder')
    else:
        marginTrading = self.safe_string(params, 'margin_trading', '1')
        request = self.extend(request, {'side': side, 'type': type, 'margin_trading': marginTrading})
        if (type == 'limit'):
            request['price'] = self.price_to_precision(symbol, price)
            request['size'] = self.amount_to_precision(symbol, amount)
        elif (type == 'market'):
            if (side == 'buy'):
                notional = self.safe_float(params, 'notional')
                createMarketBuyOrderRequiresPrice = self.safe_value(self.options, 'createMarketBuyOrderRequiresPrice', True)
                if createMarketBuyOrderRequiresPrice:
                    if (price is not None):
                        if (notional is None):
                            notional = (amount * price)
                    elif (notional is None):
                        raise InvalidOrder((self.id + " createOrder() requires the price argument with market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = False and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter(the exchange-specific behaviour)"))
                else:
                    notional = (amount if (notional is None) else notional)
                precision = market['precision']['price']
                request['notional'] = self.decimal_to_precision(notional, TRUNCATE, precision, self.precisionMode)
            else:
                request['size'] = self.amount_to_precision(symbol, amount)
        method = ('marginPostOrders' if (marginTrading == '2') else 'spotPostOrders')
    response = getattr(self, method)(self.extend(request, params))
    order = self.parse_order(response, market)
    return self.extend(order, {'type': type, 'side': side})
def create_order(self, symbol, type, side, amount, price=None, params={}):
    self.load_markets()
    market = self.market(symbol)
    request = {'instrument_id': market['id']}
    clientOrderId = self.safe_string_2(params, 'client_oid', 'clientOrderId')
    if (clientOrderId is not None):
        request['client_oid'] = clientOrderId
        params = self.omit(params, ['client_oid', 'clientOrderId'])
    method = None
    if (market['futures'] or market['swap']):
        size = (self.number_to_string(amount) if market['futures'] else self.amount_to_precision(symbol, amount))
        request = self.extend(request, {'type': type, 'size': size})
        orderType = self.safe_string(params, 'order_type')
        isMarketOrder = ((type == 'market') or (orderType == '4'))
        if isMarketOrder:
            request['order_type'] = '4'
        else:
            request['price'] = self.price_to_precision(symbol, price)
        if market['futures']:
            request['leverage'] = '10'
        method = (market['type'] + 'PostOrder')
    else:
        marginTrading = self.safe_string(params, 'margin_trading', '1')
        request = self.extend(request, {'side': side, 'type': type, 'margin_trading': marginTrading})
        if (type == 'limit'):
            request['price'] = self.price_to_precision(symbol, price)
            request['size'] = self.amount_to_precision(symbol, amount)
        elif (type == 'market'):
            if (side == 'buy'):
                notional = self.safe_float(params, 'notional')
                createMarketBuyOrderRequiresPrice = self.safe_value(self.options, 'createMarketBuyOrderRequiresPrice', True)
                if createMarketBuyOrderRequiresPrice:
                    if (price is not None):
                        if (notional is None):
                            notional = (amount * price)
                    elif (notional is None):
                        raise InvalidOrder((self.id + " createOrder() requires the price argument with market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = False and supply the total cost value in the 'amount' argument or in the 'notional' extra parameter(the exchange-specific behaviour)"))
                else:
                    notional = (amount if (notional is None) else notional)
                precision = market['precision']['price']
                request['notional'] = self.decimal_to_precision(notional, TRUNCATE, precision, self.precisionMode)
            else:
                request['size'] = self.amount_to_precision(symbol, amount)
        method = ('marginPostOrders' if (marginTrading == '2') else 'spotPostOrders')
    response = getattr(self, method)(self.extend(request, params))
    order = self.parse_order(response, market)
    return self.extend(order, {'type': type, 'side': side})