
    !:h                        d dl mZ d dlmZ d dlZd dl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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 d dlmZ d d	lm Z  d d
lm!Z! d dl"m#Z# d dl$m%Z%  G d dee      Z&y)    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddress	IndexTypeIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)AuthenticationError)	BadSymbol)InsufficientFunds)OrderNotFound)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdZi fdefdZi fdee	   fdZ
dede	fdZdId	ed
edefdZdi fdededefdZdJdede	defdZi fdedefdZdJde	defdZdddi fdedededee   fdZdJdede	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e   fdZdefdZi fdefdZ d Z!dJd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#e%fd$Z'dJd%ede	d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ddi fde%dedefd.Z0di fde%fd/Z1di fd,ede%fd0Z2dddi fde%dededee(   fd1Z3dddi fde%dededee(   fd2Z4di fd,ede%fd3Z5dddi fd,ede%dedefd4Z6i fd!ede7fd5Z8dJde"de7fd6Z9i fd!ede7fd7Z:dddi fd!e%dededee;   fd8Z<dddi fd!e%dededee;   fd9Z=dJd:Z>dJd;ede"de;fd<Z?di fd!ed)e,d=ede;fd>Z@d? ZAd@dAi ddfdBZBd!eCdCedDedEedFedGefdHZD xZES )Kndaxreturnc           !         | j                  t        t        |          dddgddi dd dddd	d
d	dd	dd	dd	dddddd	dd	dddddd	ddddddi dddddddd	dd	dd	dd	dd	d d	d!d	d"d	d#dd$dd%d	d&d	d'dd(d	i d)d	d*d	d+d	d,d	d-d	d.d	d/d	d0d	d1d	d2d	d3dd4d	d5d	d6d	d7d	d8d	d9d	i d:d	d;d	d<dd=d	d>d	d?d	d@d	dAddBddCd	dDd	dEddFd	dGd	dHddIddJdi dKddLd	dMd	dNd	dOd	dPd	dQd	dRd	dSd	dTd	dUddVd	dWd	dXddYd	dZd	d[d	d	dd	d	d	dd	d	d	d	dd	dd\d]d^d_d`dadbdcdddedfdgdhdidjdkdldldmdndndmdodpgdqdrdsdti dudvdwdvdxdvdydvdzdvd{dvd|dvd}dvd~dvddvddvddvddvddvddvddvddvdvdvdvdvdvdvdvdvdvd	ii ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvi ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvdvdvdvdvdvdvdvdi ddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvddvdvdvdvdvdvdvdvdvdvd	ddmdd	dd	dd	d	dd	d	d dddd	dd	d	d	d	d	d	ddd d	dddd	dÜd	d	d	d	dĜd	d d	d	d	dŜd	d d d d	d	d	dƜd dd idȜ	d d dɜd d dɜdʜdd	d| j	                  d̫      | j	                  dͫ      dΜiddddddϜt
        t        t        t        dМt        t        dќdҜdvdvdddddddvdddddddٜdڜdۜ      S )Nr!   NDAXCA  TCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchUnderlyingAssets)fetchVolatilityHistoryfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdraw603009001800360072001440021600432008640060480024192009676800)1m5m15m30m1h2h4h6h12h1d1w1M4Mzdhttps://user-images.githubusercontent.com/1294454/108623144-67a3ef00-744e-11eb-8140-75c6b851e945.jpgz,https://ndaxmarginstaging.cdnhop.net:8443/AP)publicprivatezhttps://api.ndax.io:8443/APzhttps://ndax.iozhttps://apidoc.ndax.io/zhttps://ndax.io/feeszhttps://one.ndax.io/bfQiSL)logotestapiwwwdocfeesreferralgetActivate2FA   Authenticate2FAAuthenticateUserGetL2Snapshot	GetLevel1GetValidate2FARequiredEndpointsLogOutGetTickerHistory
GetProductGetProductsGetInstrumentGetInstrumentsPingtradesGetLastTradesSubscribeLevel1SubscribeLevel2)	SubscribeTickerSubscribeTradesSubscribeBlockTradesUnsubscribeBlockTradesUnsubscribeLevel1UnsubscribeLevel2UnsubscribeTickerUnsubscribeTradesAuthenticateGetUserAccountInfosGetUserAccountsGetUserAffiliateCountGetUserAffiliateTagGetUserConfig"GetAllUnredactedUserConfigsForUserGetUnredactedUserConfigByKeyGetUserDevicesGetUserReportTickets GetUserReportWriterResultRecordsGetAccountInfoGetAccountPositionsGetAllAccountConfigsGetTreasuryProductsForAccountGetAccountTradesGetAccountTransactionsGetOpenTradeReportsGetAllOpenTradeReportsGetTradesHistoryGetOpenOrdersGetOpenQuotesGetOrderFeeGetOrderHistoryGetOrdersHistoryGetOrderStatusGetOmsFeeTiersGetAccountDepositTransactionsGetAccountWithdrawTransactions!GetAllDepositRequestInfoTemplatesGetDepositInfoGetDepositRequestInfoTemplateGetDepositsGetDepositTicketGetDepositTickets)GetOMSWithdrawFeesGetWithdrawFeeGetWithdrawsGetWithdrawTemplateGetWithdrawTemplateTypesGetWithdrawTicketGetWithdrawTicketsAddUserAffiliateTagCancelUserReportRegisterNewDeviceSubscribeAccountEventsUpdateUserAffiliateTagGenerateTradeActivityReport!GenerateTransactionActivityReportGenerateTreasuryActivityReportScheduleTradeActivityReport!ScheduleTransactionActivityReportScheduleTreasuryActivityReportCancelAllOrdersCancelOrderCancelQuoteCancelReplaceOrderCreateQuoteModifyOrder)		SendOrderSubmitBlockTradeUpdateQuoteCancelWithdrawCreateDepositTicketCreateWithdrawTicketSubmitDepositTicketCommentSubmitWithdrawTicketCommentGetOrderHistoryByOrderId)r   post)lastmarkindex)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   i )r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r&  )r  r#  r'  r  r&  )r  r#  r$  r%  r'  r  r&  r#  )	r   r3   createOrdersra   rh   re   rj   fetchClosedOrdersrb   )linearinverse)r(   r*   r+   tradingz0.002z0.0025)	tierBased
percentagemakertaker)apiKeysecretuidloginpassword)Not_Enough_FundszServer ErrorzResource Not Found)zInvalid InstrumentIdz5This endpoint requires 2FACode along with the payload)exactbroad                  )r   Limit
StopMarket	StopLimitTrailingStopMarketTrailingStopLimit
BlockTrade1234567)omsId
orderTypes)idname	countries	rateLimitprohas
timeframesurlsr   featuresr   requiredCredentialsprecisionMode
exceptionsoptions)deep_extendsuperr!   describeparse_numberr   r   r   r   r   r   )self	__class__s    C/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/ndax.pyr]  zndax.describe   s
   dD : <ccc %c 	c
 %c %c Uc "4c tc $Uc  c 'c tc (c 'c  (!c" "4#c$ T%c&  'c( )c* &u+c, "5-c. +E/c0 )%1c2 #E3c4 ,U5c6 '7c8 (9c: "4;c< &t=c> (?c@ 1%AcB  CcD &uEcF 'GcH (IcJ #EKcL *5McN $UOcP uQcR "5ScT *5UcV +EWcX )%YcZ t[c\  ]c^ !%_c` %eacb $Uccd /ecf "5gch #Eicj +Ekcl mcn !%ocp "5qcr &usct +Eucv  wcx dycz $U{c| +E}c~ "4c@ uAcB #ECcD dEcF !$GcH tIcJ #DKcL  McN 'OcP $UQcR !%ScT *5UcV (WcX %eYcZ )%[c\ )%]c^ t_c` acb Uccd tecf "5gch #Eicj (kcl +0$( %$)',$"!&#(! EcJ   LM
 << )- /8&  %q)1 +A (	
 $Q :1 !! +A %a &q ( )!  !! (  *1!" *1#$ ,-+,0123-.-.-.-.()5>*-q*)1* 0* .q	*
 (* =a* 7* )!* /* ;A* )!* .q* /* 8* +A*  1!!*" .q#*$ 1!%*& +A'*( ()** (+*, &q-*. *1/*0 +A1*2 )!3*4 )!5*6 87*8 9!9*: <Q;*< )!=*> 8?*@ &qA*B +AC*D ,QE*F /0*+()/045-../S*V-q*A ,Q 1!	
 1! 6q <Q 9! 6q <Q 9! *1 &q &q -a  &q!" &q#$ &',-'(*+/0016778455YH?hV  $&+(,,1$($)%*- */+06: $(#'"&#(	( #($)$)+027/4#'5$8 %)&+!$$*%+*/& ',#($)*/	# ',!%#($)*/( ',!%$(%)#($)*/$ *.#{@D ##
 ##MJX !&"&!..w7!..x8	  $ ' ):$1*7 -6M`
 "#!"*+)*"#w
n?
 n n	    c                 j   | j                          | j                  | j                  t        | j                  dz         ddi}| j                  | j                  ||            }| j                  |d      }||| j                  d<   |S | j                  |d      }|| j                  t        | j                  dz         || j                  d<   d	| j                  | j                        i}| j                  | j                  ||            }| j                  |d      }|| j                  d<   |S |S )
a  
        sign in, must be called prior to using other authenticated methods

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns: response from exchange
        z4 signIn() requires exchange.login, exchange.password
grant_typeclient_credentialsSessionTokensessionTokenPending2FaTokenz- signIn() requires exchange.twofa credentialspending2faTokenCode)check_required_credentialsr4  r5  r   rN  publicGetAuthenticateextendsafe_stringrZ  twofatotppublicGetAuthenticate2FA)r_  paramsrequestresponserg  ri  responseInners          ra  sign_inzndax.sign_in  s9    	'')::!6%dgg0f&fgg.
 --dkk'6.JK ''.A#+7DLL(O**85FG&zz!)$''4c*cdd.=DLL*+		$**-G !99$++gv:VWM  ++M>JL+7DLL(  rb  c                    | j                  | j                  dd      }d|i}| j                  | j                  ||            }i }t	        dt        |            D ]  }||   }| j                  |d      }| j                  | j                  |d            }	| j                  |d      }
|
dk(  rdnd	}|
d
k(  rd}| j                  || j                  |d      |	|| j                  |d      || j                  |d       | j                  |d      | j                  |d      ddddddddi | j                  |d      d      ||	<    |S )a  
        fetches all available currencies on an exchange

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        rL  r   r   	ProductIdProductProductTypeNationalCurrencyfiatcryptoUnknownotherProductFullNameTickSize
IsDisabledDepositEnabledWithdrawEnabledNminmax)amountr   MarginEnabled)rN  rO  codetype	precisioninfoactivedepositr   feelimitsnetworksr)   )safe_integerrZ  publicGetGetProductsrm  rangelenrn  safe_currency_codesafe_currency_structuresafe_number	safe_bool)r_  rr  rL  rs  rt  resulticurrencyrN  r  rz  r  s               ra  fetch_currencieszndax.fetch_currencies  s~    !!$,,;U
 ,,T[[&-IJ( q#h-(  	A{H!!(K8B**4+;+;Hi+PQD**8]CK)-??6hDi'77((3DE!--h
C "nnX|DD>>(4DE NN85FG  $#
  $#!	 ..?C-9 F4L 	B rb  c                     | j                  | j                  dd      }d|i}| j                  | j                  ||            }| j	                  |      S )a  
        retrieves data on all markets for ndax

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        rL  r   )r  rZ  publicGetGetInstrumentsrm  parse_markets)r_  rr  rL  rs  rt  s        ra  fetch_marketszndax.fetch_markets  sY     !!$,,;U
 //GV0LM^ !!(++rb  marketc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  | j                  |d            }| j                  |d      }| j                  |d      }|dk(  }	i d	|d
|dz   |z   d|d|dd d|d|dd ddddddddddddd|	xr | dddd d d d d d d | j                  |d      | j                  |d      dd d d | j                  |d!      d d | j                  |d"      d d d d d d#d |d$
S )%NInstrumentIdProduct1Product2Product1SymbolProduct2SymbolSessionStatus	IsDisableRunningrN  symbol/basequotesettlebaseIdquoteIdsettleIdr  r(   Tr)   Fr*   r+   r,   r  contractr*  QuantityIncrementPriceIncrement)r  pricer  MinimumQuantityMinimumPrice)r  r  r  cost)
r+  contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )rn  r  
safe_valuer  )
r_  r  rN  r  r  r  r  sessionStatus	isDisablesessionRunnings
             ra  parse_marketzndax.parse_market=  s   fn5!!&*5""6:6&&t'7'7@P'QR''(8(8AQ(RS((AOOFK8	'940
"0
dSj5(0
 D0
 U	0

 d0
 f0
 w0
 0
 F0
 D0
 e0
 E0
 e0
 e0
 ~7i-0
  !0
" d#0
$  "**63FG))&2BC  
  ++F4EF
  ++FNC
  $ _0
 0	
rb  NpriceKey	amountKeycountOrIdKeyc	                 F   d }	|g g d d d d}
t        dt        |            D ]  }||   }|| j                  |d      }n| j                  |d      }t        ||      }|	| j                  |d      }	n| j                  |d      }t        |	|      }	| j	                  |||      }| j                  |d      }|r|n|}|
|   }|j                  |        | j                  |
d   dd      |
d<   | j                  |
d   d      |
d<   ||
d<   | j                  |      |
d	<   |	|
d
<   |
S )N)r  bidsasks	timestampdatetimenoncer   r9  	   r  Tr  r  r  r  )r  r  r  r  parse_bid_askappendsort_byiso8601)r_  	orderbookr  r  bidsKeyasksKeyr  r  r  r  r  r  levelnewTimestampnewNoncebidask	levelSideside
resultSides                      ra  parse_order_bookzndax.parse_order_booky  sU   
 q#i.) 	&AaLE  --eQ7	#00:	<8	}))%3,,UA6E8,''xCF))%3I'7WDJf%!	&" fVna>vfVna8v'{!\\)4zwrb  r  r#  c                    | j                  | j                  dd      }| j                          | j                  |      }|dn|}||d   |d}| j	                  | j                  ||            }| j                  ||      S )a#  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

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

        :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
        rL  r   r"  rN  )rL  r  Depth)r  rZ  load_marketsr  publicGetGetL2Snapshotrm  r  )r_  r  r#  rr  rL  r  rs  rt  s           ra  fetch_order_bookzndax.fetch_order_book  s     !!$,,;V$E"4L

 ..t{{7F/KL. $$Xv66rb  tickerc                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j	                  i d	|d
|d| j                  |      d| j                  |d      d| j                  |d      d| j                  |d      dd d| j                  |d      dd dd d|	d|d|dd d|d|dd |
||d|      S )N	TimeStampr  LastTradedPxRolling24HrPxChangePercentRolling24HrPxChangeSessionOpenRolling24HrVolumeRolling24HrNotionalr  r  r  highSessionHighlow
SessionLowbidBestBid	bidVolumeask	BestOffer	askVolumevwapopencloser  previousClosechanger.  average)
baseVolumequoteVolumer  )r  rn  safe_marketsafe_symbolsafe_tickerr  )r_  r  r  r  marketIdr  r  r.  r  r  r  r  s               ra  parse_tickerzndax.parse_ticker  s   B %%fk:	##FN;!!(F3!!(F37%%f.JK
!!&*?@6%%f.AB
&&v/DE !
f!
!
 Y/!
 D$$V];	!

 4##FL9!
 4##FI6!
 !
 4##FK8!
 !
 D!
 D!
 T!
 D!
 T!
 f!
  *!!
" t#!
$ %&)!
* + 	rb  c                     | j                  | j                  dd      }| j                          | j                  |      }||d   d}| j	                  | j                  ||            }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

        :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>`
        rL  r   rN  rL  r  )r  rZ  r  r  publicGetGetLevel1rm  r  )r_  r  rr  rL  r  rs  rt  s          ra  fetch_tickerzndax.fetch_ticker
  sy     !!$,,;V$"4L
 **4;;w+GH>   622rb  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r:  r   r9  r;  r<  )r  r  )r_  ohlcvr  s      ra  parse_ohlcvzndax.parse_ohlcv<  sn     eQ'UA&UA&UA&UA&UA&
 	
rb  r   sincec                    | j                  | j                  dd      }| j                          | j                  |      }||d   | j	                  | j
                  ||      d}| j                  |      }	| j                         }
|4|| j                  |
|	|z  dz  z
        |d<   | j                  |
      |d<   nU| j                  |      |d<   || j                  |
      |d<   n*| j                  | j                  ||	|z  dz              |d<   | j                  | j                  ||            }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

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

        :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
        rL  r   rN  )rL  r  Intervalr&   FromDateToDate)r  rZ  r  r  rn  rT  parse_timeframemillisecondsymdhmssumpublicGetGetTickerHistoryrm  parse_ohlcvs)r_  r  	timeframer  r#  rr  rL  r  rs  durationnowrt  s               ra  fetch_ohlcvzndax.fetch_ohlcvS  sG    !!$,,;V$"4L(()YO

 ''	2!= &*kk#58H48O2O&P
#$(KK$4!"&++e"4GJ}$(KK$4!$(KK5@PSW@W0X$Y!11$++gv2NO   69eUKKrb  tradec                    d }d }d }d }d }d }d }	d }
d }d }d }t        |t              r| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |d      }|rdnd}	| j                  |d	      }
n| j                  |d
d      }| j                  |d      }| j                  |dd      }
| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }	| j                  |d      }| j                  |d      }|(| j                  |d      }| j                  |      }||d}| j                  ||      }| j                  ||||| j                  |      |
||	|||||d|      S )Nr:  r9  r=  r   r      sellbuyr;  TradeTimeMSReceiveTimeTradeIdOrderIdOrigOrderIdr  
InstrumentPriceQuantityValueGrossValueExecuted
MakerTakerSider   FeeFeeProductId)r  r  )r  rN  r  r  r  orderr  r  takerOrMakerr  r  r  r  )
isinstancelistrn  r  r  safe_integer_2safe_string_2safe_string_lowerr  r  
safe_trader  )r_  r  r  priceStringamountString
costStringr  rN  r  r  orderIdr/  r  r  	takerSidefeeCostStringfeeCurrencyIdfeeCurrencyCoder  s                      ra  parse_tradezndax.parse_trade~  s.   Z 
	eT"**5!4K++E15L))%3I!!%+B''q1Hq1I&6ED&&ua0G++E=-PI!!%3B((	=IG))%NH**5':K++E:>L++E7<PQJ11%FL))%8D))%=D ,,UE:M( $ 0 0 G"&"9"9-"H) / !!(F3"Y/( " 
  	rb  c                    | j                  | j                  dd      }| j                          | j                  |      }||d   d}|||d<   | j	                  | j                  ||            }| j                  ||||      S )a  
        get the list of most recent trades for a particular symbol
        :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 Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        rL  r   rN  r  Count)r  rZ  r  r  publicGetGetLastTradesrm  parse_trades)	r_  r  r  r#  rr  rL  r  rs  rt  s	            ra  fetch_tradeszndax.fetch_trades#  s     !!$,,;V$"4L
 $GG..t{{7F/KL   65%@@rb  c                    | j                   st        | j                  dz         | j                  | j                  dd      }| j                          || j                  | j                   d}| j                  | j                  ||            }g }t        dt        |            D ]*  }| j                  ||      }|j                  |dd|d       , |S )aQ  
        fetch all the accounts associated with a profile

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        z9 fetchAccounts() requires exchange.login email credentialrL  r   )rL  UserIdUserNamer   N)rN  r  r  r  )r4  r   rN  r  rZ  rk  r3  privateGetGetUserAccountsrm  r  r  rn  r  )r_  rr  rL  rs  rt  r  r  	accountIds           ra  fetch_accountszndax.fetch_accounts?  s     zz%dgg0k&kll!!$,,;'')hh



 11$++gv2NO q#h-( 	A((15IMM !	 	 rb  c                 P   |d d d}t        dt        |            D ]x  }||   }| j                  |d      }|| j                  v s)| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   z | j                  |      S )N)r  r  r  r   rx  AmounttotalHoldused)r  r  rn  currencies_by_idr  accountsafe_balance)r_  rt  r  r  balance
currencyIdr  rP  s           ra  parse_balancezndax.parse_balance`  s    

 q#h-( 	'AqkG))';?JT222..z:,,.#'#3#3GX#F "&"2"27F"C&t	'   ((rb  c                    | j                  | j                  dd      }| j                          | j                          | j	                  | j                  dd      }| j	                  |dd|      }|t        | j                  d   d         }| j                  |ddg      }||d}| j                  | j                  ||            }| j                  |      S )aW  
        query for balance and get the amount of funds available for trading or funds locked in orders

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        rL  r   rH  	AccountIdr   rN  rL  rV  )r  rZ  r  load_accountsr2  intaccountsomitprivateGetGetAccountPositionsrm  rT  )r_  rr  rL  defaultAccountIdrH  rs  rt  s          ra  fetch_balancezndax.fetch_balanceq  s     !!$,,;..t||[+V''[JZ[	DMM!,T23I6K#=>"
 55dkk'66RS@ !!(++rb  c                 H    dddddddddddddd}| j                  |||      S )Nr  transactionr   )r   DepositWithdrawTransfer	OrderHoldWithdrawHoldDepositHold
MarginHold
ManualHoldManualEntryMarginAcquisitionMarginRelinquishMarginQuoteHoldrn  )r_  r  typess      ra  parse_ledger_entry_typezndax.parse_ledger_entry_type  sG    $%" )(!!"!( '&
 tT22rb  itemr  c                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }d }d }t        j                  |d      r|}d}nt        j                  |d      r|}d}d }| j                  |d      }	|dk(  rt        j                  |	|      }n/|dk(  r*t        j
                  dt        j                  |	|            }| j                  |d      }
| j                  || j                  |d	      || j                  |d
      | j                  |d      | j                  |d      | j                  | j                  |d            | j                  ||      | j                  |      | j                  |      | j                  |	      d|
| j                  |
      d d|      S )Nrx  CRDR0inoutBalancer  TransactionIdrV  ReferenceIdCounterpartyReferenceTypeok)r  rN  	directionrP  referenceIdreferenceAccountr  r  r  beforeafterstatusr  r  r  )rn  safe_currencyr   	string_lt
string_add
string_max
string_subr  safe_ledger_entryro  r  r^  r  )r_  rp  r  rS  creditdebitr  r}  r  r  r  s              ra  parse_ledger_entryzndax.parse_ledger_entry  s   " %%dK8
%%j(;!!$-  t,	VS)FIuc*FI  y1''v6F$''W-?-?v-NOF%%dK8	%%""49"''k:++D-@ $ 0 0~ F001A1A$1XY//
HE''/''/&&u-"Y/'
  ! 	rb  r  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }||d}|||d	<   | j                  | j                  ||            }	d}
|| j                  |      }
| j                  |	|
||      S )
aJ  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        rL  r   rH  rV  r   rN  rW  Nr  )r  rZ  r  rX  r2  rY  rZ  r[   privateGetGetAccountTransactionsrm  r  parse_ledger)r_  r  r  r#  rr  rL  r]  rH  rs  rt  r  s              ra  fetch_ledgerzndax.fetch_ledger  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>"
 $GG88Wf9UV& }}T*H  8UEBBrb  r  c                 :    ddddddd}| j                  |||      S )Nr  rejectedcanceledexpiredclosed)AcceptedRejectedWorkingCanceledExpiredFullyExecutedrm  )r_  r  statusess      ra  parse_order_statuszndax.parse_order_status   s2    "" %
 &&99rb  r.  c                    | j                  |d      }| j                  |d      }| j                  i d| j                  |dd      d| j                  |dd      d	|d
|d| j	                  |      d| j                  |d      d| j                  | j                  |d            d| j                  ||      d| j                  |d      dd dd d| j                  |d      d| j                  |d      d| j                  | j                  | j                  |d                  d| j                  |d      d| j                  |d      d| j                  |d       | j                  |d!      d d d d"|      S )#Nr!  r%  rN  ReplacementOrderIdr#  clientOrderIdReplacementClOrdIdClientOrderIdr  r  r  lastTradeTimestampLastUpdatedTimer  
OrderStater  r  r   r  postOnlyr  r+  r  r&  r  	StopPricer  r)  r  OrigQuantityfilledQuantityExecutedAvgPrice)r  	remainingr  r   )
r  rn  
safe_orderr3  r  r  r  r4  r^  	omit_zero)r_  r.  r  r  r  s        ra  parse_orderzndax.parse_order+  s   H %%e];	##E<8  
$$$U,@)L 
T//7K_] 
 E 
 	 

 Y/ 
 !$"3"3E;L"M 
 d--d.>.>ul.ST 
 d&&x8 
 D**5+> 
 4 
  
 D**5&9 
 T%%eW5 
 D--dnnT=M=MeU`=a.bc 
 D$$U,@A 
  d&&un=! 
" d&&u.@A# 
$ ''z:+ 
, - 	rb  r  r  r  r  c                 V   | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }	| j	                  |dd      }
| j                  | j                  d	   | j                  |            }| j                  |d
      }||dk(  rd}n|dk(  rd}| j                  |g d      }| j                  |      }|dk(  rdnd}t        |d         ||	d|t        | j                  ||            |d}|t        | j                  ||            |d<   |
|
|d<   |||d<   | j                  | j                  ||            }| j!                  ||      S )a2  
        create a trade order

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

        :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 float [params.triggerPrice]: the price at which a trigger order would be triggered
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r   rH  rV  r   rN  r  r  rM  r  r  r:  r#  r;  )rH  rV  r  r  r  r  )r  rL  rV  TimeInForcer+  r'  r   
LimitPricer  )r  rZ  r  rX  r2  rY  rZ  
capitalizern  r[  r  floatamount_to_precisionprice_to_precisionprivatePostSendOrderrm  r  )r_  r  r  r  r  r  rr  rL  r]  rH  r  	orderTyper  r  	orderSiders  rt  s                    ra  create_orderzndax.create_order  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	++FO_U%%dll<&@$//RVBWX	''?#x		6#opV$%-Aa	t-" d66vvFG"
& $)$*A*A&%*P$QGL!$'4GO$##/GK ,,T[[&-IJ &11rb  rN  c                    | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }	| j	                  |dd|	      }
| j	                  |dd      }| j                  |g d	      }| j                  |      }|d
k(  rdnd}t        |      t        |d         ||
d|t        | j                  ||            | j                  | j                  d   | j                  |            d}|t        | j                  ||            |d<   |||d<   | j                  | j                  ||            }| j                  ||      S )NrL  r   rH  rV  r   rN  r  r  )rH  rV  r  r  r  rM  )OrderIdToReplacer  rL  rV  r  r+  r'  r   r  )r  rZ  r  rX  r2  rY  rZ  r[  r  r  r  r  r  privatePostCancelReplaceOrderrm  r  )r_  rN  r  r  r  r  r  rr  rL  r]  rH  r  r  r  rs  rt  s                   ra  
edit_orderzndax.edit_order  s   !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	++FO_U6#_`V$%-Aa	 #Bt-" d66vvFG**4<<+EtW[G\]
( $)$*A*A&%*P$QGL!$'4GO$55dkk'66RS &11rb  c           	      (   | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }||d}d}	|| j                  |      }	|	d   |d	<   || j                  |d
z        |d<   |||d<   | j                  | j                  ||            }
| j                  |
|	||      S )a  
        fetch all trades made by the user

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        rL  r   rH  rV  r   rN  rW  Nr  r&   StartTimeStampr  )r  rZ  r  rX  r2  rY  rZ  r[  r  parse_to_intprivateGetGetTradesHistoryrm  rB  r_  r  r  r#  rr  rL  r]  rH  rs  r  rt  s              ra  fetch_my_tradeszndax.fetch_my_trades  s/    !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>"
 [[(F&,TlGN#(,(9(9%$,(GG$%$GG224;;w3OPX   65%@@rb  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }||d}|| j                  |      }|d   |d<   | j                  | j                  ||            }| j                  d	|i      gS )
a  
        cancel all open orders

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

        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :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>`
        rL  r   rH  rV  r   rN  rW  IntrumentIdr  )r  rZ  r  rX  r2  rY  rZ  r[  r  privatePostCancelAllOrdersrm  r  )	r_  r  rr  rL  r]  rH  rs  r  rt  s	            ra  cancel_all_orderszndax.cancel_all_ordersN  s    !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>"
 [[(F%+D\GM"224;;w3OP OO 
 	
rb  c                    | j                  | j                  dd      }| j                          | j                          d}|| j	                  |      }d|i}| j                  |dd      }|||d<   nt        |      |d<   | j                  |ddg      }| j                  | j                  ||            }| j                  ||      }	| j                  |	||d      S )a  
        cancels an open order

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

        :param str id: order id
        :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]: a unique id for the order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r   Nr  	ClOrderIdr#  )rN  r  )r  rZ  r  rX  r  r2  rY  r[  privatePostCancelOrderrm  r  )
r_  rN  r  rr  rL  r  rs  r  rt  r.  s
             ra  cancel_orderzndax.cancel_ordert  s     !!$,,; [[(FU
 ++FO[Q$#0GK !$RGI6O[#AB..t{{7F/KL  62{{5*#
  	rb  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }d}|| j                  |      }||d}	| j                  | j                  |	|            }
| j                  |
|||      S )	a  
        fetch all unfilled currently open orders

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

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r   rH  rV  r   rN  NrW  )r  rZ  r  rX  r2  rY  rZ  r[  r  privateGetGetOpenOrdersrm  parse_orders)r_  r  r  r#  rr  rL  r]  rH  r  rs  rt  s              ra  fetch_open_orderszndax.fetch_open_orders  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>[[(F"
 //GV0LMf   65%@@rb  c           	      (   | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }||d}d}	|| j                  |      }	|	d   |d	<   || j                  |d
z        |d<   |||d<   | j                  | j                  ||            }
| j                  |
|	||      S )a  
        fetches information on multiple orders made by the user

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

        :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 Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r   rH  rV  r   rN  rW  Nr  r&   r  r  )r  rZ  r  rX  r2  rY  rZ  r[  r  r  privateGetGetOrdersHistoryrm  r  r  s              ra  fetch_orderszndax.fetch_orders  s/    !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>"
 [[(F&,TlGN#(,(9(9%$,(GG$%$GG224;;w3OPf   65%@@rb  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }d}|| j                  |      }||t        |      d}| j                  | j                  ||            }	| j                  |	|      S )	a  
        fetches information on an order made by the user

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

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rL  r   rH  rV  r   rN  N)rL  rV  r#  )r  rZ  r  rX  r2  rY  rZ  r[  r  privateGetGetOrderStatusrm  r  )
r_  rN  r  rr  rL  r]  rH  r  rs  rt  s
             ra  fetch_orderzndax.fetch_orderD  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>[[(F"2w

 00Wf1MNb &11rb  c                    | j                  | j                  dd      }| j                          | j                          d}|| j	                  |      }| j                  |      t        |      d}| j                  | j                  ||            }	| j                  |	d      }
| j                  |
dg       }| j                  ||||      S )a  
        fetch all the trades made from a single order

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

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades 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>`
        rL  r   N)OMSIdr#  ChangeReasonr   )r  rZ  r  rX  r  r  rY  #privatePostGetOrderHistoryByOrderIdrm  group_by	safe_listrB  )r_  rN  r  r  r#  rr  rL  r  rs  rt  groupedr   s               ra  fetch_order_tradeszndax.fetch_order_trades  s     !!$,,; [[(F&&u-2w

 ;;DKKQW<XYf --.9"5  >>rb  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }| j                  |      }|||d   dd}| j                  | j                  ||            }| j                  ||      S )	a9  
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        rL  r   rH  rV  r   rN  F)rL  rV  rx  GenerateNewKey)r  rZ  r  rX  r2  rY  rZ  r[  r  privateGetGetDepositInform  parse_deposit_address)	r_  r  rr  rL  r]  rH  r  rs  rt  s	            ra  fetch_deposit_addresszndax.fetch_deposit_address  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>==&"!$#	
 00Wf1MN ))(H==rb  c                 >   | j                  |d      }t        j                  |      }t        |      }| j                  ||dz
        }|j	                  d      }| j                  |d      }| j                  |d      }	d }
||d   }
| j                  |       ||
d ||	dS )NDepositInfor   z?memo=r   r  )r  r  networkaddresstag)rn  jsonloadsr  splitcheck_address)r_  depositAddressr  depositInfoStringdepositInfodepositInfoLength
lastStringpartsr  r  r  s              ra  r  zndax.parse_deposit_address  s     !,,^]Kjj!23,%%k3Dq3HI
  *""5!,ua(F#D7#"
 	
rb  c                 N    ddi}| j                  || j                  ||            S )a=  
        create a currency deposit address
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  T)r  rm  )r_  r  rr  rs  s       ra  create_deposit_addresszndax.create_deposit_address'  s0     d
 ))$GV0LMMrb  c           	      F   | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }d}|| j                  |      }||d}	| j                  | j                  |	|            }
t        |
t              r'| j                  t        j                  |
      |||      S | j                  |
|||      S )	a  
        fetch all deposits made to an account

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

        :param str code: unified currency code
        :param int [since]: not used by ndax fetchDeposits
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        rL  r   rH  rV  r   rN  NrW  )r  rZ  r  rX  r2  rY  rZ  r[  r  privateGetGetDepositsrm  r0  strparse_transactionsr  r  r_  r  r  r#  rr  rL  r]  rH  r  rs  rt  s              ra  fetch_depositszndax.fetch_deposits3  s    !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>}}T*H"
 --dkk'6.JK: h$**4::h+?5RWXX&&x5%HHrb  c           	         | j                  | j                  dd      }| j                          | j                          | j	                  | j                  ddt        | j                  d   d               }| j	                  |dd|      }| j                  |ddg      }d}|| j                  |      }||d}	| j                  | j                  |	|            }
| j                  |
|||      S )	a  
        fetch all withdrawals made from an account

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

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        rL  r   rH  rV  r   rN  NrW  )r  rZ  r  rX  r2  rY  rZ  r[  r  privateGetGetWithdrawsrm  r  r  s              ra  fetch_withdrawalszndax.fetch_withdrawalsm  s     !!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>}}T*H"
 ..t{{7F/KL2 &&x5%HHrb  c                     ddddddddddddddddi ddddddd	dd
ddddddddddddddddddddddddddddddddd}| j                  ||i       }| j                  |||      S )Npendingr  r|  failed)NewAdminProcessingr  r  SystemProcessingFullyProcessedFailedPending	ConfirmedAmlProcessingAmlAcceptedAmlRejected	AmlFailedLimitsAcceptedLimitsRejectedr   r  r  r  r  r  r  r  
Pending2FaAutoAcceptedDelayedUserCanceledr  AdminCanceledr  r  r	  r
  )r  r  	Submittedr  ManuallyConfirmedConfirmed2Fa)r  
withdrawal)r  rn  )r_  r  r  statusesByTyper  s        ra   parse_transaction_status_by_typez%ndax.parse_transaction_status_by_type  sM    !#,%&$-"&"$&!*()%"+","y!9 I J	
 #I !$ ( 9 i 	 9 
     y  z!" X#$ #,",&&%. )/%+ 
X ??>4<&&99rb  r`  c                     d }| j                  |d      }| j                  ||      }d }d|v r| j                  |d      }d}nd|v r| j                  |d      }d}| j                  | j                  |dd            }| j	                  |d      }|| j	                  |d	|      }| j                  |d
d      }	| j	                  |d      }
| j                  |d      }| j                  |d      }d }|||d}i d|d|d| j                  |dd      d|
d| j                  |
      d|	d|	d| j                  |d      dd dd dd d|d| j                  |d       d!|d"| j                  ||      d#|d$|d d d d%S )&Nrx  	DepositIdr  
WithdrawIdr  TemplateFormr  LastUpdateTimeStampLastUpdatedExternalAddress	ToAddressTimeSubmitted	FeeAmountTicketStatus)r  r  r  rN  txidTxIdTXIdr  r  r  	addressToaddressFromFromAddressr  tagTotagFromr  r  rK  r  r  updatedr  )internalcommentr  )	rn  r  
parse_jsonsafe_value_2r  r3  r  r  r  )r_  r`  r  rN  rS  r  r  templateFormr+  r  r  feeCosttransactionStatusr  s                 ra  parse_transactionzndax.parse_transaction  s?   f %%k;?
&&z8<+%!!+{;BD[(!!+|<BDt'8'8nVc'de##K1FG#''mWMG$$\3DkR%%lOD	"";< ,,[.I#W5C
K
"
 D&&|VVD
 	

 Y/
 w
 
 4++L-H
 4
 T
 t
 D
 d&&{H=
 
 d;;<MtT
  w!
" 3#
$ )
 	
rb  r  c           	          | j                  ||      \  }}| j                  | j                  d      }|t        | j                  dz         | j
                  t        | j                  dz         | j                  |       | j                  | j                  dd      }| j                          | j                          | j                  | j                  ddt        | j                  d   d	               }| j                  |dd|      }	| j                  |ddg      }| j                  |      }
||	|
d	   d
}| j                  |      }| j!                  |dg       }| j!                  |d      }|t#        | j                  dz   |
d   z         | j                  |d      }||	|
d	   ||d   d}| j%                  |      }| j                  |d      }|t#        | j                  dz   |
d   z         t'        j(                  |      }||d<   |	d|v r||d<   ||	|
d	   | j'                  |      |d}d| j+                  | j
                        | j'                  |      d}| j-                  | j/                  ||            }| j1                  ||
      S )a  
        make a withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rg  z/ call signIn() method to obtain a session tokenz/ withdraw() requires exchange.twofa credentialsrL  r   rH  rV  r   rN  )rL  rV  rx  TemplateTypesz8 withdraw() could not find a withdraw template type for r  TemplateNameAccountProviderId)rL  rV  rx  TemplateTyper7  Templatez3 withdraw() could not find a withdraw template for r  Memo)rL  rV  rx  r  r8  Google)TfaTypeTFaCodePayload)handle_withdraw_tag_and_paramsrn  rZ  r   rN  ro  r  r  r  rX  r2  rY  rZ  r[  r  "privateGetGetWithdrawTemplateTypesr  r   privateGetGetWithdrawTemplater  r  rp  privatePostCreateWithdrawTicketr[  r3  )r_  r  r  r  r  rr  rg  rL  r]  rH  r  withdrawTemplateTypesRequestwithdrawTemplateTypesResponsetemplateTypesfirstTemplateTypetemplateNamewithdrawTemplateRequestwithdrawTemplateResponsetemplatewithdrawTemplatewithdrawPayloadwithdrawRequestrt  s                          ra  r   zndax.withdraw0	  s    99#vFV''nE%dgg0a&abb::%dgg0a&abb7#!!$,,;..t||[+WZ[_[h[hij[klp[qWrs''[JZ[	6K#=>==&"!$.
$
 )-(O(OPl(m% (EXZ[ OOM1=$*d dgopvgw wxx''(9>J"!$(!23F!G)
 $(#E#EF]#^  ##$<jI*_ _bjkqbr rss::h/.5*+?))+. ("!$ II&67(!
  yy,yy1!

 778H8HZ`8ab%%h99rb  c                 "    | j                         S N)r  )r_  s    ra  r  z
ndax.nonce	  s      ""rb  r   GETc                    | j                   d   |   dz   | j                  ||      z   }| j                  || j                  |            }|dk(  r|dk(  r5| j                  dz   | j
                  z   }	| j                  |	      }
dd|
z   i}n9|dk(  r4| j                  | j                  d	      }|d
|i}| j                  |d	      }|r |d| j                  |      z   z  }n|dk(  r| j                          | j                  | j                  d      }|t        | j                               }|| j                  z   | j                  z   }	| j                  | j!                  |	      | j!                  | j"                        t$        j&                        }|| j                  || j                  d}nd|i}|dk(  rd|d<   | j)                  |      }n|r|d| j                  |      z   z  }||||dS )Nr   r  r   r   :AuthorizationzBasic r   ri  rh  ?r   rg  )NonceAPIKey	SignaturerE  APTokenPOSTzapplication/jsonzContent-Type)urlmethodbodyheaders)rU  implode_paramsr[  extract_paramsr4  r5  string_to_base64rn  rZ  	urlencoderk  r  r  r3  r1  hmacencoder2  hashlibsha256r  )r_  pathr   r[  rr  r]  r\  rZ  queryauthauth64ri  rg  r  	signatures                  ra  signz	ndax.sign	  s   iis#c)D,?,?f,MM		&$"5"5d";<(?~%zzC'$--7..t4#X%6 **"&"2"24<<AR"S".)?G !IIe->?EsT^^E222I++-++DLL.IL#DJJL)txx'$++5 IIdkk$&7T[[9QSZSaSab	""kk!*"hh	 | *<'yy'3!666CfdwOOrb  reasonrZ  r[  r]  r\  c
                 6   |dk(  rt        | j                  dz   |z         |y | j                  |d      }
|
b|
dk7  r]| j                  dz   |z   }| j                  | j                  d   |
|       | j                  | j                  d   ||       t        |      y )Ni   errormsg r7  r8  )r   rN  rn  throw_exactly_matched_exceptionrY  throw_broadly_matched_exceptionr   )r_  r  rl  rZ  r[  r]  r\  rt  requestHeadersrequestBodymessagefeedbacks               ra  handle_errorszndax.handle_errors	  s    3;%dggmd&:;;
 ""8Z8gmww}t+H001I7T\]001I4QYZ))rb  )Nr  r  r=  r  r9  rO  )F__name__
__module____qualname__r   r]  rv  r   r  r   r   r  dictr  r   r  r  r   r   r  r   r  r  r1  r  r  r   r>  rC  r   rI  r   rT  r^  ro  r	   r   r  r   r  r  r   r  r   r   r  r   r  r  r  r  r  r  r  r  r  r
   r  r  r  r   r  r  r  r3  r   r  rk  rY  rw  __classcell__)r`  s   @ra  r!   r!      sI   o# ob   0d ') CZ CJ $& <,$v, <,|:
4 :
F :
x lu    GP    dm  D :>b +7s +73 +7Y +7Z@4 @ @6 @D 02 033 03f 03d
 
4 
. 26DW[df )L# )Lc )LQT )Lkoptku )LVc cv c cJ 6:UW A3 As A# A\`af\g A8 %' 4= B) )" $& 5,( 5,n3$4t 4x 4; 4l (,$TZ\ .C .CC .Cs .Caefqar .C`	: 	:\ \v \ \| gksu A23 A2i A2y A2RW A2`c A2F `drv  @B +2S +2# +2Y +2i +2Y\ +2lo +2Z -1tRV_a SAc SA SAC SAj /32 $
 $
L 37r $s $C $L /3TXac LA LA3 LAc LAhlmrhs LA\ *.Dt\^ ZA3 ZAc ZA ZAcghmcn ZAx 26b J2c J23 J2X 9=4^bkm P?S P?# P?S P?X[ P?d 79 !># !>^ !>F 
h  
R`  
D 8: 
N3 
Nn 
N *.Dt\^ 8I3 8Ic 8I 8Icghsct 8It -1tRV_a 2Ic 2I 2IC 2Ifjkvfw 2Ih.:`]
T ]
X ]
Q\ ]
~ DHPR U:S U:% U:# U:Wb U:n# &eBSW ,P\# s  c TX `c rb  r!   )'ccxt.base.exchanger   ccxt.abstract.ndaxr   rd  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r!    rb  ra  <module>r     s_    ( *   L  L  L  L  L  L  * 0 & . * 4 %r&8[ r&rb  