
    E#i&                         S SK rS SKJrJrJr  S SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr   " S S\R4                  R6                  5      rg)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBoolIntMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTrade)Client)Listc                     ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS0 4S\	S\
S	\S
\S\4
S jjrSS0 4S\	S\	S\	S	\	S
\S\4S jjrS0 4S\\	   S\4S jjrS0 4S\	S\4S jjrS0 4S\	S\S\4S jjr0 4S\	S\4S jjrS r0 4S\	S\4S jjrS0 4S\S\4S jjrS0 4S\S\4S jjrSSS0 4S\S\S\S\\   4S jjrS\ 4S jr!S=S\"S\4S jjr#S\ 4S  jr$SS0 4S\	S\S\S\\   4S! jjr%0 4S\	S\4S" jjr&S\ 4S# jr'S=S$\(S\"S\4S% jjr)S&SS0 4S\	S'\	S\S\S\\*   4
S( jjr+S&0 4S\	S'\	S\4S) jjr,S\ 4S* jr-S\ S+\(4S, jr.SSS0 4S\S\S\S\\/   4S- jjr0S\ 4S. jr1S\ S\24S/ jr3S\ S0\(4S1 jr4S\ S0\(4S2 jr5S\ S0\(4S3 jr6S\ S0\(4S4 jr7S\ 4S5 jr8S\ 4S6 jr9S\ 4S7 jr:S\ 4S8 jr;S\4S9 jr<S:\(S\(4S; jr=S<r>U =r?$ )>hyperliquid   returnc           
         > U R                  [        [        U ]  5       0 SS_SS_SS_SS_SS_SS_SS	_S
S_SS_SS_SS_SS_SS_SS_SS	_SS	_SSS00SSS00S.0 U R                  SS.SS0 00S.5      $ )NwsTcancelOrderWscancelOrdersWscreateOrderWscreateOrdersWseditOrderWswatchBalanceFwatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchTradeswatchTradesForSymbolswatchPosition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/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/hyperliquid.pyr9   hyperliquid.describe   sF   k4 A Cd !$  	
 !$ t    d !$ t t  t (   !(  "@  "H 		"
  K+F
 + +	    ordersc                   #    U R                  5       I Sh  vN   U R                  S   S   S   nU R                  X5      nU R                  U5      nU R	                  US0 5      nU R                  US5      nU R                  X7Xg5      I Sh  vN nU R	                  US0 5      n	U R	                  U	S0 5      n
U R                  U
S	/ 5      nU R                  US5      $  N NQ7f)
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_marketsr3   createOrdersRequestwrap_as_post_action	safe_dictsafe_stringwatch	safe_listparse_orders)r:   r?   paramsurlordersRequestwrappedrA   rB   rC   responseOjbrD   rE   s               r<   create_orders_wshyperliquid.create_orders_ws=   s      !!!iit$X.00@**=9..)R8$$Wk:	CGGGnnXz2>~~k626>>$
B7  400 	" Hs#   C CA5C CAC C Nsymboltypesideamountpricec           	         #    U R                  5       I Sh  vN   U R                  SXX4XV5      u  pxU R                  U/U5      I Sh  vN n	[        U	5      n
U
S:X  a  U R	                  0 5      $ U	S   nU$  N^ N/7f)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   )rF   parseCreateEditOrderArgsrS   len
safe_order)r:   rU   rV   rW   rX   rY   rN   orderglobalParamsr?   ordersLengthparsedOrders               r<   create_order_wshyperliquid.create_order_wsS   s     * !!!";;D&PT^cl,,eWlCC6{1??2&&Qi 	"Cs!   A9A50A9A7.A97A9idc           	      B  #    U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   S   n	U R                  XX4XVU5      u  pU R	                  U
/U5      nU R                  U5      nU R                  US0 5      nU R                  US5      nU R                  XX5      I Sh  vN nU R                  US0 5      nU R                  US0 5      nU R                  US	/ 5      nU R                  US
0 5      nU R                  UU5      nU$  GN Ng7f)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,   rA   rB   rC   rD   rE   r   )rF   marketr3   r[   editOrdersRequestrH   rI   rJ   rK   rL   parse_order)r:   rd   rU   rV   rW   rX   rY   rN   rf   rO   r^   r_   postRequestrQ   rA   rB   rC   responseObject
dataObjectrE   firstra   s                         r<   edit_order_wshyperliquid.edit_order_wsr   s     * !!!V$iit$X.";;BTZcij,,eWlC**;7..)R8$$Wk:	CGGG*bA^^NFB?
>>*j"=xB/&&uf5 	" Hs#   DDBD5D6A%DDidsc                 P  #    U R                  5         U R                  5       I Sh  vN   U R                  XU5      nU R                  S   S   S   nU R	                  U5      nU R                  US0 5      nU R                  US5      nU R                  XXXx5      I Sh  vN n	U R                  U	S0 5      n
U R                  U
S0 5      nU R                  US	/ 5      n/ n[        S
[        U5      5       H*  nX   nUR                  U R                  UUS.5      5        M,     U$  N N7f)aY  
cancel multiple orders using WebSocket post request

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

:param str[] ids: list of order ids to cancel
:param str symbol: unified symbol of the market the orders were made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str[] [params.clientOrderId]: list of client order ids to cancel instead of order ids
:param str [params.vaultAddress]: the vault address for order cancellation
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr-   r   r,   rA   rB   rC   rD   rE   r   )infostatus)check_required_credentialsrF   cancelOrdersRequestr3   rH   rI   rJ   rK   rL   ranger\   appendr]   )r:   ro   rU   rN   rA   rO   rQ   	wsRequestrB   rC   responseObjrD   rE   r?   irr   s                   r<   cancel_orders_wshyperliquid.cancel_orders_ws   s!     	'')!!!**3?iit$X.**73NN7Ir:	$$Wk:	CIIInnXz2>~~k626>>$
B7q#h-(A[FMM$// +   ) # 	" Js#   $D&D"A6D&D$BD&$D&c                 h   #    U R                  U/X#5      I Sh  vN nU R                  US5      $  N7f)a4  
cancel a single order using WebSocket post request

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

:param str id: order id to cancel
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: client order id to cancel instead of order id
:param str [params.vaultAddress]: the vault address for order cancellation
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   )rz   rI   )r:   rd   rU   rN   r?   s        r<   cancel_order_wshyperliquid.cancel_order_ws   s5      ,,bT6BB~~fa(( Cs   202limitc                 L  #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nU R                  S   S   S   nSSUS	   (       a  US
   OUS   S.S.nU R                  Xs5      nU R	                  XeX5      I Sh  vN n	U	R                  5       $  N N7f)a   
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
NrU   
orderbook:r-   r   r,   	subscribel2BookswapbaseNamerd   rV   coinmethodsubscription)rF   rf   r3   extendrK   r   )
r:   rU   r   rN   rf   messageHashrO   rA   message	orderbooks
             r<   watch_order_bookhyperliquid.watch_order_book   s      !!!V$!"V+iit$X.! .4Vnz*&,
 ++g.**SwLL	   	" Ms"   B$B A4B$B"B$"B$c                 j  #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nSU-   nU R                  S   S   S   n[        U R	                  5       5      nUSS	US
   (       a  US   OUS   S.S.nU R                  X5      n	U R                  XeX5      I Sh  vN $  N N7f)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
NrU   r   unsubscribe:r-   r   r,   unsubscriber   r   r   rd   r   )rd   r   r   )rF   rf   r3   strnoncer   rK   )
r:   rU   rN   rf   subMessageHashr   rO   rd   rA   r   s
             r<   un_watch_order_bookhyperliquid.un_watch_order_book   s      !!!V$!%.$~5iit$X.# .4Vnz*&,
 ++g.ZZ'GGG! 	"  Hs"   B3B/BB3*B1+B31B3c           	      (   U R                  US0 5      nU R                  US5      nU R                  U5      nU R                  U5      nUS   nU R	                  US/ 5      nU R	                  US/ 5      U R	                  US/ 5      S.n	U R                  US5      n
U R                  XU
S	S
SS5      nXpR                  ;  a  U R                  U5      nXR                  U'   U R                  U   nUR                  U5        SU-   nUR                  X5        g )NrD   r   rU   levelsr      )bidsaskstimer   r   pxszr   )rI   rJ   coinToMarketIdrf   rL   safe_integerparse_order_book
orderbooks
order_bookresetresolve)r:   clientr   entryr   marketIdrf   rU   rawDatarD   	timestampsnapshotobr   r   s                  r<   handle_order_bookhyperliquid.handle_order_book   s   4 w3v.&&t,X&!.."5NN7Ar2NN7Ar2
 %%eV4	((y&&RVX\]//)*B&(OOF#OOF+	!"V+y.r>   c                 x   #    U R                  U5      nUS   nU R                  U/U5      I Sh  vN nXA   $  N7f)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>`
rU   N)rf   watch_tickers)r:   rU   rN   rf   tickerss        r<   watch_tickerhyperliquid.watch_ticker.  sC      V$!**F8V<< =s   -:8	:symbolsc                 Z  #    U R                  5       I Sh  vN   U R                  USS5      nSnU R                  S   S   S   nSSS	S
.S.nU R                  XCU R	                  XR5      U5      I Sh  vN nU R
                  (       a  U R                  USU5      $ U R                  $  N N67f)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,   r   webData2*0x0000000000000000000000000000000000000000rV   userr   rU   )rF   market_symbolsr3   rK   r   
newUpdatesfilter_by_array_tickersr   )r:   r   rN   r   rO   rA   r   s          r<   r   hyperliquid.watch_tickers=  s      !!!%%gtT:iit$X.!"D
 

3T[[5QS^__??//7KK|| 	" `s"   B+B'AB+2B)35B+)B+c                   #    U R                  5       I Sh  vN   U R                  USS5      nSnSU-   nU R                  S   S   S   nSS	S
S.S.nU R                  XTU R	                  Xb5      U5      I Sh  vN $  Ne N7f)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   r   )rF   r   r3   rK   r   )r:   r   rN   r   r   rO   rA   s          r<   un_watch_tickershyperliquid.un_watch_tickersW  s      !!!%%gtT:"$~5iit$X.#"D
 ZZ$++g2NP[\\\ 	" ]s"   B A<A B 7A>8B >B sincec                   #    SnU R                  SU5      u  pTU R                  5       I Sh  vN   SnUb  U R                  U5      nUSU-   -  nU R                  S   S   S   nSS	US
.S.nU R	                  X5      n	U R                  XvX5      I Sh  vN n
U R                  (       a  U
R                  X5      nU R                  XX#S5      $  N N;7f)al  
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,   r   	userFillsr   r   T)	handlePublicAddressrF   rU   r3   r   rK   r   getLimitfilter_by_symbol_since_limit)r:   rU   r   r   rN   userAddressr   rO   rA   r   tradess              r<   watch_my_tradeshyperliquid.watch_my_tradeso  s      "66O!!! [[(F3<'Kiit$X.!##
 ++g.zz#GII??OOF2E00tTT# 	" Js"   *CCA%CC:CCr   c           	      B   U R                  US0 5      nU R                  US/ 5      n/ n[        S[        U5      5       Hb  nXF   nU R	                  US5      nU R                  US S S5      n	U	S   n
U R                  Xy5      nUR                  U5        XR                  U
'   Md     U R                  US0 5      nU R                  US/ 5      nU R                  US	/ 5      n[        S[        U5      5       H  nU R                  U R                  X0 5      U R                  X0 5      5      nUS
   S-   nU R                  US S S5      n	U	S   n
U R                  X5      nXR                  U
'   UR                  U5        M     U R                  US5      nUR                  US5        g )NrD   spotAssetCtxsr   r   spotrU   metauniverse	assetCtxsnamez
/USDC:USDCr   r   )rI   rL   ru   r\   rJ   safe_marketparse_ws_tickerrv   r   r   index_byr   )r:   r   r   r   
spotAssetsparsedTickersry   assetObjectr   rf   rU   tickerr   r   r   rD   rd   r   s                     r<   handle_ws_tickershyperliquid.handle_ws_tickers  s   ` ..&"5^^G_bA
q#j/*A$-K''V<H%%hdFCFH%F))+>F  (#)LL  + ~~gvr2>>$
B7NN7K<	q#h-(A;;xB/yR0D f,B%%b$f=FH%F))$7F#)LL   ( ) --x8w	*r>   rf   c                 $    U R                  X5      $ N)parse_ticker)r:   	rawTickerrf   s      r<   r   hyperliquid.parse_ws_ticker  s      33r>   c                 Z   U R                  US0 5      nU R                  c-  U R                  U R                  SS5      n[	        U5      U l        U R                  n0 nU R                  US/ 5      n[        U5      nUS:X  a  g [        S[        U5      5       H2  n	Xy   n
U R                  U
5      nUS   nSXl'   UR                  U5        M4     [        UR                  5       5      n[        S[        U5      5       H  n	SX   -   nUR                  X^5        M     S	nUR                  X_5        g )
NrD   tradesLimit  fillsr   rU   Tz	myTrades:r   )rI   r   r   r4   r   rL   r\   ru   parse_ws_traderv   listkeysr   )r:   r   r   r   r   r   r   rD   
dataLengthry   rawTradeparsedrU   r   currentMessageHashr   s                   r<   handle_my_tradeshyperliquid.handle_my_trades  s   : w3== %%dllM4HE259DM~~eWb1Y
?q#d)$AwH((2FH%F"GOMM&! % GLLN#q#d)$A!,tw!6NN66 % !v+r>   c                   #    U R                  5       I S h  vN   U R                  U5      nUS   nSU-   nU R                  S   S   S   nSSUS   (       a  US	   OUS
   S.S.nU R                  X5      n	U R	                  XvX5      I S h  vN n
U R
                  (       a  U
R                  X5      nU R                  XUSS5      $  N N<7f)NrU   trade:r-   r   r,   r   r   r   r   rd   r   r   r   TrF   rf   r3   r   rK   r   r   filter_by_since_limit)r:   rU   r   r   rN   rf   r   rO   rA   r   r   s              r<   watch_tradeshyperliquid.watch_trades  s      !!!V$!'iit$X.! .4Vnz*&,
 ++g.zz#GII??OOF2E))&TRR! 	" Js"   C
CA4C
C;C
C
c                 6  #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nSU-   nU R                  S   S   S   nSS	US
   (       a  US   OUS   S.S.nU R                  Xr5      nU R	                  XeX5      I Sh  vN $  N~ N7f)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>`
NrU   r   r   r-   r   r,   r   r   r   r   rd   r   r   rF   rf   r3   r   rK   )	r:   rU   rN   rf   r   r   rO   rA   r   s	            r<   un_watch_tradeshyperliquid.un_watch_trades4  s      !!!V$!!F*$~5iit$X.# .4Vnz*&,
 ++g.ZZ'GGG 	" Hs"   BBA9BBBBc                 4   U R                  US/ 5      nU R                  US0 5      nU R                  US5      nU R                  U5      nU R	                  U5      nUS   nXR
                  ;  a6  U R                  U R                  SS5      n	[        U	5      n
XR
                  U'   U R
                  U   n[        S[        U5      5       H6  nU R                  X<5      nU R                  U5      nUR                  U5        M8     SU-   nUR                  X5        g )NrD   r   r   rU   r   r   r   )rL   rI   rJ   r   rf   r   r   r4   r   ru   r\   r   rv   r   )r:   r   r   r   rl   r   r   rf   rU   r   storedr   ry   rD   trader   s                   r<   handle_tradeshyperliquid.handle_tradesN  s    " w3ua,v.&&t,X&!++%%%dllM4HE&F"(KKV$q#e*%A>>%+D''-EMM%  & 'v+r>   r   c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  US 5      nUS   nU R                  US5      n	U R                  US5      n
U
b
  U
S:X  a  S	OS
n
U R                  US5      nU R	                  UUU R                  U5      UU	U R                  US5      S U
S UUS USS.S.U5      $ )Nr   r   r   r   rU   tidrW   AsellbuyfeeoidUSDC)costcurrency)rq   r   datetimerU   rd   r^   rV   rW   takerOrMakerrY   rX   r  r  )r   rJ   r   r   
safe_tradeiso8601)r:   r   rf   r   rY   rX   r   r   rU   rd   rW   r  s               r<   r   hyperliquid.parse_ws_tradeq  s   D %%eV4	  -!!%.v.&&t,!!(D1!eU+v."ck6Due,"Y/%%eU3 V4 
  	r>   1m	timeframec                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   S   nSSUS   (       a  US	   OUS
   US.S.nSU-   S-   U-   n	U R                  X5      n
U R	                  XyX5      I Sh  vN nU R
                  (       a  UR                  X5      nU R                  XUSS5      $  N N<7f)aj  
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
NrU   r-   r   r,   r   candler   r   rd   rV   r   intervalr   candles:r   r   Tr   )r:   rU   r  r   r   rN   rf   rO   rA   r   r   ohlcvs               r<   watch_ohlcvhyperliquid.watch_ohlcv  s      !!!V$!iit$X.! .4Vnz*&,%
 !9,s2V;++g.jj7HH??NN61E))%q$GG# 	" Is"   CCA;CC;CCc                 D  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  S   S   S   nSSUS   (       a  US	   OUS
   US.S.nSU-   S-   U-   nSU-   nU R                  Xc5      n	U R	                  XXX5      I Sh  vN $  N N7f)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
NrU   r-   r   r,   r   r  r   r   rd   r  r   r  r   r   r   )
r:   rU   r  rN   rf   rO   rA   r   messagehashr   s
             r<   un_watch_ohlcvhyperliquid.un_watch_ohlcv  s      !!!V$!iit$X.# .4Vnz*&,%
 $i/#5>$~5++g.ZZ'GGG 	" Hs"   B BB B BB B c                 (   U R                  US0 5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nX`R                  ;  a  0 U R                  U'   XpR                  U   ;  a9  U R                  U R                  SS5      n[        U5      n	XR                  U   U'   U R                  U   U   n
U R                  U5      nU
R                  U5        SU-   S-   U-   nUR                  X5        g )NrD   sry   
OHLCVLimitr   r  r   )rI   rJ   r   safe_symbolohlcvsr   r4   r   parse_ohlcvrv   r   )r:   r   r   rD   baser   rU   r  r   r   r  r   r   s                r<   handle_ohlcvhyperliquid.handle_ohlcv  s   $ ~~gvr2c*&&t,!!(+$$T3/	++%"$DKK[[00%%dllL$GE*51F-3KK	*F#I.!!$'V 9,s2V;u*r>   r   c                     U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUR                  Xd5        g )NrD   rd   rC   payload)rI   rJ   r   )r:   r   r   rD   rd   rC   r'  s          r<   handle_ws_posthyperliquid.handle_ws_post  sR     ~~gv.dD)>>$
3..95w#r>   c                   #    U R                  5       I Sh  vN   SnU R                  SU5      u  pTSnSnUb  U R                  U5      nUS   nUS-   U-   nU R                  S   S   S   nS	S
US.S.n	U R	                  X5      n
U R                  XX5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  N N;7f)al  
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&   r^   rU   r   r-   r   r,   r   orderUpdatesr   r   T)	rF   r   rf   r3   r   rK   r   r   r   )r:   rU   r   r   rN   r   rf   r   rO   rA   r   r?   s               r<   watch_ordershyperliquid.watch_orders  s      !!!"66}fM[[(FH%F%+f4Kiit$X.!&#
 ++g.zz#GII??OOF2E00tTT+ 	"$ Js"   CCBCC:CCc                 X   U R                  US/ 5      nU R                  c-  U R                  U R                  SS5      n[	        U5      U l        [        U5      nUS:X  a  g U R                  nSn0 n[        S[        U5      5       H?  n	X9   n
U R                  U
5      nUR                  U5        U R                  US5      nSX'   MA     [        UR                  5       5      n[        S[        U5      5       H   n	X   nUS-   U-   nUR                  Xn5        M"     UR                  Xg5        g )	NrD   ordersLimitr   r   r^   rU   Tr   )rL   r?   r   r4   r   r\   ru   rh   rv   rJ   r   r   r   )r:   r   r   rD   r   r   r   r   marketSymbolsry   rawOrderr^   rU   r   innerMessageHashs                  r<   handle_orderhyperliquid.handle_orderB  s   * ~~gvr2;;%%dllM4HE07DKY
? q#d)$AwH$$X.EMM% %%eX6F$(M! % M&&()q#d)$AWF*S069NN64 % 	v+r>   c                 8   U R                  USS5      nUS:X  a7  U R                  USS5      nU R                  S-   U-   nUR                  U5        gU R                  US0 5      nU R                  US5      nUc  U R                  US5      nU R                  US0 5      nU R                  US	0 5      n	U R                  U	S
5      n
U
b9  U
S:w  a3  U R                  S-   U R	                  U	5      -   nUR                  XW5        gU R                  U	S5      nUS:X  a3  U R                  S-   U R	                  U	5      -   nUR                  X5        g U R                  SSSS0 U R	                  U	5      U	0 0 5	        g! [         a  nUR                  X5         S nAgS nAff = f)Nchannel errorrD    Trd   rC   r'  rr   okrV   r   F)rJ   rd   rejectrI   jsonhandle_errors	Exception)r:   r   r   r6  ret_msgerrorMsgrD   rd   rC   r'  rr   rV   r8  es                 r<   handle_error_message hyperliquid.handle_error_messagen  s   < ""7Ir:g&&w;Gww}w.HMM(#~~gvr2gt,:!!$-B>>$
B7..9b9!!'84&D.ww}tyy'99HMM('07?GGcMDIIg$66EMM%$	q"b"b$))G2DgrSUV   	MM! 	s   (E4 4
F>FFr   c                     U R                  US5      nU R                  U5      nU R                  U5      nSU-   nSU-   nU R                  XU5        XPR                  ;   a  U R                  U	 g g )Nr   r   r   )rJ   r   r   clean_unsubscriptionr   r:   r   r   r   r   rU   r   r   s           r<    handle_order_book_unsubscription,hyperliquid.handle_order_book_unsubscription  su     f5&&t,!!(+%.$~5!!&+F__$' %r>   c                     U R                  US5      nU R                  U5      nU R                  U5      nSU-   nSU-   nU R                  XU5        XPR                  ;   a  U R                  U	 g g )Nr   r   r   )rJ   r   r   rE  r   rF  s           r<   handle_trades_unsubscription(hyperliquid.handle_trades_unsubscription  ss    f5&&t,!!(+!F*$~5!!&+F[[ F# !r>   c                     SnSU-   nU R                  XU5        [        U R                  R                  5       5      n[	        S[        U5      5       H  nU R                  XV   	 M     g )Nr   r   r   )rE  r   r   r   ru   r\   )r:   r   r   r   r   r   ry   s          r<   handle_tickers_unsubscription)hyperliquid.handle_tickers_unsubscription  s[    "$~5!!&+Ft||((*+q#g,'AWZ( (r>   c                 \   U R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nU R                  U5      nSU-   S-   U-   nSU-   n	U R	                  XU	5        XPR
                  ;   a$  XpR
                  U   ;   a  U R
                  U   U	 g g g )Nr   r  r  r   r   )rJ   r   r   find_timeframerE  r!  )
r:   r   r   r   r   rU   r  r  r   r   s
             r<   handle_ohlcv_unsubscription'hyperliquid.handle_ohlcv_unsubscription  s    f5&&t,!!(+##L*=''1	#i/#5>$~5!!&+F[[ KK//KK'	2 0 !r>   c                 f   U R                  US0 5      nU R                  US5      nUS:X  a  U R                  US0 5      nU R                  US5      nUS:X  a  U R                  X5        g US:X  a  U R                  X5        g US:X  a  U R	                  X5        g US	:X  a  U R                  X5        g g g )
NrD   r   r   r   rV   r   r   r   r  )rI   rJ   rG  rJ  rM  rQ  )r:   r   r   rD   r   r   rV   s          r<   handle_subscription_response(hyperliquid.handle_subscription_response  s    2 ~~gvr2!!$1]">>$CL##L&9Dx55fK!11&G#226H!00F " #r>   c           
         U R                  X5      (       a  g U R                  USS5      nU R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S.	nU R                  XC5      nUb	  U" X5        g [        UR                  5       5      n[        S[        U5      5       H,  nXg   nUR!                  Xg   5      S:  d  M   XH   n	U	" X5          g    g )Nr6  r7  )	pongr   r   r  r+  r   r   postsubscriptionResponser   )rB  rJ   handle_pongr   r   r$  r3  r   r   r(  rT  
safe_valuer   r   ru   r\   find)
r:   r   r   topicmethods
exacMethodr   ry   keyr   s
             r<   handle_messagehyperliquid.handle_message  s     $$V55  )R8$$((,,'' --....''$($E$E

 __W4
!v'GLLN#q#d)$A'Czz$'"a' v' %r>   c                 
    SS0$ )Nr   r/    )r:   r   s     r<   r/   hyperliquid.ping,  s    f
 	
r>   c                 4    U R                  US5      Ul        U$ )NrW  )r   lastPong)r:   r   r   s      r<   rZ  hyperliquid.handle_pong1  s     ++GV<r>   c                 |    U R                  U R                  U R                  SS5      S5      nXR                  S'   U$ )NrB   r   r   )sumr   r4   )r:   rB   s     r<   
request_idhyperliquid.request_id:  s7    HHT..t||[!LaP	$-[!r>   rA   c                 :    U R                  5       nUSUSUS.S.S.$ )NrX  action)rV   r'  )r   rd   rA   )rB   rA   )rk  )r:   rA   rB   s      r<   rH   hyperliquid.wrap_as_post_action?  s1    OO%	" $&

 
	
r>   )r   r?   r   )@__name__
__module____qualname____firstlineno__r   r9   r   r   rS   r   r   r   floatr
   rb   rm   r   rz   r}   r   r   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,  r3  r   rB  rG  rJ  rM  rQ  rT  ra  r/   rZ  rk  rH   __static_attributes____classcell__)r;   s   @r<   r   r      s   ,# ,\ IK 1T,-? 1, pt|~ C y 	 [` il > ]aos|~ $c $3 $c $ $VY $il $L DHPR $s) S B <@ ) )S )  @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K+ K+Z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 <| ?CQUdhqs H H H3 H^a Hx|  ~B  yC H@ BFb H3 H3 HUX H8!+6 !+F$V $d $  04$UYbd "U "UC "Us "Uimnsit "UH*,6 *,X96 9t 9v(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   r   !ccxt.async_support.base.ws.clientr   typingr   async_supportr   rd  r>   r<   <module>r     sN     f f T  T  T  T  T 4 ~
$$$00 ~
r>   