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

Method create_order_request

python/ccxt/async_support/hyperliquid.py:2081–2139  ·  view source on GitHub ↗
(self, symbol: str, type: OrderType, side: OrderSide, amount: str, price: Str = None, params={})

Source from the content-addressed store, hash-verified

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

Callers 1

create_orders_requestMethod · 0.95

Calls 14

marketMethod · 0.95
price_to_precisionMethod · 0.95
amount_to_precisionMethod · 0.95
ArgumentsRequiredClass · 0.90
safe_string_2Method · 0.80
safe_stringMethod · 0.80
safe_boolMethod · 0.80
safe_string_lowerMethod · 0.80
string_mulMethod · 0.80
string_addMethod · 0.80
string_subMethod · 0.80
parse_to_intMethod · 0.80

Tested by

no test coverage detected