
    E#il                         S SK rS SKJrJrJrJr  S SK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  S SKJr  S SKJr  S SKJr   " S S\R4                  R6                  5      rg)	    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesBoolIntOrder	OrderBookPositionStrStringsTickerTrade)Client)List)ExchangeErrorc            
       F  ^  \ rS rSrS\4U 4S jjrS\4S jrS\S\S\	S\4S	 jr
0 4S
\S\4S jjrS\4S jrS*S jrSSS0 4S
\S\S\S\\   4S jjrS\4S jrS*S\4S jjrS0 4S
\S\S\4S jjrS\4S jrS rSS0 4S
\S\S\S\\   4S jjrS\4S jrS*S jr0 4S jr0 4S\4S jjrS\4S jr S r!SSS0 4S\"S\S\S\\#   4S  jjr$S! r%S0 4S"\\   S\\   S\\#   4S# jjr&S*S$ jr'SSS0 4S
\(S\S\S\\)   4S% jjr*S\4S& jr+S*S\)4S' jjr,S\S\-4S( jr.S)r/U =r0$ )+arkham   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSSS.SSS00SSS	S
.0SS0S.5      $ )NTF)wswatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolswatchOrderswatchMyTradeswatchTickerwatchTickerswatchBalanceapir   zwss://arkm.com/wsr   d   i  )depthinterval	keepAlivei )hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    I/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/arkham.pyr1   arkham.describe   s    fd < >#)."&,1"(-#!&# % $ - !  ## V5A
  	    clientc           	      T   U R                  X5      (       a  g U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  S.nU R                  US5      nUS:X  a  g U R                  X45      nUb	  U" X5        g g )N)tickercandles
l2_updatestradesbalances	positionsorder_statusestrigger_orderschannelconfirmations)
handle_error_messagehandle_tickerhandle_ohlcvhandle_order_bookhandle_tradeshandle_balancehandle_positionshandle_ordersafe_string
safe_value)r2   r7   messagemethodsrA   methods         r4   handle_messagearkham.handle_message1   s    
 $$V55((((00((++.."//"//

 ""7I6o%
 26# r6   messageHash
rawChannelparamsc                    #    UnUUS.U R                  5       SS.nU R                  U R                  S   S   XU5      I S h  vN $  N7f)N)rA   rT   	subscribe)argsconfirmationIdrO   r&   r   )uuidwatchr,   )r2   rR   rS   rT   subscriptionHashrequests         r4   rV   arkham.subscribeN   sW     & &  #iik!
 ZZ		% 0 6N^____s   A A	AA	symbolc                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nSUS   -   nU R                  USU R                  X$5      5      I Sh  vN $  NN N7f)a  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://arkm.com/docs#stream/ticker

: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>`
Nr^   idticker::r9   )load_marketsmarketrV   extend)r2   r^   rT   rc   
requestArgrR   s         r4   watch_tickerarkham.watch_tickerZ   sr      !!!V$fTl

 !6(#33^^K4;;v;Z[[[ 	" \s"   A)A%A	A) A'!A)'A)c                     U R                  US0 5      nU R                  US5      nU R                  US 5      nUS   nU R                  X55      nXpR                  U'   UR                  USU-   5        g )Ndatar^   ra   )	safe_dictrK   safe_marketparse_ws_tickertickersresolve)r2   r7   rM   ri   marketIdrc   r^   r9   s           r4   rD   arkham.handle_tickerl   ss    8 ~~gvr2##D(3!!(D1!%%d3%VvzF23r6   Nc                 $    U R                  X5      $ N)parse_ticker)r2   rM   rc   s      r4   rl   arkham.parse_ws_ticker   s      11r6   1msincelimitc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  X"5      nUS   US.nSUS   -   S-   U-   n	U R	                  U	SU R                  X5      5      I Sh  vN n
U
nU R                  (       a  UR                  US   U5      nU R                  XUSS	5      $  N NB7f)
a8  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://arkm.com/docs#stream/candles

: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
Nr`   )r^   durationohlcv::r^   ::r:   r   T)	rb   rc   rK   
timeframesrV   rd   
newUpdatesgetLimitfilter_by_since_limit)r2   r^   	timeframerv   rw   rT   rc   rawTimeframere   rR   resultohlcvs               r4   watch_ohlcvarkham.watch_ohlcv   s      !!!V$''NTl$

  &"22T9LH~~k9dkk*>]^^??NN6(#3U;E))%q$GG 	" _s#   CCA,CCACCc                 8   U R                  US0 5      nU R                  US5      nU R                  US 5      nUS   nU R                  US5      nU R	                  U5      nSU-   S-   U-   n	U R                  U R                  U0 5      U R                  U'   XR                  U   ;  a.  U R                  SSS5      n
[        U
5      U R                  U   U'   U R                  U   U   nU R                  X55      nUR                  U5        UR                  X5        U$ )	Nri   r^   ry   rz   r{   r   rw     )rj   rK   rk   safe_integerfindTimeframeByDurationrL   ohlcvshandle_optionr   parse_ws_ohlcvappendrn   )r2   r7   rM   ri   ro   rc   r^   ry   r   rR   rw   storedparseds                r4   rE   arkham.handle_ohlcv   s   $ ~~gvr2##D(3!!(D1!$$T:600:	&(4/);"oodkk62FF[[00&&|WdCE-B5-IDKK	*V$Y/$$T2fv+r6   c                 $    U R                  X5      $ rr   )parse_ohlcv)r2   r   rc   s      r4   r   arkham.parse_ws_ohlcv       ..r6   c                    #    U R                  5       I Sh  vN   U R                  U5      nUS   SS.nSUS   -   nU R                  USU R                  XS5      5      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://arkm.com/docs#stream/l2_updates

: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
Nr`   T)r^   snapshotorderBook::r^   r;   )rb   rc   rV   rd   rw   )r2   r^   rw   rT   rc   re   rR   	orderbooks           r4   watch_order_bookarkham.watch_order_book   s      !!!V$Tl

 $fX&66..lDKKPZDcdd	   	" es"   A:A6A
A:!A8"A:8A:c           	         U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5      nUS   nSU-   nXpR                  ;  a#  U R	                  0 5      n	XyS'   XR                  U'   U R                  U   n
US:X  a;  U R                  USS5      nU R                  X7USS	S
S5      nU
R                  U5        OdUS:X  a^  U R                  USS5      nU R                  US5      nUS:X  a  U
S   OU
S	   nU R                  X5        XS'   U R                  U5      U
S'   XR                  U'   UR                  U R                  U   U5        g )Nri   typer^   r   r   lastTimegMbP?bidsaskspricesizeupdatetimesidebuy	timestampdatetime)rj   rK   rk   
orderbooks
order_booksafe_integer_productparse_order_bookresethandle_deltaiso8601rn   )r2   r7   rM   ri   r   ro   rc   r^   rR   obr   r   parsedOrderBookr   booksides                  r4   rF   arkham.handle_order_book   sl   @ ~~gv.0##D(3!!(+!#f,//)$B!xL&(OOF#OOF+	:11$
EJI"33D)VU[]dflmOOOO,X11$FI##D&1D-1U]y(6ARHh-%.k"$(LL$;Ij!"+tv.<r6   c                 L    U R                  USS5      nUR                  U5        g )Nr   r   )parse_bid_ask
storeArray)r2   r   deltabidAsks       r4   r   arkham.handle_delta'  s$    ##E7F;F#r6   c                 J  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nSUS   -   nU R                  USU R                  Xd5      5      I Sh  vN nU R                  (       a  UR                  US   U5      nU R                  XUSS5      $  N N@7f)a  
watches information on multiple trades made in a market

https://arkm.com/docs#stream/trades

:param str symbol: unified market symbol of the market trades were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of trade structures to retrieve
: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>`
Nr^   r`   trade::r<   r   T)rb   rc   rV   rd   r}   r~   r   )	r2   r^   rv   rw   rT   rc   re   rR   r<   s	            r4   watch_tradesarkham.watch_trades+  s      !!!V$fTl

  &"22~~k8T[[=\]]??OOF8$4e<E))&TRR 	" ^s"   B#BA	B# B!!?B#!B#c                    U R                  US5      nU R                  US5      nU R                  U5      nXPR                  ;  a5  U R	                  U R
                  SS5      n[        U5      U R                  U'   U R                  U5      nU R                  U   nUR                  U5        UR                  USU-   5        g )Nri   r^   tradesLimitr   r   )
rj   rK   safe_symbolr<   r   r-   r   parse_ws_trader   rn   )	r2   r7   rM   ri   ro   r^   rw   r   r   s	            r4   rG   arkham.handle_tradesB  s     ~~gv.##D(3!!(+++%%%dllM4HE",U"3DKK$$T*V$fvy612r6   c                 $    U R                  X5      $ rr   )parse_trade)r2   traderc   s      r4   r   arkham.parse_ws_trade\  r   r6   c           	        #    U R                  5         U R                  5       U R                  U R                  SS5      -   S-  nU R	                  U R                  S0 5      nU R                  US5      nUc  SnSnSnU R                  [        U5      -   UR                  5       -   S-   U-   U-   nU R                  U R                  5      n	U R                  U R                  U5      U	[        R                  S	5      n
SS
SSSU R                  [        U5      U
S.000nU R                  U5        U R!                  U R"                  S   S   5        g g 7f)NrequestExpirationi  r   r   tokenGET /base64r-   headerszapplication/json)zContent-TypeAcceptzArkham-Api-KeyzArkham-ExpireszArkham-Signaturer&   )check_required_credentialsmillisecondsr   r-   rj   rK   apiKeystrupperbase64_to_binarysecrethmacencodehashlibsha256extend_exchange_optionsr7   r,   )r2   rT   expires	wsOptionsauthenticatedrO   bodyStrpathpayloaddecodedSecret	signaturedefaultOptionss               r4   authenticatearkham.authenticate`  sD    '')$$&):):4<<I\^b)ccgkk..tR@	((G< FGDkkCL06<<>ACG$NQXXG 11$++>M		$++g"6w~~W_`I!,>&8.2kk.1'l09$ 
$N ((8KK		%(./+ !s   EEc                    #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SS0nSnU R                  USU R                  X!5      5      I Sh  vN nU$  NN N8 N
7f)a  
watch balance and get the amount of funds available for trading or funds locked in orders

https://arkm.com/docs#stream/balances

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: spot or contract if not provided self.options['defaultType'] is used
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr   Tr=   )r   rb   rV   rd   )r2   rT   re   rR   r   s        r4   watch_balancearkham.watch_balance|  so      !!!!!!

 !~~k:t{{:?^__ 	"!
 `s1   A+A%A+A'/A+A)A+'A+)A+c                    U R                  US5      n0 nUS:X  a.  U R                  US5      nU R                  U5      nX$S'   X@l        OZU R	                  US5      nU/nU R                  U5      nU R                  US5      nU R                  U5      nXH   U R                  U'   Sn	UR                  U R                  U R                  5      U	5        g )Nr   r   ri   infor^   r=   )rK   	safe_listparse_ws_balancebalancerj   safe_currency_codern   safe_balance)
r2   r7   rM   r   r   ri   balancesArray
currencyIdcoderR   s
             r4   rH   arkham.handle_balance  s    r 0:>>'62D**40F$6N!L>>'62D!FM**=9F))$9J**:6D!'DLL t((6Dr6   c                 $    U R                  U5      $ rr   )parse_balance)r2   r   s     r4   r   arkham.parse_ws_balance  s    !!'**r6   symbolsc                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnU R                  U5      (       d(  U R                  U5      nUSSR	                  U5      -   -  n[        5       U l        SS0nU R                  USU R                  Xd5      5      I Sh  vN nU R                  (       a  U$ U R                  U R                  XUS5      $  N N N97f)a  

https://arkm.com/docs#stream/positions

watch all open positions
:param str[] [symbols]: list of unified market symbols
:param int [since]: the earliest time in ms to fetch positions for
:param int [limit]: the maximum number of positions to retrieve
:param dict params: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
Nr>   r{   ,r   FT)r   rb   is_emptymarket_symbolsjoinr   r>   rV   rd   r}   filter_by_symbols_since_limit)r2   r   rv   rw   rT   rR   re   newPositionss           r4   watch_positionsarkham.watch_positions  s      !!!!!!!}}W%%))'2G4#((7"333K13

 "^^KdkkR\Feff??11$..'RWY]^^ 	"! gs2   C'C!C'C#A<C'+C%,6C'#C'%C'c                    / nU R                   c  0 U l         U R                  US5      nUS:X  a  U R                  US/ 5      n[        S[	        U5      5       H_  nU R                  XV   5      nU R                  US5      S:w  d  M.  UR                  U5        U R                  US5      nXpR                   U'   Ma     OTU R                  US5      nU R                  U5      nU R                  US5      nXpR                   U'   UR                  U5        U R                  US5      n	[        S[	        U	5      5       Hk  nX   n
U
R                  S5      nUS	   nUR                  S
5      nU R                  USUS5      nU R                  U5      (       a  MZ  UR                  X5        Mm     [	        U5      nUS:  a  UR                  US5        g g )Nr   r   ri   r   
entryPricer^   zpositions::r{      r   Fr>   )r>   rK   r   rangelenparse_ws_positionr   r   rj   find_message_hashessplitfilter_by_arrayr   rn   )r2   r7   rM   r   r   ri   ipositionr^   messageHashesrR   partssymbolsStringr   r>   lengths                   r4   rI   arkham.handle_positions  s   B >>!DN0:>>'626D1c$i(11$':$$X|<A ''1!--hAF-5NN6* ) >>'62D--d3H%%h9F%-NN6")00Gq#m,-A'*K%%d+E!!HM#))#.G,,\8WeTI==++y6 . \"A:NN<5 r6   r>   c                    U R                  U5      nU R                  U5      n/ n[        S[        U5      5       H8  nU R	                  U R                  X   S 5      U5      nUR                  U5        M:     U R                  USUS5      $ )Nr   r^   F)r   to_arrayr  r  rd   r  r   filter_by_array_positions)r2   r>   r   rT   r   r
  r  s          r4   parse_ws_positionsarkham.parse_ws_positions9  s~    %%g.MM),	q#i.)A{{4#9#9),#MvVHMM(# * --fhOOr6   c                 $    U R                  X5      $ rr   )parse_position)r2   r  rc   s      r4   r  arkham.parse_ws_positionB  s    ""844r6   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnUb  U R                  U5      nSS0nSnU R                  USSS5      u  ptU(       a  SOSnSn	Ub  U	S	US
   -   -  n	U	S	U-   -  n	U R	                  XU R                  Xd5      5      I Sh  vN n
U R                  (       a  U
R                  X5      nU R                  XX#S5      $  N N N=7f)a  
watches information on multiple orders made by the user

https://arkm.com/docs#stream/order_statuses

: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
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   Fr!   triggerr@   r?   ordersr{   r^   T)	r   rb   rc   handle_option_and_paramsrV   rd   r}   r~   filter_by_symbol_since_limit)r2   r^   rv   rw   rT   rc   re   isTriggerOrderrS   rR   r  s              r4   watch_ordersarkham.watch_ordersF  s      !!!!!![[(F

 !%!>!>v}V_af!g)7%=M
4&"222Ktj((~~kt{{:?^__??OOF2E00tTT% 	"! `s2   C,C&C,C(A=C,,C*-:C,(C,*C,c                    U R                  US5      nU R                  US5      nU R                  c-  U R                  U R                  SS5      n[        U5      U l        U R                  nU R                  U5      nUR                  U5        UR                  US5        UR                  USUS   -   S-   U-   5        UR                  USU-   5        g )	NrA   ri   ordersLimitr   r  zorders::r^   r{   )	rK   rj   r  r   r-   r   parse_ws_orderr   rn   )r2   r7   rM   rA   ri   rw   r  orders           r4   rJ   arkham.handle_orderf  s    J ""7I6~~gv.;;%%dllM4HE07DK##D)evx(vzE(O;dBWLMvzG34r6   c                 $    U R                  X5      $ rr   )parse_order)r2   r$  rc   s      r4   r#  arkham.parse_ws_order  r   r6   c                    U R                  US5      nUb  U R                  U5      nU R                  US5      nU R                  S-   U-   nU R                  U R                  S   XV5        U R                  U R                  S   X65        U R                  U R                  S   X65        [        U R                  S-   U-   5      eg)NrM   r`    exactbroadF)rK   jsonr`   throw_exactly_matched_exception
exceptionsthrow_broadly_matched_exceptionr   )r2   r7   responserM   body	errorCodefeedbacks          r4   rC   arkham.handle_error_message  s     ""8Y799X&D((48Iww}t+H001I9_001I7]001I7]# 455r6   )r   r  r>   rr   )1__name__
__module____qualname____firstlineno__r   r1   r   rP   r   dictrV   r   rf   rD   rl   r
   r   listr   rE   r   r   r   rF   r   r   r   rG   r   r   r   r   rH   r   r   r   r   rI   r  r  r   r   r  rJ   r#  r	   rC   __static_attributes____classcell__)r3   s   @r4   r   r      s]   # @$V $:
`3 
`C 
` 
`RU 
` 68 \ \F \$"4F "4N2 8<$]ajl H HC HWZ Hquvzq{ H6!6 !F/D / @DB !S ! !S\ !*7= 7=r$ <@d[] S SS S Sbfglbm S.3F 34/ )+ 08 *,  &IEV IEV+ 8<$]ajl _W _C _WZ _quv~q _6>6@ MQY[ PDI PS	 P`dem`n P5 04$UYbd U UC Us Uimnsit U@/56 /5b/E /6   r6   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r   ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   async_supportr    r6   r4   <module>rG     sH     A  A  m m m m 4  *_
T&& _
r6   