(self, symbol: str, type: OrderType, side: OrderSide, amount: str, price: Str = None, params={})
| 2078 | return self.parse_orders(ordersToBeParsed) |
| 2079 | |
| 2080 | def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: str, price: Str = None, params={}): |
| 2081 | market = self.market(symbol) |
| 2082 | type = type.upper() |
| 2083 | side = side.upper() |
| 2084 | isMarket = (type == 'MARKET') |
| 2085 | isBuy = (side == 'BUY') |
| 2086 | clientOrderId = self.safe_string_2(params, 'clientOrderId', 'client_id') |
| 2087 | slippage = self.safe_string(params, 'slippage') |
| 2088 | defaultTimeInForce = 'ioc' if (isMarket) else 'gtc' |
| 2089 | postOnly = self.safe_bool(params, 'postOnly', False) |
| 2090 | if postOnly: |
| 2091 | defaultTimeInForce = 'alo' |
| 2092 | timeInForce = self.safe_string_lower(params, 'timeInForce', defaultTimeInForce) |
| 2093 | timeInForce = self.capitalize(timeInForce) |
| 2094 | triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice') |
| 2095 | stopLossPrice = self.safe_string(params, 'stopLossPrice', triggerPrice) |
| 2096 | takeProfitPrice = self.safe_string(params, 'takeProfitPrice') |
| 2097 | isTrigger = (stopLossPrice or takeProfitPrice) |
| 2098 | px = None |
| 2099 | if isMarket: |
| 2100 | if price is None: |
| 2101 | raise ArgumentsRequired(self.id + ' market orders require price to calculate the max slippage price. Default slippage can be set in options(default is 5%).') |
| 2102 | px = Precise.string_mul(price, Precise.string_add('1', slippage)) if (isBuy) else Precise.string_mul(price, Precise.string_sub('1', slippage)) |
| 2103 | px = self.price_to_precision(symbol, px) # round after adding slippage |
| 2104 | else: |
| 2105 | px = self.price_to_precision(symbol, price) |
| 2106 | sz = self.amount_to_precision(symbol, amount) |
| 2107 | reduceOnly = self.safe_bool(params, 'reduceOnly', False) |
| 2108 | orderType = {} |
| 2109 | if isTrigger: |
| 2110 | isTp = False |
| 2111 | if takeProfitPrice is not None: |
| 2112 | triggerPrice = self.price_to_precision(symbol, takeProfitPrice) |
| 2113 | isTp = True |
| 2114 | else: |
| 2115 | triggerPrice = self.price_to_precision(symbol, stopLossPrice) |
| 2116 | tpSlType = 'tp' if (isTp) else 'sl' |
| 2117 | orderType['trigger'] = { |
| 2118 | 'isMarket': isMarket, |
| 2119 | 'triggerPx': triggerPrice, |
| 2120 | 'tpsl': tpSlType, |
| 2121 | } |
| 2122 | else: |
| 2123 | orderType['limit'] = { |
| 2124 | 'tif': timeInForce, |
| 2125 | } |
| 2126 | params = self.omit(params, ['clientOrderId', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce', 'client_id', 'reduceOnly', 'postOnly']) |
| 2127 | orderObj = { |
| 2128 | 'a': self.parse_to_int(market['baseId']), |
| 2129 | 'b': isBuy, |
| 2130 | 'p': px, |
| 2131 | 's': sz, |
| 2132 | 'r': reduceOnly, |
| 2133 | 't': orderType, |
| 2134 | # 'c': clientOrderId, |
| 2135 | } |
| 2136 | if clientOrderId is not None: |
| 2137 | orderObj['c'] = clientOrderId |
no test coverage detected