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

Method create_twap_order

python/ccxt/hyperliquid.py:1965–2035  ·  view source on GitHub ↗

create a trade order that is executed TWAP order over a specified duration. :param str symbol: unified symbol of the market to create an order in :param str side: 'buy' or 'sell' :param float amount: how much of currency you want to trade in units of base currency

(self, symbol: str, side: OrderSide, amount: float, duration: float, params={})

Source from the content-addressed store, hash-verified

1963 return orders[0]
1964
1965 def create_twap_order(self, symbol: str, side: OrderSide, amount: float, duration: float, params={}) -> Order:
1966 """
1967 create a trade order that is executed TWAP order over a specified duration.
1968 :param str symbol: unified symbol of the market to create an order in
1969 :param str side: 'buy' or 'sell'
1970 :param float amount: how much of currency you want to trade in units of base currency
1971 :param int duration: the duration of the TWAP order in milliseconds
1972 :param dict [params]: extra parameters specific to the exchange API endpoint
1973 :param bool [params.randomize]: whether to randomize the time intervals of the TWAP order slices(default is False, meaning equal intervals)
1974 :param bool [params.reduceOnly]: True or False whether the order is reduce-only
1975 :param int [params.expiresAfter]: time in ms after which the twap order expires
1976 :param str [params.vaultAddress]: the vault address for order
1977 :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
1978 """
1979 self.load_markets()
1980 self.initialize_client()
1981 market = self.market(symbol)
1982 nonce = self.milliseconds()
1983 isBuy = (side == 'BUY')
1984 vaultAddress = None
1985 randomize = self.safe_bool(params, 'randomize', False)
1986 params = self.omit(params, 'randomize')
1987 vaultAddress, params = self.handle_option_and_params(params, 'createOrder', 'vaultAddress')
1988 vaultAddress = self.format_vault_address(vaultAddress)
1989 durationMins = int(math.floor(duration / 1000 / 60)) # convert from ms to minutes
1990 orderObj = {
1991 'a': self.parse_to_int(market['baseId']),
1992 'b': isBuy,
1993 's': self.amount_to_precision(symbol, amount),
1994 'r': self.safe_bool(params, 'reduceOnly', False),
1995 'm': durationMins,
1996 't': randomize,
1997 }
1998 orderAction = {
1999 'type': 'twapOrder',
2000 'twap': orderObj,
2001 }
2002 signature = self.sign_l1_action(orderAction, nonce, vaultAddress)
2003 request = {
2004 'action': orderAction,
2005 'nonce': nonce,
2006 'signature': signature,
2007 # 'vaultAddress': vaultAddress,
2008 }
2009 if vaultAddress is not None:
2010 params = self.omit(params, 'vaultAddress')
2011 request['vaultAddress'] = vaultAddress
2012 expiresAfter = self.safe_integer(params, 'expiresAfter')
2013 if expiresAfter is not None:
2014 request['expiresAfter'] = expiresAfter
2015 params = self.omit(params, 'expiresAfter')
2016 response = self.privatePostExchange(request)
2017 # {
2018 # "status":"ok",
2019 # "response":{
2020 # "type":"twapOrder",
2021 # "data":{
2022 # "status": {

Callers

nothing calls this directly

Calls 15

initialize_clientMethod · 0.95
marketMethod · 0.95
format_vault_addressMethod · 0.95
amount_to_precisionMethod · 0.95
sign_l1_actionMethod · 0.95
parse_orderMethod · 0.95
safe_boolMethod · 0.80
parse_to_intMethod · 0.80
safe_integerMethod · 0.80
safe_dictMethod · 0.80
safe_stringMethod · 0.80

Tested by

no test coverage detected