
    ":h!                         d dl Zd dlmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ  G d dej6                  j8                        Zy)	    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyIntMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTrade)Client)List)ExchangeErrorc                       e Zd Zdef fdZi fdee   fdZdi fdede	de
d	ed
ef
dZddi fdedededed	ed
efdZdi fdededefdZi fdedefdZd Zi fdedefdZdi fdedefdZdi fdedefdZdddi fdedededee   fdZdefdZd7dedefdZ defdZ!ddi fdedededee   fdZ"i fdedefdZ#defdZ$d7d e%dedefd!Z&d"ddi fdedededee'   fd#Z(d"i fdedefd$Z)defd%Z*ded&e%fd'Z+dddi fdedededee,   fd(Z-defd)Z.defd*Z/ded+e%fd,Z0ded+e%fd-Z1ded+e%fd.Z2ded+e%fd/Z3defd0Z4defd1Z5defd2Z6defd3Z7defd4Z8d5e%de%fd6Z9 xZ:S )8hyperliquidreturnc                     | j                  t        t        |          ddddddddddddddddddiidddiidi | j                  d	d
ddi iid      S )NTF)wscreateOrderWscreateOrdersWseditOrderWswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchTradeswatchTradesForSymbolswatchPositionr   publiczwss://api.hyperliquid.xyz/wsz$wss://api.hyperliquid-testnet.xyz/ws)apitesti N  )ping	keepAliveexact)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describer,   )self	__class__s    N/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/hyperliquid.pyr6   zhyperliquid.describe   s    k4 A C!%"&# %!%""&## $#).!&$  "@  "H 		"
  G)F
 ) )	    ordersc                   K   | j                          d{    | j                  d   d   d   }| j                  ||      }| j                  |      }| j	                  |di       }| j                  |d      }| j                  ||||       d{   }| j	                  |di       }	| j	                  |	di       }
| j                  |
d	g       }| j                  |d      S 7 7 Qw)
a  
        create a list of trade orders using WebSocket post request

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr*   r   r)   request	requestIdresponsedatastatuses)	load_marketsr0   createOrdersRequestwrap_as_post_action	safe_dictsafe_stringwatch	safe_listparse_orders)r7   r;   paramsurlordersRequestwrappedr=   r>   r?   responseOjbr@   rA   s               r9   create_orders_wszhyperliquid.create_orders_ws<   s      !!!iit$X.00@**=9..)R8$$Wk:	CGYGGnnXz2>~~k626>>$
B7  400 	" Hs#   C#CA8C#C!AC#!C#Nsymboltypesideamountpricec                 .  K   | j                          d{    | j                  d||||||      \  }}| j                  |g|       d{   }	|	d   }
| j                  |
d      }| j	                  ddddd| j                  |      |dd	       |
S 7 z7 Gw)a=  
        create a trade order using WebSocket post request

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
        :param bool [params.postOnly]: True or False whether the order is post-only
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
        :param str [params.slippage]: the slippage for market order
        :param str [params.vaultAddress]: the vault address for order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   info)rB   parseCreateEditOrderArgsrO   rE   handle_errorsjson)r7   rP   rQ   rR   rS   rT   rJ   orderglobalParamsr;   parsedOrder	orderInfos               r9   create_order_wszhyperliquid.create_order_wsR   s     * !!!";;D&$PTV\^cekl|,,eWlCCQiNN;7	4tT499MyZ^`de 	"Cs"   BB4BBABBidc                   K   | j                          d{    | j                  |      }| j                  d   d   d   }	| j                  |||||||      \  }
}| j	                  |
g|      }| j                  |      }| j                  |di       }| j                  |d      }| j                  |	|||       d{   }| j                  |di       }| j                  |di       }| j                  |d	g       }| j                  |d
i       }| j                  ||      }| j                  |d      }| j                  ddddd| j                  |      |dd	       |S 7 D7 w)a	  
        edit a trade order

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: 'Gtc', 'Ioc', 'Alo'
        :param bool [params.postOnly]: True or False whether the order is post-only
        :param bool [params.reduceOnly]: True or False whether the order is reduce-only
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param str [params.clientOrderId]: client order id,(optional 128 bit hex string e.g. 0x1234567890abcdef1234567890abcdef)
        :param str [params.vaultAddress]: the vault address for order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr*   r   r)   r=   r>   r?   r@   rA   r   rV   )rB   marketr0   rW   editOrdersRequestrD   rE   rF   rG   rH   parse_orderrX   rY   )r7   r_   rP   rQ   rR   rS   rT   rJ   ra   rK   rZ   r[   postRequestrM   r=   r>   r?   responseObject
dataObjectrA   firstr\   r]   s                          r9   edit_order_wszhyperliquid.edit_order_wsp   sh    * !!!V$iit$X.";;BdTZ\acij|,,eWlC**;7..)R8$$Wk:	CGYGG*bA^^NFB?
>>*j"=xB/&&uf5NN;7	4tT499MyZ^`de% 	" Hs#   EEB$E;E<BEElimitc                 H  K   | j                          d{    | j                  |      }|d   }d|z   }| j                  d   d   d   }dd|d	   r|d
   n|d   dd}| j                  ||      }| j	                  ||||       d{   }	|	j                         S 7 7 w)aX  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        NrP   
orderbook:r*   r   r)   	subscribel2Bookswapbaser_   rQ   coinmethodsubscription)rB   ra   r0   extendrG   ri   )
r7   rP   ri   rJ   ra   messageHashrK   r=   message	orderbooks
             r9   watch_order_bookzhyperliquid.watch_order_book   s      !!!V$!"V+iit$X.! *0.vfTl
 ++gv.**S+wLL	   	" Ms"   B"BA2B"	B 
B" B"c                 f  K   | j                          d{    | j                  |      }|d   }d|z   }d|z   }| j                  d   d   d   }t        | j	                               }|dd	|d
   r|d   n|d   dd}| j                  ||      }	| j                  |||	|       d{   S 7 7 w)a  
        unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        NrP   rk   unsubscribe:r*   r   r)   unsubscriberm   rn   ro   r_   rp   )r_   rs   rt   )rB   ra   r0   strnonceru   rG   )
r7   rP   rJ   ra   subMessageHashrv   rK   r_   r=   rw   s
             r9   un_watch_order_bookzhyperliquid.un_watch_order_book   s      !!!V$!%.$~5iit$X.# *0.vfTl
 ++gv.ZZ[';GGG! 	"  Hs"   B1B-BB1(B/)B1/B1c           	      ,   | j                  |di       }| j                  |d      }| j                  |      }| j                  |      }|d   }| j	                  |dg       }| j	                  |dg       | j	                  |dg       d}	| j                  |d      }
| j                  |	||
d	d
dd      }|| j                  vr | j                  |      }|| j                  |<   | j                  |   }|j                  |       d|z   }|j                  ||       y )Nr@   rq   rP   levelsr      )bidsaskstimer   r   pxszrk   )rE   rF   coinToMarketIdra   rH   safe_integerparse_order_book
orderbooks
order_bookresetresolve)r7   clientrw   entryrq   marketIdra   rP   rawDatar@   	timestampsnapshotobrx   rv   s                  r9   handle_order_bookzhyperliquid.handle_order_book   s   4 w3v.&&t,X&!.."5NN7Ar2NN7Ar2
 %%eV4	((vy&&RVX\]$//)*B&(DOOF#OOF+	!"V+y+.r:   c                 z   K   | j                  |      }|d   }| j                  |g|       d{   }||   S 7 	w)a  

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        rP   N)ra   watch_tickers)r7   rP   rJ   ra   tickerss        r9   watch_tickerzhyperliquid.watch_ticker   sF      V$!**F8V<<v =s   -;9
;symbolsc                 T  K   | j                          d{    | j                  |dd      }d}| j                  d   d   d   }ddd	d
d}| j                  ||| j	                  ||      |       d{   }| j
                  r| j                  |d|      S | j                  S 7 7 1w)a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr   r*   r   r)   rl   webData2*0x0000000000000000000000000000000000000000rQ   userrr   rP   )rB   market_symbolsr0   rG   ru   
newUpdatesfilter_by_array_tickersr   )r7   r   rJ   rv   rK   r=   r   s          r9   r   zhyperliquid.watch_tickers  s      !!!%%gtT:iit$X.!"D
 

3T[[&5QS^__??//7KK|| 	" `s"   B(B$AB(4B&50B(&B(c                   K   | j                          d{    | j                  |dd      }d}d|z   }| j                  d   d   d   }dd	d
dd}| j                  ||| j	                  ||      |       d{   S 7 g7 w)a  
        unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str[] symbols: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr   r{   r*   r   r)   r|   r   r   r   rr   )rB   r   r0   rG   ru   )r7   r   rJ   r   rv   rK   r=   s          r9   un_watch_tickerszhyperliquid.un_watch_tickers'  s      !!!%%gtT:"$~5iit$X.#"D
 ZZ[$++gv2NP[\\\ 	" ]s"   BA>A"B9B :B Bsincec                   K   d}| j                  d|      \  }}| j                          d{    d}|| j                  |      }|d|z   z  }| j                  d   d   d   }dd	|d
d}| j	                  ||      }	| j                  |||	|       d{   }
| j                  r|
j                  ||      }| j                  |
|||d      S 7 7 9w)a  
        watches information on multiple trades made by the user

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr    myTrades:r*   r   r)   rl   	userFillsr   rr   T)	handlePublicAddressrB   rP   r0   ru   rG   r   getLimitfilter_by_symbol_since_limit)r7   rP   r   ri   rJ   userAddressrv   rK   r=   rw   tradess              r9   watch_my_tradeszhyperliquid.watch_my_trades?  s      "66OV!!! [[(F3<'Kiit$X.!##
 ++gv.zz#{G[II??OOFE2E00tTT# 	" Js"   +CCA'CC8CCr   c           	         | j                  |di       }| j                  |dg       }g }t        dt        |            D ]P  }||   }| j	                  |d      }| j                  |d d d      }	| j                  ||	      }
|j                  |
       R | j                  |di       }| j                  |dg       }| j                  |dg       }t        dt        |            D ]u  }| j                  | j                  ||i       | j                  ||i             }|d	   d
z   }| j                  |d d d      }	| j                  ||	      }
|j                  |
       w | j                  |d      }|j                  |d       y )Nr@   spotAssetCtxsr   rq   spotmetauniverse	assetCtxsnamez
/USDC:USDCrn   rP   r   )rE   rH   rangelenrF   safe_marketparse_ws_tickerappendru   index_byr   )r7   r   rw   r   
spotAssetsparsedTickersiassetObjectr   ra   tickerr   r   r   r@   r_   r   s                    r9   handle_ws_tickerszhyperliquid.handle_ws_tickersa  s   ` ..&"5^^G_bA
q#j/* 	)A$Q-K''V<H%%hdFCF))+v>F  (	) ~~gvr2>>$
B7NN7K<	q#h-( 	)A;;xB/y!R0D f,B%%b$f=F))$7F  (	) --x8w	*r:   ra   c                 &    | j                  ||      S N)parse_ticker)r7   	rawTickerra   s      r9   r   zhyperliquid.parse_ws_ticker  s      F33r:   c                 X   | j                  |di       }| j                  -| j                  | j                  dd      }t	        |      | _        | j                  }i }| j                  |dg       }t        |      }|dk(  ry t        dt        |            D ]3  }	||	   }
| j                  |
      }|d   }d||<   |j                  |       5 t        |j                               }t        dt        |            D ]  }	d||	   z   }|j                  ||        d	}|j                  ||       y )
Nr@   tradesLimit  fillsr   rP   Tz	myTrades:r   )rE   r   r   r1   r   rH   r   r   parse_ws_trader   listkeysr   )r7   r   rw   r   ri   r   r   r@   
dataLengthr   rawTradeparsedrP   r   currentMessageHashrv   s                   r9   handle_my_tradeszhyperliquid.handle_my_trades  s(   : w3== %%dllM4HE259DM~~eWb1Y
?q#d)$ 	"AAwH((2FH%F"GFOMM&!	" GLLN#q#d)$ 	7A!,tAw!6NN6#56	7 !v{+r:   c                   K   | j                          d {    | j                  |      }|d   }d|z   }| j                  d   d   d   }dd|d   r|d	   n|d
   dd}| j                  ||      }	| j	                  |||	|       d {   }
| j
                  r|
j                  ||      }| j                  |
||dd      S 7 7 9w)NrP   trade:r*   r   r)   rl   r   rn   ro   r_   rp   rr   r   TrB   ra   r0   ru   rG   r   r   filter_by_since_limit)r7   rP   r   ri   rJ   ra   rv   rK   r=   rw   r   s              r9   watch_tradeszhyperliquid.watch_trades  s      !!!V$!'iit$X.! *0.vfTl
 ++gv.zz#{G[II??OOFE2E))&%TRR! 	" Js"   CCA2C	C
8CCc                 2  K   | j                          d{    | j                  |      }|d   }d|z   }d|z   }| j                  d   d   d   }dd	|d
   r|d   n|d   dd}| j                  ||      }| j	                  ||||       d{   S 7 |7 w)a  
        unWatches information on multiple trades made in a market

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified market symbol of the market trades were made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        NrP   r   r{   r*   r   r)   r|   r   rn   ro   r_   rp   rr   rB   ra   r0   ru   rG   )	r7   rP   rJ   ra   r   rv   rK   r=   rw   s	            r9   un_watch_tradeszhyperliquid.un_watch_trades   s      !!!V$!!F*$~5iit$X.# *0.vfTl
 ++gv.ZZ[';GGG 	" Hs"   BBA7BBBBc                 4   | j                  |dg       }| j                  |di       }| j                  |d      }| j                  |      }| j	                  |      }|d   }|| j
                  vr7| j                  | j                  dd      }	t        |	      }
|
| j
                  |<   | j
                  |   }t        dt        |            D ]6  }| j                  ||      }| j                  |      }|j                  |       8 d|z   }|j                  ||       y )Nr@   r   rq   rP   r   r   r   )rH   rE   rF   r   ra   r   r   r1   r   r   r   r   r   r   )r7   r   rw   r   rg   rq   r   ra   rP   ri   storedr   r   r@   traderv   s                   r9   handle_tradeszhyperliquid.handle_trades  s   " w3ua,v.&&t,X&!$++%%%dllM4HE&F"(DKKV$q#e*% 	!A>>%+D''-EMM% 	! 'v{+r:   r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d       }|d   }| j                  |d      }	| j                  |d      }
|
	|
dk(  rd	nd
}
| j                  |d      }| j	                  ||| j                  |      ||	| j                  |d      d |
d ||d |ddd|      S )Nr   r   r   rq   rP   tidrR   AsellbuyfeeoidUSDC)costcurrency)rV   r   datetimerP   r_   rZ   rQ   rR   takerOrMakerrT   rS   r   r   )r   rF   r   r   
safe_tradeiso8601)r7   r   ra   r   rT   rS   rq   r   rP   r_   rR   r   s               r9   r   zhyperliquid.parse_ws_trade=  s   D %%eV4	  -!!%.v.&&t,!!(D1!eU+v."ck6Due,"Y/%%eU3 V4 
  	r:   1mc                   K   | j                          d{    | j                  |      }|d   }| j                  d   d   d   }dd|d   r|d	   n|d
   |dd}d|z   dz   |z   }	| j                  ||      }
| j	                  ||	|
|	       d{   }| j
                  r|j                  ||      }| j                  |||dd      S 7 7 9w)a  
        watches historical candlestick data containing the open, high, low, close price, and the volume of a market

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NrP   r*   r   r)   rl   candlern   ro   r_   rQ   rq   intervalrr   candles:r   r   Tr   )r7   rP   	timeframer   ri   rJ   ra   rK   r=   rv   rw   ohlcvs               r9   watch_ohlcvzhyperliquid.watch_ohlcv{  s      !!!V$!iit$X.! *0.vfTl%
 !9,s2V;++gv.jjk7KHH??NN651E))%q$GG# 	" Is"   CCA9CC
8C
Cc                 @  K   | j                          d{    | j                  |      }|d   }| j                  d   d   d   }dd|d   r|d	   n|d
   |dd}d|z   dz   |z   }d|z   }| j                  ||      }	| j	                  |||	|       d{   S 7 7 w)a#  
        watches historical candlestick data containing the open, high, low, close price, and the volume of a market

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        NrP   r*   r   r)   r|   r   rn   ro   r_   r   rr   r   r   r{   r   )
r7   rP   r   rJ   ra   rK   r=   r   messagehashrw   s
             r9   un_watch_ohlcvzhyperliquid.un_watch_ohlcv  s      !!!V$!iit$X.# *0.vfTl%
 $i/#5>$~5++gv.ZZ[';GGG 	" Hs"   BBA>BBBBc                 (   | j                  |di       }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }|| j                  vri | j                  |<   || j                  |   vr:| j                  | j                  dd      }t        |      }	|	| j                  |   |<   | j                  |   |   }
| j                  |      }|
j                  |       d|z   dz   |z   }|j                  |
|       y )Nr@   sr   
OHLCVLimitr   r   r   )rE   rF   r   safe_symbolohlcvsr   r1   r   parse_ohlcvr   r   )r7   r   rw   r@   ro   r   rP   r   ri   r   r   r   rv   s                r9   handle_ohlcvzhyperliquid.handle_ohlcv  s   $ ~~gvr2c*&&t,!!(+$$T3/	$++%"$DKKT[[00%%dllL$GE*51F-3DKK	*F#I.!!$'V 9,s2V;uk*r:   rw   c                     | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|j                  ||       y )Nr@   r_   r?   payload)rE   rF   r   )r7   r   rw   r@   r_   r?   r  s          r9   handle_ws_postzhyperliquid.handle_ws_post  sT     ~~gv.dD)>>$
3..95w#r:   c                   K   | j                          d{    d}| j                  d|      \  }}d}d}|| j                  |      }|d   }|dz   |z   }| j                  d   d   d   }d	d
|dd}	| j	                  |	|      }
| j                  |||
|       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 9w)a  
        watches information on multiple orders made by the user

        https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.user]: user address, will default to self.walletAddress if not provided
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr#   rZ   rP   r   r*   r   r)   rl   orderUpdatesr   rr   T)	rB   r   ra   r0   ru   rG   r   r   r   )r7   rP   r   ri   rJ   r   ra   rv   rK   r=   rw   r;   s               r9   watch_orderszhyperliquid.watch_orders  s      !!!"66}fMV[[(FH%F%+f4Kiit$X.!&#
 ++gv.zz#{G[II??OOFE2E00tTT+ 	"$ Js"   CCBCC8CCc                 V   | j                  |dg       }| j                  -| j                  | j                  dd      }t	        |      | _        t        |      }|dk(  ry | j                  }d}i }t        dt        |            D ]@  }	||	   }
| j                  |
      }|j                  |       | j                  |d      }d||<   B t        |j                               }t        dt        |            D ]!  }	||	   }|dz   |z   }|j                  ||       # |j                  ||       y )	Nr@   ordersLimitr   r   rZ   rP   Tr   )rH   r;   r   r1   r   r   r   rc   r   rF   r   r   r   )r7   r   rw   r@   ri   r   r   rv   marketSymbolsr   rawOrderrZ   rP   r   innerMessageHashs                  r9   handle_orderzhyperliquid.handle_order  s,   * ~~gvr2;;%%dllM4HE07DKY
? q#d)$ 	)AAwH$$X.EMM% %%eX6F$(M&!	) M&&()q#d)$ 	5A!WF*S069NN6#34	5 	v{+r:   c                     | j                  |dd      }| j                  |dd      }|dk(  rt        | j                  dz   |z         y)Nchannel r@   error F)rF   r   r_   )r7   r   rw   r  ret_msgs        r9   handle_error_messagez hyperliquid.handle_error_message:  sO     ""7Ir:""7FB7g# 788r:   rt   c                     | j                  |d      }| j                  |      }| j                  |      }d|z   }d|z   }| j                  |||       || j                  v r| j                  |= y y )Nrq   rk   r{   )rF   r   r   clean_unsubscriptionr   r7   r   rt   rq   r   rP   r   rv   s           r9    handle_order_book_unsubscriptionz,hyperliquid.handle_order_book_unsubscriptionH  sy     f5&&t,!!(+%.$~5!!&.+FT__$' %r:   c                     | j                  |d      }| j                  |      }| j                  |      }d|z   }d|z   }| j                  |||       || j                  v r| j                  |= y y )Nrq   r   r{   )rF   r   r   r  r   r  s           r9   handle_trades_unsubscriptionz(hyperliquid.handle_trades_unsubscriptionZ  sw    f5&&t,!!(+!F*$~5!!&.+FT[[ F# !r:   c                     d}d|z   }| j                  |||       t        | j                  j                               }t	        dt        |            D ]  }| j                  ||   =  y )Nr   r{   r   )r  r   r   r   r   r   )r7   r   rt   r   rv   r   r   s          r9   handle_tickers_unsubscriptionz)hyperliquid.handle_tickers_unsubscriptione  sd    "$~5!!&.+Ft||((*+q#g,' 	)AWQZ(	)r:   c                 Z   | j                  |d      }| j                  |      }| j                  |      }| j                  |d      }| j                  |      }d|z   dz   |z   }d|z   }	| j	                  |||	       || j
                  v r#|| j
                  |   v r| j
                  |   |= y y y )Nrq   r   r   r   r{   )rF   r   r   find_timeframer  r   )
r7   r   rt   rq   r   rP   r   r   r   rv   s
             r9   handle_ohlcv_unsubscriptionz'hyperliquid.handle_ohlcv_unsubscriptionn  s    f5&&t,!!(+##L*=''1	#i/#5>$~5!!&.+FT[[ DKK//KK'	2 0 !r:   c                 d   | j                  |di       }| j                  |d      }|dk(  r| j                  |di       }| j                  |d      }|dk(  r| j                  ||       y |dk(  r| j                  ||       y |dk(  r| j	                  ||       y |d	k(  r| j                  ||       y y y )
Nr@   rs   r|   rt   rQ   rm   r   r   r   )rE   rF   r  r  r  r  )r7   r   rw   r@   rs   rt   rQ   s          r9   handle_subscription_responsez(hyperliquid.handle_subscription_response{  s    2 ~~gvr2!!$1]">>$CL##L&9Dx55flK!11&,G#226<H!00F " #r:   c           
         | j                  ||      ry | j                  |dd      }| j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  d	}| j                  ||      }|
 |||       y t        |j                               }t        dt        |            D ].  }||   }|j!                  ||         dk\  s ||   }	 |	||        y  y )Nr  r  )	pongr   rm   r   r  r   r   postsubscriptionResponser   )r  rF   handle_pongr   r   r  r  r   r   r  r!  
safe_valuer   r   r   r   find)
r7   r   rw   topicmethods
exacMethodr   r   keyrs   s
             r9   handle_messagezhyperliquid.handle_message  s    $$VW5  )R8$$((,,'' --....''$($E$E

 __We4
!vw'GLLN#q#d)$ 	Aq'Czz$q'"a' vw'	r:   c                 
    ddiS )Nrs   r,    )r7   r   s     r9   r,   zhyperliquid.ping  s    f
 	
r:   c                 4    | j                  |d      |_        |S )Nr#  )r   lastPong)r7   r   rw   s      r9   r&  zhyperliquid.handle_pong  s     ++GV<r:   c                 ~    | j                  | j                  | j                  dd      d      }|| j                  d<   |S )Nr>   r   r   )sumr   r1   )r7   r>   s     r9   
request_idzhyperliquid.request_id  s9    HHT..t||[!LaP	$-[!r:   r=   c                 :    | j                         }|d|d|dddS )Nr$  action)rQ   r  )rs   r_   r=   )r>   r=   )r4  )r7   r=   r>   s      r9   rD   zhyperliquid.wrap_as_post_action  s1    OO%	" $&

 
	
r:   r   );__name__
__module____qualname__r   r6   r   r   rO   r}   r   r   floatr	   r^   rh   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   dictr   r   r   r   r  r  r
   r  r  r  r  r  r  r  r!  r-  r,   r&  r4  rD   __classcell__)r8   s   @r9   r   r      s   *# *X IK 1T,-? 1, pt|~ C y 	 [` il < ]aos|~ 'c '3 'c ' 'VY 'il 'R @DB !S ! !S\ !6 =? H H3 H8,/\ 68  F  6:" 7  4 9=R ]g ]C ]0 37TX\eg  UC  Us  URU  Ulpqvlw  UDG+ G+R4 46 43,v 3,j <@d[] S SS S Sbfglbm S< 9; HC Hs H4!,F !,F<D <& <E <| 8<$]ajl H HC HWZ Hquvzq{ H@ ;?r H3 Hc H8!+6 !+F$V $d $  04$UYbd "U "UC "Us "Uimnsit "UH*,6 *,X6 (v (T ($	$6 	$ 	$)F )$ )3& 3 3%G6 %GN'V 'R
6 

& E 

4 
D 
r:   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr   r/  r:   r9   <module>rE     sK     f f N  N  N  N 4  *\
$$$00 \
r:   