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={})
| 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": { |
nothing calls this directly
no test coverage detected