
    i\                        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 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#dS )    )Exchange)ImplicitAPIN)AccountBalances
CurrenciesCurrency	IndexTypeIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)AuthenticationError)	BadSymbol)InsufficientFunds)OrderNotFound)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi fdefdZi fdee         fdZ	defdZ
dBdededefdZdi fdededefdZdCdedefdZi fdedefdZdCdedefdZdddi fdedededee         fdZdCd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dCd!e fd"Z!dddi fd#e"dedefd$Z#d% Z$dCd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.Z-di fde"fd/Z.di fd,ede"fd0Z/dddi fde"dededee%         fd1Z0dddi fde"dededee%         fd2Z1di fd,ede"fd3Z2dddi fd,ede"dedefd4Z3i fd#efd5Z4dCd!e fd6Z5i fd#efd7Z6dddi fd#e"dededee7         fd8Z8dddi fd#e"dededee7         fd9Z9dCd:Z:dCd!e de7fd;Z;di fd#ed)e)fd<Z<d= Z=d>d?i ddfd@Z>dA Z? xZ@S )Dndaxc                     |                      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	dd	d	dd	d	dd	d	d	d	dd	dd:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdJdKdLdLdKdMdNgdOdPdQdRi dSdTdUdTdVdTdWdTdXdTdYdTdZdTd[dTd\dTd]dTd^dTd_dTd`dTdadTdbdTdcdTdddTdTdTdTdTdTdTdTdTdTde	ii dfdTdgdTdhdTdidTdjdTdkdTdldTdmdTdndTdodTdpdTdqdTdrdTdsdTdtdTdudTdvdTi dwdTdxdTdydTdzdTd{dTd|dTd}dTd~dTddTddTddTddTddTddTddTddTddTdTdTdTdTdTdTdTdi ddTddTddTddTddTddTddTddTddTddTddTddTddTddTddTddTddTdTdTdTdTdTdTdTdTdTd	ddKdd	d|                     d          |                     d          diddddddt
          t          t          t          dt          t          dddTdTdddddddTddddddd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fetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCV)fetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchWithdrawalsreduceMarginsetLeverage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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   r   requiredCredentialsprecisionMode
exceptionsoptions)deep_extendsuperr   describeparse_numberr   r   r   r   r   r   )self	__class__s    ]/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/ndax.pyr  zndax.describe   s   dD 1 1 : : < <BBB %B 	B
 %B %B UB "4B tB $UB  B 'B tB (B 'B  (!B" "4#B B$ T%B&  'B( )B* +E+B, )%-B. '/B0 (1B2 "43B4 &t5B6  7B8 &u9B: #E;B< *5=B> $U?B@ "5ABB *5CBD +EEB B BF tGBH  IBJ %eKBL MBN !%OBP  QBR dSBT +EUBV "4WBX dYBZ !$[B\ t]B^ #D_B`  aBb !%cBd %eeBf )%gB Bh  $ %"##($)$( %$!&#(! CB B BH    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?h hT !&"&!..w77!..x88	   $ $ ' ):$1*7  -6M` 
 
 "#!"*+)*"#  _B?
 B?
 B B B	    c                   K   |                                   | j        | j        t          | j        dz             ddi}|                     |                     ||                     d{V }|                     |d          }||| j        d<   |S |                     |d          }|| j	        t          | j        dz             || j        d	<   d
| 
                    | j	                  i}|                     |                     ||                     d{V }|                     |d          }|| j        d<   |S |S )a  
        sign in, must be called prior to using other authenticated methods
        :see: https://apidoc.ndax.io/#authenticate2fa
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns: response from exchange
        Nz4 signIn() requires exchange.login, exchange.password
grant_typeclient_credentialsSessionTokensessionTokenPending2FaTokenz- signIn() requires exchange.twofa credentialspending2faTokenCode)check_required_credentialsr   r   r   r	  publicGetAuthenticateextendsafe_stringr  twofatotppublicGetAuthenticate2FA)r  paramsrequestresponser!  r#  responseInners          r  sign_inzndax.sign_in  st      	''))):!6%dg0f&fggg.
 33DKK4P4PQQQQQQQQ ''.AA#+7DL(O**85FGG&z!)$'4c*cddd.=DL*+		$*--G #'"?"?GU[@\@\"]"]]]]]]]M  ++M>JJL+7DL(  r  returnc                   K   |                      | j        dd          }d|i}|                     |                     ||                     d{V }i }t	          dt          |                    D ]}||         }|                     |d          }|                     |d          }	|                     |d          }
|
dk    rd	nd
}|
dk    rd}|                     |                     |d                    }|                     |d          }| }||	||| 	                    |d          ||ddddddddddi d||<   |S )a  
        fetches all available currencies on an exchange
        :see: https://apidoc.ndax.io/#getproduct
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   Nr   	ProductIdProductFullNameProductTypeNationalCurrencyfiatcryptoUnknownotherProduct
IsDisabledTickSizeminmax)amountrc   )r	  r
  codetype	precisioninfoactivedepositrc   feelimitsnetworks)
safe_integerr  publicGetGetProductsr'  rangelenr(  safe_currency_code
safe_valuesafe_number)r  r,  r  r-  r.  resulticurrencyr	  r
  r5  rC  rB  
isDisabledrF  s                  r  fetch_currencieszndax.fetch_currenciesL  s      !!$,;;U
 224;;w3O3OPPPPPPPP" q#h--(( "	 "	A{H!!(K88B##H.?@@D**8]CCK)-???66hDi''**4+;+;Hi+P+PQQD<@@J#^F!--h
CC     $# 
  $#! !	 	 + F4LL. r  c                    K   |                      | j        dd          }d|i}|                     |                     ||                     d{V }|                     |          S )a  
        retrieves data on all markets for ndax
        :see: 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
        r  r   N)rK  r  publicGetGetInstrumentsr'  parse_markets)r  r,  r  r-  r.  s        r  fetch_marketszndax.fetch_markets  sy       !!$,;;U
 55dkk'66R6RSSSSSSSS^ !!(+++r  c                    |                      |d          }|                      |d          }|                      |d          }|                     |                      |d                    }|                     |                      |d                    }|                      |d          }|                     |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|	o| 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$
S )%NInstrumentIdProduct1Product2Product1SymbolProduct2SymbolSessionStatus	IsDisableRunningr	  symbol/basequotesettlebaseIdquoteIdsettleIdrC  r$   Tr%   Fr&   r'   r(   rF  contractlinearQuantityIncrementPriceIncrement)rA  pricer>  MinimumQuantityMinimumPrice)leveragerA  rp  cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionTyperD  rI  createdrE  )r(  rO  rP  rQ  )
r  marketr	  ri  rj  rf  rg  sessionStatus	isDisablesessionRunnings
             r  parse_marketzndax.parse_market  sn   fn55!!&*55""6:66&&t'7'7@P'Q'QRR''(8(8AQ(R(RSS((AAOOFK8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G))&2BCC    
  ++F4EFF 
  ++FNCC 
    $ _0
 0
 0
 0	
r  Nbidsasksr      r   priceKey	amountKeycountOrIdKeyc	                    d }	|g g d d d d}
t          dt          |                    D ]}||         }||                     |d          }n&|                     |d          }t          ||          }|	|                     |d          }	n&|                     |d          }t          |	|          }	|                     |||          }|                     |d          }|r|n|}|
|                             |           |                     |
d         dd          |
d<   |                     |
d         d          |
d<   ||
d<   |                     |          |
d	<   |	|
d
<   |
S )N)rd  r  r  	timestampdatetimenoncer   r   	   r  Tr  r  r  r  )rM  rN  rK  r@  parse_bid_askappendsort_byiso8601)r  	orderbookrd  r  bidsKeyasksKeyr  r  r  r  rR  rS  levelnewTimestampnewNoncebidask	levelSidesides                     r  parse_order_bookzndax.parse_order_book  s   
 
 q#i..)) 	( 	(AaLE  --eQ77		#00::	<88	}))%33,,UA66E8,,''xCCF))%33I'477WD4L''''fVna>>vfVna88v'{!\\)44zwr  rd  limitc                 J  K   |                      | j        dd          }|                                  d{V  |                     |          }|dn|}||d         |d}|                     |                     ||                     d{V }|                     ||          S )a'  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        r  r   Nd   r	  )r  r\  Depth)rK  r  load_marketsr|  publicGetGetL2Snapshotr'  r  )r  rd  r  r,  r  r|  r-  r.  s           r  fetch_order_bookzndax.fetch_order_book'  s       !!$,;;!!!!!!!!!V$$E"4L
 

 44T[[&5Q5QRRRRRRRR. $$Xv666r  r|  c                    |                      |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|          S )N	TimeStampr\  LastTradedPxRolling24HrPxChangePercentRolling24HrPxChangeSessionOpenRolling24HrVolumeRolling24HrNotionalrd  r  r  highSessionHighlow
SessionLowbidBestBid	bidVolumeask	BestOffer	askVolumevwapopencloselastpreviousClosechanger   average)
baseVolumequoteVolumerE  )rK  r(  safe_marketsafe_symbolsafe_tickerr  )r  tickerr|  r  marketIdrd  r  r   r  r  r  r  s               r  parse_tickerzndax.parse_tickerR  s+   B %%fk::	##FN;;!!(F33!!(F3377%%f.JKK
!!&*?@@66%%f.ABB
&&v/DEE !
f!
!
 Y//!
 D$$V];;	!

 4##FL99!
 4##FI66!
 !
 4##FK88!
 !
 D!
 D!
 T!
 D!
 T!
 f!
  *!!
" t#!
$ %&)!
 !
 !
* +  	r  c                 <  K   |                      | j        dd          }|                                  d{V  |                     |          }||d         d}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        r  r   Nr	  r  r\  )rK  r  r  r|  publicGetGetLevel1r'  r  )r  rd  r,  r  r|  r-  r.  s          r  fetch_tickerzndax.fetch_ticker  s       !!$,;;!!!!!!!!!V$$"4L
 
 00Wf1M1MNNNNNNNN>   6222r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r   r   r   r   )rK  rQ  )r  ohlcvr|  s      r  parse_ohlcvzndax.parse_ohlcv  s     eQ''UA&&UA&&UA&&UA&&UA&&
 	
r  rq   sincec                   K   |                      | j        dd          }|                                  d{V  |                     |          }||d         |                     | j        ||          d}|                     |          }	|                                 }
|<|9|                     |
|	|z  dz  z
            |d<   |                     |
          |d<   ne|                     |          |d<   ||                     |
          |d<   n2|                     | 	                    ||	|z  dz                      |d<   | 
                    |                     ||                     d{V }|                     |||||          S )	a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: 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
        r  r   Nr	  )r  r\  Intervalr"   FromDateToDate)rK  r  r  r|  r(  r  parse_timeframemillisecondsymdhmssumpublicGetGetTickerHistoryr'  parse_ohlcvs)r  rd  	timeframer  r  r,  r  r|  r-  durationnowr.  s               r  fetch_ohlcvzndax.fetch_ohlcv  s      !!$,;;!!!!!!!!!V$$"4L(()YOO
 

 ''	22!!= &*kk#58H48O2O&P&P
#$(KK$4$4!"&++e"4"4GJ}$(KK$4$4!!$(KK5@PSW@W0X0X$Y$Y!77GV8T8TUUUUUUUU   69eUKKKr  c                    d }d }d }d }d }d }d }	d }
d }d }d }t          |t                    r|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|rdnd}	|                     |d	          }
n(|                     |d
d          }|                     |d          }|                     |dd          }
|                     |dd          }|                     |d          }|                     |d          }|                     |dd          }|                     |d          }|                     |d          }	|                     |d          }|                     |d          }|0|                     |d          }|                     |          }||d}| 	                    ||          }| 
                    |||||                     |          |
||	|||||d|          S )Nr   r   r   r   r   r  sellbuyr   TradeTimeMSReceiveTimeTradeIdOrderIdOrigOrderIdr\  
InstrumentPriceQuantityValueGrossValueExecuted
MakerTakerSider   FeeFeeProductId)rt  rT  )rE  r	  rd  r  r  orderrC  r  takerOrMakerrp  rA  rt  rH  )
isinstancelistr(  rK  rP  safe_integer_2safe_string_2safe_string_lowerrO  r  
safe_trader  )r  trader|  priceStringamountString
costStringr  r	  r  r  orderIdr  rH  rC  	takerSidefeeCostStringfeeCurrencyIdfeeCurrencyCoderd  s                      r  parse_tradezndax.parse_trade  s   Z 
	eT"" 	**5!44K++E155L))%33I!!%++B''q11Hq11I&166ED&&ua00GG++E=-PPI!!%33B((	=IIG))%NNH**5'::K++E:>>L++E7<PQQJ11%FFL))%88D))%==D ,,UE::M( $ 0 0 G G"&"9"9-"H"H) /  !!(F33"Y//( " 
  
   	r  c                 N  K   |                      | j        dd          }|                                  d{V  |                     |          }||d         d}|||d<   |                     |                     ||                     d{V }|                     ||||          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>`
        r  r   Nr	  r  Count)rK  r  r  r|  publicGetGetLastTradesr'  parse_trades)	r  rd  r  r  r,  r  r|  r-  r.  s	            r  fetch_tradeszndax.fetch_trades  s       !!$,;;!!!!!!!!!V$$"4L
 
 $GG44T[[&5Q5QRRRRRRRR   65%@@@r  c                   K   | j         st          | j        dz             |                     | j        dd          }|                                  || j        | j         d}|                     |                     ||                     d{V }g }t          dt          |                    D ]2}|                     ||          }|                    |dd|d           3|S )aU  
        fetch all the accounts associated with a profile
        :see: 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 credentialr  r   )r  UserIdUserNameNr   )r	  rC  rT  rE  )r   r   r	  rK  r  r%  r   privateGetGetUserAccountsr'  rM  rN  r(  r  )r  r,  r  r-  r.  rR  rS  	accountIds           r  fetch_accountszndax.fetch_accounts  s      z 	m%dg0k&klll!!$,;;'')))h

 

 77GV8T8TUUUUUUUU q#h--(( 	 	A((155IMM !	      r  c                    |d d d}t          dt          |                    D ]}||         }|                     |d          }|| j        v r`|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )N)rE  r  r  r   r3  AmounttotalHoldused)rM  rN  r(  currencies_by_idrO  accountsafe_balance)r  r.  rR  rS  balance
currencyIdrB  r  s           r  parse_balancezndax.parse_balance  s    
 

 q#h--(( 	' 	'AqkG))';??JT222..z::,,..#'#3#3GX#F#F "&"2"27F"C"C&t  (((r  c           	        K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }||d}|                     | 	                    ||                     d{V }| 
                    |          S )	a[  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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>`
        r  r   Nr  	AccountIdr   r	  r  r  )rK  r  r  load_accountsr  intaccountsomitprivateGetGetAccountPositionsr'  r  )r  r,  r  defaultAccountIdr  r-  r.  s          r  fetch_balancezndax.fetch_balance  s/      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>"
 
 ;;DKKQW<X<XYYYYYYYY@ !!(+++r  c                 P    dddddddddddddd}|                      |||          S )Nr  transactionrb   )r   DepositWithdrawTransfer	OrderHoldWithdrawHoldDepositHold
MarginHold
ManualHoldManualEntryMarginAcquisitionMarginRelinquishMarginQuoteHoldr(  )r  rC  typess      r  parse_ledger_entry_typezndax.parse_ledger_entry_type(  sO    $%" )(!!"!( '&
 
 tT222r  rT  c                    |                      |d          }|                      |d          }|                      |d          }d }d }t          j        |d          r|}d}nt          j        |d          r|}d}d }|                      |d          }	|dk    rt          j        |	|          }n.|dk    r(t          j        dt          j        |	|                    }|                     |d          }
||                      |d	          ||                      |d
          |                      |d          |                      |d          |                     |                      |d                    |                     ||          | 	                    |          | 	                    |          | 	                    |	          d|
| 
                    |
          d dS )Nr3  CRDR0inoutBalancer  TransactionIdr  ReferenceIdCounterpartyReferenceTypeok)rE  r	  	directionr  referenceIdreferenceAccountrC  rT  rA  beforeafterstatusr  r  rH  )r(  r   	string_lt
string_add
string_max
string_subrK  r+  rO  r  r  )r  itemrT  r  creditdebitrA  r8  r;  r<  r  s              r  parse_ledger_entryzndax.parse_ledger_entry:  s   " %%dK88
!!$--  t,,	VS)) 	FIIuc** 	FI  y11'v66FF$'W-?v-N-NOOF%%dK88	""499"''k::++D-@@ $ 0 0~ F F001A1A$1X1XYY//
HEE''//''//&&u--"Y//
 
 	
r  rB  c           	      T  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }||d}|||d	<   |                     | 	                    ||                     d{V }	d}
|| 
                    |          }
|                     |	|
||          S )
aQ  
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :see: 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 entrys 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-structure>`
        r  r   Nr  r  r   r	  r  r  )rK  r  r  r  r  r  r  r   privateGetGetAccountTransactionsr'  rT  parse_ledger)r  rB  r  r  r,  r  r  r  r-  r.  rT  s              r  fetch_ledgerzndax.fetch_ledgero  s`      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>"
 
 $GG>>t{{7TZ?[?[\\\\\\\\& }}T**H  8UEBBBr  c                 B    ddddddd}|                      |||          S )Nr  rejectedcanceledexpiredclosed)AcceptedRejectedWorkingCanceledExpiredFullyExecutedr)  )r  r=  statusess      r  parse_order_statuszndax.parse_order_status  s:    "" %
 
 &&999r  c                    |                      |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"|          S )#Nr  r  r	  ReplacementOrderIdr  clientOrderIdReplacementClOrdIdClientOrderIdrE  r  r  lastTradeTimestampLastUpdatedTimer=  
OrderStaterd  rC  r   timeInForcepostOnlyr  r  rp  r  	stopPrice	StopPricert  r  rA  OrigQuantityfilledQuantityExecutedAvgPrice)r  	remainingrH  r   )
rK  r(  
safe_orderr  r  rV  r  r  r  	omit_zero)r  r  r|  r  r  s        r  parse_orderzndax.parse_order  sB   H %%e];;	##E<88  
$$$U,@)LL 
T//7K_]] 
 E 
 	 

 Y// 
 !$"3"3E;L"M"M 
 d--d.>.>ul.S.STT 
 d&&x88 
 D**5+>> 
 4 
  
 D**5&99 
 T%%eW55 
 **4>>$:J:J5R]:^:^+_+_`` 
 D$$U,@AA 
  d&&un==! 
" d&&u.@AA# 
$ ''z::+ 
  
  
, -  	r  rC  r  rA  rp  c                   K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }	|                     |dd	          }
|                      | j        d
         |                     |                    }|                     |d          }||dk    rd}n|dk    rd}| 	                    |g d          }| 
                    |          }|dk    rdnd}t          |d                   ||	d|t          |                     ||                    |d}|&t          |                     ||                    |d<   |
|
|d<   |||d<   |                     |                     ||                     d{V }|                     ||          S )a  
        create a trade order
        :see: 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 fullfilled, 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r   Nr  r  r   r	  r[  rY  r  triggerPricer|  r   r  r   )r  r  rY  r[  rl  r  )r\  r  r  TimeInForcer  r  r   
LimitPricerb  )rK  r  r  r  r  r  r  
capitalizer(  r  r|  floatamount_to_precisionprice_to_precisionprivatePostSendOrderr'  rj  )r  rd  rC  r  rA  rp  r,  r  r  r  rY  	orderTyperl  r|  	orderSider-  r.  s                    r  create_orderzndax.create_order  sK      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	++FO_UU%%dl<&@$//RVBWBWXX	''??#x			6#o#o#oppV$$%--AAa	t--" d66vvFFGG"
 
& $)$*A*A&%*P*P$Q$QGL!$'4GO$##/GK 224;;w3O3OPPPPPPPP &111r  r	  c                   K   |                      | j        dd          }|                                  d {V  |                                  d {V  |                     | j        ddt          | j        d         d                             }	|                     |dd|	          }
|                     |dd          }|                     |g d	          }|                     |          }|d
k    rdnd}t          |          t          |d                   ||
d|t          | 
                    ||                    |                      | j        d         |                     |                    d}|&t          |                     ||                    |d<   |||d<   |                     |                     ||                     d {V }|                     ||          S )Nr  r   r  r  r   r	  r[  rY  )r  r  rY  r[  r  r  )OrderIdToReplacer\  r  r  rm  r  r  r   rn  )rK  r  r  r  r  r  r  r  r|  rp  rq  ro  rr  privatePostCancelReplaceOrderr'  rj  )r  r	  rd  rC  r  rA  rp  r,  r  r  r  rY  r|  ru  r-  r.  s                   r  
edit_orderzndax.edit_orderF  s     !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	++FO_UU6#_#_#_``V$$%--AAa	 #Bt--" d66vvFFGG**4<+EtW[G\G\]]
 
( $)$*A*A&%*P*P$Q$QGL!$'4GO$;;DKKQW<X<XYYYYYYYY &111r  c           	        K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }||d}d}	| |                     |          }	|	d         |d	<   || 	                    |d
z            |d<   |||d<   | 
                    |                     ||                     d{V }
|                     |
|	||          S )a  
        fetch all trades made by the user
        :see: 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>`
        r  r   Nr  r  r   r	  r  r\  r"   StartTimeStampr  )rK  r  r  r  r  r  r  r  r|  parse_to_intprivateGetGetTradesHistoryr'  r  r  rd  r  r  r,  r  r  r  r-  r|  r.  s              r  fetch_my_tradeszndax.fetch_my_tradess  s      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>"
 
 [[((F&,TlGN#(,(9(9%$,(G(GG$%$GG88Wf9U9UVVVVVVVVX   65%@@@r  c           	      ,  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }||d}| |                     |          }|d         |d	<   | 	                    | 
                    ||                     d{V }|S )
a  
        cancel all open orders
        :see: 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>`
        r  r   Nr  r  r   r	  r  IntrumentId)rK  r  r  r  r  r  r  r  r|  privatePostCancelAllOrdersr'  )	r  rd  r,  r  r  r  r-  r|  r.  s	            r  cancel_all_orderszndax.cancel_all_orders  sC      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>"
 
 [[((F%+D\GM"88Wf9U9UVVVVVVVV r  c                 .  K   |                      | j        dd          }|                                  d{V  |                                  d{V  d}||                     |          }d|i}|                     |dd          }|||d<   nt          |          |d<   |                     |ddg          }|                     | 	                    ||                     d{V }| 
                    ||          }	| 	                    |	||d          S )av  
        cancels an open order
        :see: 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
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r   NrY  	ClOrderIdr  )r	  rY  )rK  r  r  r  r|  r  r  r  privatePostCancelOrderr'  rj  )
r  r	  rd  r,  r  r|  r-  rY  r.  r  s
             r  cancel_orderzndax.cancel_order  sW      !!$,;;!!!!!!!!!  """"""""" [[((FU
 ++FO[QQ$#0GK  !$RGI6O[#ABB44T[[&5Q5QRRRRRRRR  622{{5*#
 #
   	r  c           	      F  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }d}||                     |          }||d}	| 	                    | 
                    |	|                     d{V }
|                     |
|||          S )	a  
        fetch all unfilled currently open orders
        :see: 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>`
        r  r   Nr  r  r   r	  r  )rK  r  r  r  r  r  r  r  r|  privateGetGetOpenOrdersr'  parse_orders)r  rd  r  r  r,  r  r  r  r|  r-  r.  s              r  fetch_open_orderszndax.fetch_open_orders	  sP      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>[[((F"
 
 55dkk'66R6RSSSSSSSSf   65%@@@r  c           	        K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }||d}d}	| |                     |          }	|	d         |d	<   || 	                    |d
z            |d<   |||d<   | 
                    |                     ||                     d{V }
|                     |
|	||          S )a#  
        fetches information on multiple orders made by the user
        :see: 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>`
        r  r   Nr  r  r   r	  r  r\  r"   r|  r  )rK  r  r  r  r  r  r  r  r|  r}  privateGetGetOrdersHistoryr'  r  r  s              r  fetch_orderszndax.fetch_ordersU  s      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>"
 
 [[((F&,TlGN#(,(9(9%$,(G(GG$%$GG88Wf9U9UVVVVVVVVf   65%@@@r  c           	      ^  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }d}||                     |          }||t          |          d}| 	                    | 
                    ||                     d{V }	|                     |	|          S )	at  
        fetches information on an order made by the user
        :see: https://apidoc.ndax.io/#getorderstatus
        :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>`
        r  r   Nr  r  r   r	  )r  r  r  )rK  r  r  r  r  r  r  r  r|  privateGetGetOrderStatusr'  rj  )
r  r	  rd  r,  r  r  r  r|  r-  r.  s
             r  fetch_orderzndax.fetch_order  sU      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>[[((F"2ww
 

 66t{{7F7S7STTTTTTTTb &111r  c                 
  K   |                      | j        dd          }|                                  d{V  |                                  d{V  d}||                     |          }|                     |          t          |          d}|                     |                     ||                     d{V }	| 	                    |	d          }
| 
                    |
dg           }|                     ||||          S )a  
        fetch all the trades made from a single order
        :see: 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>`
        r  r   N)OMSIdr  ChangeReasonr   )rK  r  r  r  r|  r}  r  #privatePostGetOrderHistoryByOrderIdr'  group_by	safe_listr  )r  r	  rd  r  r  r,  r  r|  r-  r.  groupedr   s               r  fetch_order_tradeszndax.fetch_order_trades  s(      !!$,;;!!!!!!!!!  """"""""" [[((F&&u--2ww
 

 AA$++gW]B^B^________f --.99"55  >>>r  c           	      J  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }|                     |          }|||d         dd	}| 	                    | 
                    ||                     d{V }|                     ||          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>`
        r  r   Nr  r  r   r	  F)r  r  r3  GenerateNewKey)rK  r  r  r  r  r  r  r  rT  privateGetGetDepositInfor'  parse_deposit_address)	r  rB  r,  r  r  r  rT  r-  r.  s	            r  fetch_deposit_addresszndax.fetch_deposit_addressH  sJ      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>==&&"!$#	
 
 66t{{7F7S7STTTTTTTT ))(H===r  c                 z   |                      |d          }t          j        |          }t          |          }|                      ||dz
            }|                    d          }|                      |d          }|                      |d          }	d }
||d         }
|                     |           |
||	d |dS )NDepositInfor   z?memo=r   rB  )rT  addresstagnetworkrE  )r(  jsonloadsrN  splitcheck_address)r  depositAddressrT  depositInfoStringdepositInfodepositInfoLength
lastStringpartsr  r  rB  s              r  r  zndax.parse_deposit_addressk  s     !,,^]KKj!233,,%%k3Dq3HII
  **""5!,,ua((F#D7###"
 
 	
r  c                 n   K   ddi}|                      ||                     ||                     d{V 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  TN)r  r'  )r  rB  r,  r-  s       r  create_deposit_addresszndax.create_deposit_address  sL       d
 //dkk'66R6RSSSSSSSSSr  c           	        K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }d}||                     |          }||d}	| 	                    | 
                    |	|                     d{V }
t          |
t                    r*|                     t          j        |
          |||          S |                     |
|||          S )	a  
        fetch all deposits made to an account
        :see: 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>`
        r  r   Nr  r  r   r	  r  )rK  r  r  r  r  r  r  r  rT  privateGetGetDepositsr'  r  strparse_transactionsr  r  r  rB  r  r  r,  r  r  r  rT  r-  r.  s              r  fetch_depositszndax.fetch_deposits  s      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>}}T**H"
 
 33DKK4P4PQQQQQQQQ: h$$ 	Y**4:h+?+?5RWXXX&&x5%HHHr  c           	      F  K   |                      | j        dd          }|                                  d{V  |                                  d{V  |                     | j        ddt          | j        d         d                             }|                     |dd|          }|                     |ddg          }d}||                     |          }||d}	| 	                    | 
                    |	|                     d{V }
|                     |
|||          S )	a  
        fetch all withdrawals made from an account
        :see: 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>`
        r  r   Nr  r  r   r	  r  )rK  r  r  r  r  r  r  r  rT  privateGetGetWithdrawsr'  r  r  s              r  fetch_withdrawalszndax.fetch_withdrawals  sO      !!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>}}T**H"
 
 44T[[&5Q5QRRRRRRRR2 &&x5%HHHr  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}|                      ||i           }|                     |||          S )NpendingrK  r7  failed)NewAdminProcessingrO  rP  SystemProcessingFullyProcessedFailedPending	ConfirmedAmlProcessingAmlAcceptedAmlRejected	AmlFailedLimitsAcceptedLimitsRejectedr  r  rO  rP  r  r  r  r  
Pending2FaAutoAcceptedDelayedUserCanceledrL  AdminCanceledr  r  r  r  )r  r  	Submittedr  ManuallyConfirmedConfirmed2Fa)rG  
withdrawal)rP  r(  )r  r=  rC  statusesByTyperU  s        r   parse_transaction_status_by_typez%ndax.parse_transaction_status_by_type  sg    !#,%&$-"&"$&!*()%"+", "y!9 I J	
 #I !$ ( 9 i 	 9 
     y  z!" X#$ #,",&&%. )/  %+
 +
X ??>4<<&&999r  c                    d }|                      |d          }|                     ||          }d }d|v r|                      |d          }d}nd|v r|                      |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%S )&Nr3  	DepositIdrG  
WithdrawIdr  TemplateFormr  LastUpdateTimeStampLastUpdatedExternalAddress	ToAddressTimeSubmitted	FeeAmountTicketStatus)rT  rt  rE  r	  txidTxIdTXIdr  r  r  	addressToaddressFromFromAddressr  tagTotagFromrC  rA  r  rT  r=  updatedrH  )internalcommentr  )	r(  rO  
parse_jsonsafe_value_2rK  r  rQ  r  r  )r  r  rT  r	  r  rB  rC  templateFormr  r  r  feeCosttransactionStatusrH  s                 r  parse_transactionzndax.parse_transaction3  s   f %%k;??
&&z8<<+%%!!+{;;BDD[((!!+|<<BDt'8'8nVc'd'dee##K1FGG#''mWMMG$$\3DkRR%%lODD	"";<< ,,[.II#W55C
K
"
 D&&|VVDD
 	

 Y//
 w
 
 4++L-HH
 4
 T
 t
 D
 d&&{H==
 
 d;;<MtTT
  w!
" 3#
$ )
 
 
 	
r  c           	        K   |                      ||          \  }}|                     | j        d          }|t          | j        dz             | j        t          | j        dz             |                     |           |                     | j        dd          }|                                  d{V  | 	                                 d{V  | 
                    | j        ddt          | j        d	         d
                             }| 
                    |dd|          }	|                     |ddg          }|                     |          }
||	|
d
         d}|                     |           d{V }|                     |dg           }|                     |d	          }| t#          | j        dz   |
d         z             |                     |d          }||	|
d
         ||d         d}|                     |           d{V }|                     |d          }| t#          | j        dz   |
d         z             t'          j        |          }||d<   |	d|v r||d<   ||	|
d
         |                     |          |d}d|                     | j                  |                     |          d}|                     |                     ||                     d{V }|                     ||
          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>`
        r!  Nz/ call signIn() method to obtain a session tokenz/ withdraw() requires exchange.twofa credentialsr  r   r  r  r   r	  )r  r  r3  TemplateTypesz8 withdraw() could not find a withdraw template type for rB  TemplateNameAccountProviderId)r  r  r3  TemplateTyper  Templatez3 withdraw() could not find a withdraw template for r  Memo)r  r  r3  r  r  Google)TfaTypeTFaCodePayload)handle_withdraw_tag_and_paramsr(  r  r   r	  r)  r  rK  r  r  r  r  r  r  rT  "privateGetGetWithdrawTemplateTypesrP  r   privateGetGetWithdrawTemplater  r  r*  privatePostCreateWithdrawTicketr  r  )r  rB  rA  r  r  r,  r!  r  r  r  rT  withdrawTemplateTypesRequestwithdrawTemplateTypesResponsetemplateTypesfirstTemplateTypetemplateNamewithdrawTemplateRequestwithdrawTemplateResponsetemplatewithdrawTemplatewithdrawPayloadwithdrawRequestr.  s                          r  rc   zndax.withdraw  s      99#vFFV''nEE%dg0a&abbb:%dg0a&abbb7###!!$,;;!!!!!!!!!  """""""""..t|[+WZ[_[hij[klp[qWrWrss''[JZ[[	6K#=>>==&&"!$(
 (
$
 /3.U.UVr.s.s(s(s(s(s(s(s% (EXZ[[ OOM1==$*d dgopvgw wxxx''(9>JJ"!$(!23F!G#
 #
 *.)K)KLc)d)d#d#d#d#d#d#d  ##$<jII*_ _bjkqbr rsss:h//.5*+?)))+. ("!$ II&677(
 
  yy,,yy11
 

 ==d>N>N`f>g>ghhhhhhhh%%h999r  c                 *    |                                  S N)r  )r  s    r  r  z
ndax.nonce  s      """r  r~   GETc                     | j         d         |         dz   |                     ||          z   }|                     ||                     |                    }|dk    r|dk    r/| j        dz   | j        z   }	|                     |	          }
dd|
z   i}n=|dk    r7|                     | j        d	          }|d
|i}|                     |d	          }|r|d| 	                    |          z   z  }n|dk    r| 
                                 |                     | j        d          }|t          |                                           }|| j        z   | j        z   }	|                     |                     |	          |                     | j                  t$          j                  }|| j        || j        d}nd|i}|dk    rd|d<   |                     |          }n|r|d| 	                    |          z   z  }||||dS )Nr   re  r~   r   :AuthorizationzBasic r   r#  r"  ?r   r!  )NonceAPIKey	Signaturer  APTokenPOSTzapplication/jsonzContent-Type)urlmethodbodyheaders)r  implode_paramsr  extract_paramsr   r   string_to_base64r(  r  	urlencoder%  r  r  r   r   hmacencoder   hashlibsha256r  )r  pathr   r  r,  r  r  r  queryauthauth64r#  r!  r  	signatures                  r  signz	ndax.sign  s-   is#c)D,?,?f,M,MM		&$"5"5d";";<<(??~%%zC'$-7..t44#X%6 ***"&"2"24<AR"S"S".)?G !IIe->??E 3sT^^E2222I++---++DL.IIL#DJJLL))tx'$+5 IIdkk$&7&7T[9Q9QSZSabb	""k!*"h	  | *<'yy'' 73!6!666CfdwOOOr  c
                 J   |dk    rt          | j        dz   |z             |d S |                     |d          }
|
f|
dk    r`| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         ||           t          |          d S )Ni   errormsg r   r   )r   r	  r(  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   )r  rB  reasonr  r  r  r  r.  requestHeadersrequestBodymessagefeedbacks               r  handle_errorszndax.handle_errors	  s    3;;%dgmd&:;;;4
 ""8Z88gmmw}t+H001I7T\]]]001I4QYZZZ)))tr  )Nr  r  r   r  r   r  )A__name__
__module____qualname__r  r0  r   rV  r   r   rZ  r  r	   r  r  r
   r   r  r   r  r  r  r  r  r   r  r  r   r  r   r  r  r+  r   rE  r   rI  rV  r   rj  r   r   rp  r   rv  rz  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  rc   r  r(  r4  __classcell__)r  s   @r  r   r      s       C C C C CJ $& . . . .` -/ @ @: @ @ @ @D *, :, :,V :, :, :, :,x:
f :
 :
 :
 :
x lu   GP   dm    B @DB )7 )7S )7 )7S\ )7 )7 )7 )7V@ @6 @V @ @ @ @D 68 .3 .3 .3F .3 .3 .3 .3`
 
 
4 
 
 
 
. 8<$]ajl 'L 'L 'LC 'LWZ 'Lquvzq{ 'L 'L 'L 'LRc c c5 c c c cJ <@d[] A A AS A Abfglbm A A A A8 +-  g    >) ) ) ) )" *, 1, 1, 1, 1, 1, 1,f3 3 3$3
 3
 3
 3
 3
 3
j .2SW`b ,C ,Cs ,C# ,CS ,C ,C ,C ,C\	: 	: 	:\ \ \5 \ \ \ \| mqy{ >2 >2 >2I >2Y >2X] >2fi >2 >2 >2 >2@ fjx|  FH +2 +23 +2 +29 +2I +2_b +2ru +2 +2 +2 +2Z 37TX\eg QA QAC QAs QARU QA QA QA QAf 59  c    @ 9=R ! !S !# ! ! ! !F 59tZ^gi JA JAc JA JATW JAnrsxny JA JA JA JAX 04$UYbd XA XA XAC XAs XAimnsit XA XA XA XAt 8<B G2 G2C G2 G2 G2 G2 G2R ?CQUdhqs N? N?3 N? N?3 N?^a N? N? N? N?` =? !> !> !> !> !> !>F 
  
h  
  
  
  
D >@ 
T 
T 
T 
T 
T 
T 04$UYbd 6I 6I 6IC 6Is 6Iimnyiz 6I 6I 6I 6Ip 37TX\eg 0I 0IC 0Is 0IRU 0Ilpq|l} 0I 0I 0I 0Id.: .: .: .:`]
 ]
x ]
; ]
 ]
 ]
 ]
~ EIQS U: U:3 U: U: U: U: U:n# # # &eBSW ,P ,P ,P ,P\      r  r   )$ ccxt.async_support.base.exchanger   ccxt.abstract.ndaxr   r!  r  ccxt.base.typesr   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    r  r  <module>rA     s   6 5 5 5 5 5 * * * * * *   j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j  j       * * * * * * 0 0 0 0 0 0 & & & & & & . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %T$ T$ T$ T$ T$8[ T$ T$ T$ T$ T$r  