
    E#iY                         S SK rS SKJr  S SKrS SKJrJrJrJ	r	J
r
  S SKJr  S SKJr   " S S\R                  R                   5      rg)    N)
ArrayCache)AnyInt	OrderBookTickerTrade)Client)Listc                   (  ^  \ rS rSrS\4U 4S jjrS r0 4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S\
4S jrSS	S	0 4S\S\S
\S\S\\   4
S jjrS\
4S jrS	0 4S\S\S\4S jjrS\
4S jrS\
4S jrS\
4S jrS\
4S jrSrU =r$ )ndax   returnc           
      j   > U R                  [        [        U ]  5       SSSSSSS.SS0SS0S.S.5      $ )	NTF)wswatchOrderBookwatchTradeswatchTradesForSymbolswatchTicker
watchOHLCVr   z7wss://ndaxmarginstaging.cdnhop.net:10456/WSAdminGatewa/zwss://api.ndax.io/WSGateway)testapi)hasurls)deep_extendsuperr   describe)self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/ndax.pyr   ndax.describe   s]    dD : <"&#).#" S 7	?
  	    c                 |    U R                  U R                  U R                  SS5      S5      nXR                  S'   U$ )N	requestIdr      )sumsafe_integeroptions)r   r#   s     r   
request_idndax.request_id)   s7    HHT..t||[!LaP	$-[!r!   symbolc                   #    U R                  U R                  SS5      nU R                  5       I Sh  vN   U R                  U5      nSnUS-   US   -   nU R                  S   S   nU R                  5       nU[        US   5      S	.n	S
UUU R                  U	5      S.n
U R                  X5      nU R                  XvX5      I Sh  vN $  N 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://apidoc.ndax.io/#subscribelevel1

: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>`
omsIdr$   NSubscribeLevel1:idr   r   )OMSIdInstrumentIdr   mino)
r&   r'   load_marketsmarketr   r(   intjsonextendwatch)r   r*   paramsr,   r8   namemessageHashurlr#   payloadrequestmessages               r   watch_tickerndax.watch_ticker.   s      !!$,,;!!!V$ Sj6$</iit$OO%	t-
 7#	
 ++g.ZZ'GGG% 	"$ Hs"   1CC
BCCCCclientc                     U R                  US0 5      nU R                  U5      nUS   nU R                  U5      nX@R                  U'   SnUS-   US   -   nUR	                  XH5        g )Nr6   r*   r-   r.   r/   )
safe_valueparse_tickerr8   tickersresolve)	r   rF   rC   rA   tickerr*   r8   r>   r?   s	            r   handle_tickerndax.handle_tickerM   sm    //'334 ""7+!V$%V Sj6$</v+r!   Nsincelimitc                   #    U R                  U R                  SS5      nU R                  5       I Sh  vN   U R                  U5      nUS   nSnUS-   US   -   nU R                  S   S	   n	U R                  5       n
U[        US   5      S
S.nSU
UU R                  U5      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                  XUSS5      $  N N<7f)a  
get the list of most recent trades for a particular symbol

https://apidoc.ndax.io/#subscribetrades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r,   r$   Nr*   SubscribeTradesr.   r/   r   r   d   )r0   r1   IncludeLastCountr   r2   	timestampT)r&   r'   r7   r8   r   r(   r9   r:   r;   r<   
newUpdatesgetLimitfilter_by_since_limit)r   r*   rO   rP   r=   r,   r8   r>   r?   r@   r#   rA   rB   rC   tradess                  r   watch_tradesndax.watch_tradesp   s     !!$,,;!!!V$! Sj6$</iit$OO%	t- #
 7#	
 ++g.zz#GII??OOF2E))&TRR- 	"& Js"   1D
DBD
D;D
D
c                 r   U R                  US/ 5      nSn0 n[        S[        U5      5       H  nU R                  X6   5      nUS   nU R                  U R                  U5      n	U	c(  U R                  U R                  SS5      n
[        U
5      n	U	R                  U5        XR                  U'   SXX'   M     [        UR                  5       5      n[        S[        U5      5       HP  nX   nU R                  U5      nUS-   US	   -   nU R                  U R                  U5      n	UR                  X5        MR     g )
Nr6   rR   r   r*   tradesLimit  Tr.   r/   )rH   rangelenparse_traderY   r&   r'   r   appendlistkeysr8   rK   )r   rF   rC   rA   r>   updatesr4   trader*   tradesArrayrP   symbolsr8   r?   s                 r   handle_tradesndax.handle_trades   s   //'33( !q#g,'A$$WZ0E8_F//$++v>K"))$,,tL(/u%"-KK"GO ( w||~&q#g,'AZF[[(F*vd|3K//$++v>KNN;4 (r!   1m	timeframec           	      l  #    U R                  U R                  SS5      nU R                  5       I Sh  vN   U R                  U5      nUS   nSnUS-   U-   S-   US   -   n	U R                  S   S	   n
U R                  5       nU[        US   5      [        U R                  U R                  X"5      5      S
S.nSUUU R                  U5      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                  XUSS5      $  N N<7f)a;  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://apidoc.ndax.io/#subscribeticker

: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
r,   r$   Nr*   SubscribeTickerr.   r/   r   r   rS   )r0   r1   IntervalrT   r   r2   T)r&   r'   r7   r8   r   r(   r9   safe_string
timeframesr:   r;   r<   rV   rW   rX   )r   r*   rl   rO   rP   r=   r,   r8   r>   r?   r@   r#   rA   rB   rC   ohlcvs                   r   watch_ohlcvndax.watch_ohlcv   s3     !!$,,;!!!V$! Sj9,s2VD\Aiit$OO%	t-D,,T__iST #	
 7#	
 ++g.jj7HH??NN61E))%q$GG/ 	"( Is"   1D4D0CD45D26;D42D4c                    U R                  US/ 5      n0 n[        S[        U5      5       GHf  nX5   nU R                  US5      nU R	                  U5      nUS   n	0 XG'   U R                  U R
                  U	0 5      U R
                  U	'   [        U R                  R                  5       5      n
[        S[        U
5      5       GH  nX   nU R                  U R                  X5      n[        U5      S-  nU R                  US5      nU R                  X-  U-  5      U R                  US5      U R                  US5      U R                  US5      U R                  US	5      U R                  US
5      /nU R                  U R
                  U	   U/ 5      n[        U5      nU(       ao  US   UUS-
     S   :X  a]  UUS-
     nUS   US   [        US   US   5      [        US   US   5      US	   U R                  US
   US
   5      /UUS-
  '   SXG   U'   OhU(       a  US   UUS-
     S   :  a  GMm  UR!                  U5        U R                  U R"                  SS5      nUU:  a  UR%                  S5        SXG   U'   UU R
                  U	   U'   GM     GMi     Sn[        UR                  5       5      n[        S[        U5      5       H  nUU   n[        XG   R                  5       5      n[        S[        U5      5       H^  nUU   nUS-   U-   S-   U-   nU R	                  U5      nUS   n	U R                  U R
                  U	   U/ 5      nUR'                  UU5        M`     M     g )Nr6   r      r*   r^      r$            T
OHLCVLimitrn   r.   )rH   r_   r`   rp   safe_marketohlcvsrc   rq   rd   r9   r&   parse_to_int
safe_floatmaxminr%   rb   r'   poprK   )r   rF   rC   rA   re   r4   rr   marketIdr8   r*   rd   jrl   intervaldurationrU   parsedstoredlengthpreviousrP   r>   	marketIdsrq   r?   s                            r   handle_ohlcvndax.handle_ohlcv   sQ    //'33" q#g,'AJE''q1H%%h/FH%F "G"&//$++vr"JDKK,,./D1c$i( G	++DOOYRx=4/ --eQ7	%%y';x&GHOOE1-OOE1-OOE1-OOE1-OOE1- V)<iLVvayF6A:,>q,AA%fqj1Hq	 F1Ix{3F1Ix{3q	HQK8*F6A:& 48G%i06!9vfqj/A!/D#D f- $ 1 1$,,d S!U?"JJqM7;))417F#I.G ) (X !(	q#i.)A |Hg/4467J1c*o.&qM	"Sj94s:XE))(3)V)<iLv{3 / *r!   c           	        #    U R                  U R                  SS5      nU R                  5       I Sh  vN   U R                  U5      nUS   nSnUS-   US   -   nU R                  S   S	   nU R                  5       n	Uc  S
OUnU[        US   5      US.n
SU	UU R                  U
5      S.nU	UUUUS   U R                  UUS.nU R                  X5      nU R                  XXU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://apidoc.ndax.io/#subscribelevel2

: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
r,   r$   Nr*   SubscribeLevel2r.   r/   r   r   rS   )r0   r1   Depthr   r2   )r/   r?   r>   r*   r   methodrP   r=   )r&   r'   r7   r8   r   r(   r9   r:   handle_order_book_subscriptionr;   r<   rP   )r   r*   rP   r=   r,   r8   r>   r?   r@   r#   rA   rB   subscriptionrC   	orderbooks                  r   watch_order_bookndax.watch_order_book9  s*     !!$,,;!!!V$! Sj6$</iit$OO%	Et-	
 7#	
 &t99	
 ++g.**Sw\ZZ	  A 	"> [s"   1DD B7D+D,DDc                    U R                  US/ 5      nU R                  US/ 5      nU R                  US5      nUc  g U R                  U5      nUS   nU R                  U R                  U5      nUc  g S n	S n
[	        S[        U5      5       GH  nX;   nU	c  U R                  US5      n	OU R                  US5      n[        X5      n	U
c  U R                  US5      n
OU R                  US5      n[        X5      n
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S:X  a  US
   OUS   nUS:X  a  UR                  UU5        M  US:X  a  UR                  UU5        M  US:X  d  GM  UR                  US5        GM     XS'   XS'   U R                  U	5      US'   SnUS-   U-   nXR                  U'   UR                  UU5        g )Nr6   r      r*   rx   rw      rv   	   bidsasksr$   noncerU   datetimer   r.   )rH   rp   r|   
orderbooksr_   r`   r&   r   r   storeiso8601rK   )r   rF   rC   rA   firstBidAskr   r8   r*   r   rU   r   r4   bidasknewTimestampnewNoncetypepriceamountsideorderbookSider>   r?   s                         r   handle_order_bookndax.handle_order_bookg  s    //'33 oogq"5##K3!!(+!OODOOV<		q#g,'AZF  --fa8	#00;	8	}))&!4,,VQ7E,$$VQ/DOOFA.E__VQ/F$$VQ/D26!)If-)FBSMqy##E62##E62##E1-3 (4 #'!*+ $Y 7	* Sj8+"+y+.r!   c                    U R                  US/ 5      nU R                  US5      nU R                  XE5      nU R                  US5      nU R	                  Xg5      nXR
                  U'   U R                  US5      n	UR                  X5        g )Nr6   r*   rP   r?   )rH   rp   parse_order_bookr&   
order_bookr   rK   )
r   rF   rC   r   rA   r*   snapshotrP   r   r?   s
             r   r   #ndax.handle_order_book_subscription  s     //'33" !!,9((9!!,8OOH4	"+&&|]Cy.r!   c                     U R                  UR                  S5      nU R                  US5      nU R                  X45      nUb   U R                  US5      nUb
  U" XU5        g g g )Nr/   r4   r   )index_bysubscriptionsr&   rH   )r   rF   rC   subscriptionsByIdr/   r   r   s          r   handle_subscription_statusndax.handle_subscription_status  sl     !MM&*>*>Ew,'8=#__\8<F!v5 " $r!   c           	      v   U R                  US5      nUc  g [        R                  " U5      US'   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 R                  XE5      nUb	  U" X5        g g )Nr6   )r   r-   Level2UpdateEventLevel1UpdateEventrR   TradeDataUpdateEventrn   TickerDataUpdateEventr5   )	rp   r:   loadsr   rM   r   ri   r   rH   )r   rF   rC   rA   methodseventr   s          r   handle_messagendax.handle_message  s    . ""7C0?zz'*#>>#11!%!7!7!%!3!3#11$($6$6#00%)%6%6	
   #.06# r!    )__name__
__module____qualname____firstlineno__r   r   r(   strr   rD   r	   rM   r   r
   r   rZ   ri   rc   rs   r   r   r   r   r   r   r   __static_attributes____classcell__)r   s   @r   r   r      s=   # 2
 68 H HF H>!,F !,F <@d[] #S #SS #S #Sbfglbm #SJ'5F '5R ?CQUdhqs %H %H %H3 %H^a %Hx|  ~B  yC %HNR46 R4h @DB ,!S ,! ,!S\ ,!\C/ C/J /V  /D6 6"($V ($ ($r!   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r:   ccxt.base.typesr   r   r   r   r   !ccxt.async_support.base.ws.clientr	   typingr
   async_supportr   r   r!   r   <module>r      s6     7  > > 4 y$4"" y$r!   