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

Method create_order_request

python/ccxt/hyperliquid.py:2080–2138  ·  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

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

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