
    !:h                    X   d dl mZ d dlm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 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! 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* d dl+m,Z,  G d dee      Z-y)    )Exchange)ImplicitAPIN)AccountAnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)OrderNotFound)RateLimitExceeded)OnMaintenance)CancelPending)	TICK_SIZE)Precisec                       e Zd Zdef 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dDde
dedefd	Zi fd
edefdZdi fdedefdZdi fd
ededefdZdDde
dedefdZddi fd
edededee   fdZdddi fd
edededee   fdZdDdedefdZdefdZi fdefdZdi fd
ededede de!f
dZ"di fded
e#fdZ$di f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ddi fd
e#dededee&   fd"Z(dddi fd
e#dededee&   fd#Z)dddi fded
e#dedefd$Z*d%e#fd&Z+dDd'e
dede&fd(Z,i fd)ede d*ed+ede-f
d,Z.dDd-e
d.e/de-fd/Z0d%e#de#fd0Z1di fd)ede d1ede2fd2Z3i fdee4   fd3Z5dddi fd)e#dededee2   fd4Z6dddi fd)e#dededee2   fd5Z7dddi fd)e#dededee2   fd6Z8d%e#fd7Z9dDd8e
d.e/de2fd9Z:dddi fd
e#dedefd:Z;d;d<i ddfd=Z<d)e=d>ed?ed@edAe
dBefdCZ> xZ?S )Enovadax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d0d
d1dd2dd3d
d4dd5dd6dd7dd8dd9d
d:d
i d;d
d<d
d=d
d>d
d?d
d@d
dAddBddCddDddEd
dFd
dGdHdIddJd
dKd
dLd
d
dddMdNdOdPdQdRdSdTdUdVdWdXdXdYdZd[gd\d]d^d_d`d`d`dad`d`dadadbid`ddcdd`d`d`ddcdd	daded`dddadcdcdfdgdYdhd
d| j	                  di      | j	                  dj      dkidddlt
        i dmt        dnt        dot        dpt        dqt        drt        dst        dtt        dut        dvt        dwt        dxt        dyt         dzt         d{t         d|t         d}t         t"        t         t         t$        t         t         t"        d~i dddidd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
dddd
dd
d
d
d
dd
d d
d
d
dd
dddd
d
d
dd
ddd`dd
d
d
ddd id	d d dd d ddd      S )Nr)   NovaDAXBR
   v1CORSspotTmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsemulatedfetchWithdrawalsreduceMarginsetLeveragesetMarginMode)setPositionModetransferwithdrawONE_MINFIVE_MINFIFTEEN_MINHALF_HOUONE_HOUONE_DAYONE_WEEONE_MON)1m5m15m30m1h1d1w1Mzchttps://user-images.githubusercontent.com/1294454/92337550-2b085500-f0b3-11ea-98e7-5794fb07dd3b.jpgzhttps://api.novadax.com)publicprivatezhttps://www.novadax.com.brzhttps://doc.novadax.com/pt-BR/z*https://www.novadax.com.br/fees-and-limitsz"https://www.novadax.com.br/?s=ccxt)logoapiwwwdocfeesreferralget      )zcommon/symbolzcommon/symbolszcommon/timestampzmarket/tickerszmarket/tickerzmarket/depthzmarket/tradeszmarket/kline/history   )	z
orders/getzorders/listzorders/fillzorders/fillszaccount/getBalancezaccount/subszaccount/subs/balancezaccount/subs/transfer/recordzwallet/query/deposit-withdraw2   )zorders/createzorders/batch-createzorders/cancelzorders/batch-cancelzorders/cancel-by-symbolzaccount/subs/transferzwallet/withdraw/coinzaccount/withdraw/coin)r   posttradingz0.005z0.0025)	tierBased
percentagetakermaker)apiKeysecretA99999A10001A10002A10003A10004A10005A10006A10007A10011A10012A10013A30001A30002A30003A30004A30005A30006)A30007A30008A30009A30010A30011A30012A40004)exactbroadvolumeamountfillResponseFromRequest)rZ   rv   )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   r   daysBackCanceledr   r   r   r   r   )	sandboxr=   createOrdersrY   r]   r\   r_   rF   rZ   )linearinverse)r1   r3   r4   )idname	countries	rateLimitversionhas
timeframesurlsr   r   requiredCredentialsprecisionMode
exceptionsoptionsfeatures)deep_extendsuperr)   describeparse_numberr&   r   r   r   r#   r   r   r   r   r$   r"   r!   r    r%   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/novadax.pyr   znovadax.describe   s'   gt = ? HHH %H 	H
 %H %H UH tH $UH  H /H ,UH 0H tH (H  '!H" (#H$ "4%H&  'H( )H* +E+H, )%-H. $T/H0 '1H2 (3H4 &u5H6 (7H8 1%9H:  ;H< +D=H> &u?H@ #EAHB *5CHD $UEHF "5GHH *5IHJ +EKHL  MHN %eOHP QHR !%SHT  UHV dWHX +EYHZ "4[H\ d]H^ !$_H` taHb #DcHd  eHf 'gHh $UiHj !%kHl *5mHn (oHp %eqHr )%sHt tuHv wHx TyHz t{H| "5}H~ #EH@ $ZAHB #DCHD EHF uGHH  IHJ $)  OHT   $!	 ~78 44 E@ )**+,-*+)*())*01	 '(')'((*./()018:9:
 *+/1)*/135120112	$L !&"&!..w7!..x8	 $ 'm j m	
 1 / . . / i i m m l l  l!" l#$ l%& 0**+**/369B h .t	  %&+(,,0,0).+06: $)#("'#(	( #($)$)+/27/4#'+$. %)&+!$$*%+*/& ',#($)*/	# ',!%#($)*/( ',!$$*%+#($)*/$ ',!$$*,-%+#($)*/	*  #CDL ##
 ##UNEQB
 Q Q	    c                 H    | j                  |      }| j                  |d      S )aS  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://doc.novadax.com/en-US/#get-current-system-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        data)publicGetCommonTimestampsafe_integerr   paramsresponses      r   
fetch_timeznovadax.fetch_time3  s)     008   622r   c                 l    | j                  |      }| j                  |dg       }| j                  |      S )a   
        retrieves data on all markets for novadax

        https://doc.novadax.com/en-US/#get-all-supported-trading-symbol

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   )publicGetCommonSymbols
safe_valueparse_markets)r   r   r   r   s       r   fetch_marketsznovadax.fetch_marketsF  s9     ..v6( x4!!$''r   marketc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }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|dk(  dddd d d d d d d | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  dd d d| j	                  |d      d dd d d| j	                  |d      d ddd |d 
S )!NbaseCurrencyquoteCurrencysymbolstatusr   /basequotesettlebaseIdquoteIdsettleIdtyper1   Tr2   Fr3   r4   r5   activeONLINEcontractr   amountPrecisionpricePrecision)r   price)minmaxminOrderAmountminOrderValue)r   r   r  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsafe_currency_coder   parse_precisionsafe_number)r   r   r  r  r   r  r  r   s           r   parse_marketznovadax.parse_marketf  s   !!&.9""6?;fh/&&v.''0!!&(31
"1
dSj5(1
 D1
 U	1

 d1
 f1
 w1
 1
 F1
 D1
 e1
 E1
 e1
 e1
 v)1
  !1
" d#1
$  "++D,@,@AQAQRXZkAl,mn**4+?+?@P@PQWYi@j+kl  
  ++F4DE
  
  ++FOD$ a1
 1	
r   Ntickerc                 4   | j                  |d      }| 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d ||	|d|      S )N	timestampr   _open24h	lastPricebaseVolume24hquoteVolume24hdatetimehighhigh24hlowlow24hbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechanger   average)
baseVolumequoteVolumer  )r   r  safe_symbolsafe_tickeriso8601)
r   r!  r   r#  marketIdr   r3  r5  r9  r:  s
             r   parse_tickerznovadax.parse_ticker  s   " %%fk:	##FH5!!(FC8	24%%fo>
&&v/?@ !
f!
!
 Y/!
 D$$VY7	!

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

        https://doc.novadax.com/en-US/#get-latest-ticker-for-specific-pair

        :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   r   )load_marketsr   publicGetMarketTickerextend	safe_dictr?  )r   r   r   r   requestr   r   s          r   fetch_tickerznovadax.fetch_ticker  sr     	V$fTl
 --dkk'6.JK& ~~h3  v..r   symbolsc                 &   | j                          | j                  |      }| j                  |      }| j                  |dg       }i }t	        dt        |            D ]   }| j                  ||         }|d   }|||<   " | j                  |d|      S )a#  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://doc.novadax.com/en-US/#get-latest-tickers-for-all-trading-pairs

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   r   r   )rA  market_symbolspublicGetMarketTickersr   rangelenr?  filter_by_array_tickers)	r   rG  r   r   r   resultir!  r   s	            r   fetch_tickersznovadax.fetch_tickers  s     	%%g...v6* x4q#d)$ 	$A&&tAw/FH%F#F6N	$ ++FHgFFr   r   c                    | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |d      }| j                  ||d   |dd      S )a-  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://doc.novadax.com/en-US/#get-market-depth

        :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   r   r   r#  bidsasks)rA  r   publicGetMarketDepthrC  r   r   parse_order_book)	r   r   r   r   r   rE  r   r   r#  s	            r   fetch_order_bookznovadax.fetch_order_book  s     	V$fTl
 $GG,,T[[&-IJ( x4%%dK8	$$T6(+;YPVWWr   tradec                 B   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |	|d      }
| j                  |d	      }| j                  |d
      }d }|8| j                  |d      }| j	                  |      }| j                  |d      |d}| j                  |||| j                  |      |
d |||d |||d|      S )Nr   orderIdr#  sider  r   r   r$  rolefeefeeCurrency	feeAmountr  currency)r   orderr#  r)  r   r  rZ  r  r   r  takerOrMakerr\  r  )r  r   safe_string_lowerr;  r  
safe_trader=  )r   rW  r   r   rY  r#  rZ  priceStringamountStringr>  r   rb  	feeStringr\  feeCurrencyIdfeeCurrencyCodes                   r   parse_tradeznovadax.parse_tradeG  sO   V eT*""5)4%%e[9	%%eV4&&ug6''x8##E84!!(FC8--eV<$$UE2	  ,,UMBM"55mDO((<+C "Y/ "( 
  	r   sincec                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a  
        get the list of most recent trades for a particular symbol

        https://doc.novadax.com/en-US/#get-recent-trades

        :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   r   r   )rA  r   publicGetMarketTradesrC  	safe_listparse_trades)	r   r   rk  r   r   r   rE  r   r   s	            r   fetch_tradesznovadax.fetch_trades  s     	V$fTl
 $GG--dkk'6.JK ~~h3  vue<<r   r   c                    | j                          | j                  |      }|d   | j                  | j                  ||      d}| j	                  |      }| j                         }	|d}||	||z  z
  |d<   |	|d<   n1| j                  |dz        }
|
|d<   | j                  |
||z        |d<   | j                  | j                  ||            }| j                  |dg       }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://doc.novadax.com/en-US/#get-kline-data

        :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   uniti  fromtoi  r   )rA  r   r  r   parse_timeframesecondsparse_to_intsumpublicGetMarketKlineHistoryrC  rn  parse_ohlcvs)r   r   	timeframerk  r   r   r   rE  durationnow	startFromr   r   s                r   fetch_ohlcvznovadax.fetch_ohlcv  s    	V$Tl$$T__iK
 ''	2lln=E=!EH$44GFOGDM))%$,7I'GFO HHY0@AGDM33DKK4PQ( ~~h3  vy%GGr   c           	      2   | j                  | j                  di       }| j                  |dd      }| j                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  |d      | j	                  ||      gS )	NrZ   r   r   score	openPrice	highPricelowPrice
closePrice)r   r   r  safe_timestampr  )r   ohlcvr   r   volumeFields        r   parse_ohlcvznovadax.parse_ohlcv  s     //$,,bA&&w(Cw/UK0UK0UJ/UL1UK0
 	
r   c                    | j                  |dg       }|d d d}t        dt        |            D ]~  }||   }| j                  |d      }| j	                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d	      |d
<   |||<    | j                  |      S )Nr   )r  r#  r)  r   r`  balancetotal	availablefreeholdused)r   rK  rL  r  r  accountsafe_balance)	r   r   r   rN  rO  r  
currencyIdcoder  s	            r   parse_balanceznovadax.parse_balance  s    x4

 q#d)$ 	#A1gG))':>J**:6DllnG#//CGG"..wDGFO"..w?GFO"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )a^  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://doc.novadax.com/en-US/#get-account-balance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )rA  privateGetAccountGetBalancer  r   s      r   fetch_balanceznovadax.fetch_balance  s3     	33F; !!(++r   r  rZ  r   r  c                    | j                          | j                  |      }|j                         }|j                         }	|d   |	d}
| j                  |dd      }|(|dk(  s|dk(  rut	        | j
                  dz   |z   d	z         |d
k(  rd}n|dk(  rd}|	dk(  rdnd}| j                  |d|      |
d<   | j                  ||      |
d<   | j                  |ddg      }|d
k(  s|dk(  r+| j                  ||      |
d<   | j                  ||      |
d<   n|dk(  s|dk(  r|	dk(  r| j                  ||      |
d<   n|	dk(  rd}d}| j                  |ddd      \  }}| j                  |dd      }| j                  |d      }|| j                  ||      }ny|re|t        | j
                  dz         | j                  |      }| j                  |      }t        j                   ||      }| j                  ||      }n| j                  ||      }||
d<   ||
d<   | j#                  | j%                  |
|            }| j'                  |di       }| j)                  ||      S )a  
        create a trade order

        https://doc.novadax.com/en-US/#order-introduction

        :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 you want to trade in units of the 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.cost]: for spot market buy orders, the quote quantity that can be used alternative for the amount
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r   rZ  r   	stopPriceN
STOP_LIMITSTOP_MARKETz2 createOrder() requires a stopPrice parameter for z ordersLIMITMARKETBUYLTEGTEoperatorr  r   SELLTr=   !createMarketBuyOrderRequiresPricer  valuea	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr  r   )rA  r   uppersafe_value_2r   r   r  price_to_precisionomitamount_to_precisionhandle_option_and_paramssafe_number_2cost_to_precisionr!   number_to_stringr'   
string_mulprivatePostOrdersCreaterC  rD  parse_order)r   r   r  rZ  r   r  r   r   uppercaseTypeuppercaseSiderE  r   defaultOperatorquoteAmountr  r  rf  re  costRequestr   r   s                        r   create_orderznovadax.create_order1  s    	V$



Tl!
 ((M-=M3Q'2f(fiv(v  zC  )C  D  D' ,(* -(5(>eUO"&"2"26:"WGJ#'#:#:6<#PGK YYv'DEFW$-<*G#66vuEGG $ 8 8 HGHx']m-K&$($<$<VV$L!%'"481<@<Y<YZ`bo  rU  W[  =\916))&&'B662#"&"8"8"FK6}*477  6A  ,A  B  B'+'<'<V'D&*&;&;E&B&-&8&8{&S&*&<&<V[&Q"&"8"8"HK#. '//GV0LM0 ~~h3f--r   r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j	                  |      S )al  
        cancels an open order

        https://doc.novadax.com/en-US/#cancel-an-order

        :param str id: order id
        :param str symbol: not used by novadax cancelOrder()
        :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   )rA  privatePostOrdersCancelrC  rD  r  r   r   r   r   rE  r   r   s          r   cancel_orderznovadax.cancel_order  s^     	"
 //GV0LM ~~h3%%r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j	                  |      S )a  
        fetches information on an order made by the user

        https://doc.novadax.com/en-US/#get-order-details

        :param str id: order id
        :param str symbol: not used by novadax fetchOrder
        :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   )rA  privateGetOrdersGetrC  rD  r  r  s          r   fetch_orderznovadax.fetch_order  s^     	"
 ++DKK,HI, ~~h3%%r   c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a(  
        fetches information on multiple orders made by the user

        https://doc.novadax.com/en-US/#get-order-history

        :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>`
        Nr   r   r   fromTimestampr   )rA  r   privateGetOrdersListrC  rn  parse_orders	r   r   rk  r   r   rE  r   r   r   s	            r   fetch_ordersznovadax.fetch_orders  s     	
 [[(F &tGH$GG',GO$,,T[[&-IJ0 ~~h3  vue<<r   c           	      R    ddi}| j                  |||| j                  ||            S )a  
        fetch all unfilled currently open orders

        https://doc.novadax.com/en-US/#get-order-history

        :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   z-SUBMITTED,PROCESSING,PARTIAL_FILLED,CANCELINGr  rC  r   r   rk  r   r   rE  s         r   fetch_open_ordersznovadax.fetch_open_orders  s5     E
   t{{7F7STTr   c           	      R    ddi}| j                  |||| j                  ||            S )a/  
        fetches information on multiple closed orders made by the user

        https://doc.novadax.com/en-US/#get-order-history

        :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   zFILLED,CANCELED,REJECTEDr  r  s         r   fetch_closed_ordersznovadax.fetch_closed_orders  s5     0
   t{{7F7STTr   c                     | j                          d|i}| j                  | j                  ||            }d}|| j                  |      }| j	                  |dg       }	| j                  |	|||      S )a  
        fetch all the trades made from a single order

        https://doc.novadax.com/en-US/#get-order-match-details

        :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   Nr   )rA  privateGetOrdersFillrC  r   r   ro  )
r   r   r   rk  r   r   rE  r   r   r   s
             r   fetch_order_tradesznovadax.fetch_order_trades.  s}     	"
 ,,T[[&-IJ[[(Fx4,   vue<<r   r   c                 <    dddddddd}| j                  |||      S )Nr3  closedcanceledrejected)	SUBMITTED
PROCESSINGPARTIAL_FILLED	CANCELINGFILLEDCANCELEDREJECTEDr  r   r   statusess      r   parse_order_statusznovadax.parse_order_status[  s5     $""
 &&99r   ra  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }	| j	                  |d	      }
| j                  |d
      }| j                  |d      }d }| j                  |d      }||d d}| j                  |d      }| j                  ||d      }| j                  i d|dd d|d	|
d| j                  |
      dd d|d|dd dd d|d|d| j                  |d      d|d|d|d|d |	|d d|      S )Nr   r   r  filledValuer  r  rZ  r   r#  averagePricefilledAmount	filledFeer_  r   r$  clientOrderIdr  r)  lastTradeTimestampr   postOnlyr   r  r  r8  filled)	remainingr   r\  trades)	r  safe_string_2rc  r  r   r  r;  
safe_orderr=  )r   ra  r   r   r   r  r  r  rZ  r   r#  r8  r  r\  feeCostr>  r   s                    r   r  znovadax.parse_orderg  s#   8 eT*!!%2  0!!%@%%eV4%%eV4(()9)9%)JK%%e[9	""5.9!!%8""5+6 C ##E84!!(FC8  
" 
T 
 E 
 	 

 Y/ 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
 D,,UK@ 
 f 
 D 
  w! 
" f# 
$ + 
, - 	r   r  fromAccount	toAccountc                    | j                          | j                  |      }|dk7  r|dk7  rt        | j                  dz         |dk(  rdnd}| j	                  ||      |d   |dk(  r|n||d}| j                  | j                  ||            }	| j                  |	|      }
| j                  | j                  di       }| j                  |dd	      }|r||
d
<   ||
d<   ||
d<   |
S )a  
        transfer currency internally between wallets on the same account

        https://doc.novadax.com/en-US/#get-sub-account-transfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        mainzH transfer() supports transfers between main account and subaccounts onlyzmaster-transfer-inzmaster-transfer-outr   )transferAmountr`  subIdtransferTyperv   r   Tr  r  r   )rA  r`  r   r   currency_to_precisionprivatePostAccountSubsTransferrC  parse_transferr   r   	safe_bool)r   r  r   r  r  r   r`  r  rE  r   rv   transferOptionsr   s                r   rv   znovadax.transfer  s    	==&& Y&%8*t tuu )4v(=#DY"88vF #'+?#?Yk 	
 66t{{7F7ST &&x://$,,
BG"&..B[]a"b"&1H]#$-H[!!'HXr   rv   r`  c           
          | j                  |d      }| j                  |d      }| j                  d |      }||d |d d d d |d	S )Nr   message)	r  r   r   r`  r  r  r#  r)  r   )r  r  )r   rv   r`  r   r   currencyCodes         r   r  znovadax.parse_transfer  s_     h/!!(I6..tX>$

 
	
r   c                 0    ddi}| j                  ||d      S )NSUCCESSpendingfailedr  r  s      r   parse_transfer_statusznovadax.parse_transfer_status  s%    y
 &(;;r   addressc                    | j                  ||      \  }}| j                          | j                  |      }|d   | j                  ||      |d}|||d<   | j	                  | j                  ||            }| j                  ||      S )a  
        make a withdrawal

        https://doc.novadax.com/en-US/#send-cryptocurrencies

        :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   )r  r   wallettag)handle_withdraw_tag_and_paramsrA  r`  r  privatePostAccountWithdrawCoinrC  parse_transaction)	r   r  r   r  r  r   r`  rE  r   s	            r   rw   znovadax.withdraw  s     99#vFV==&TN00v>

 ? GEN66t{{7F7ST %%h99r   c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]A  }||   }| j	                  |d      }| j	                  |d      }|j                  ||d|d       C |S )a]  
        fetch all the accounts associated with a profile

        https://doc.novadax.com/en-US/#get-sub-account-list

        :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
        r   r   r  
subAccountN)r   r  r`  r  )privateGetAccountSubsr   rK  rL  r  append)	r   r   r   r   rN  rO  r  	accountIdr  s	            r   fetch_accountsznovadax.fetch_accounts  s     --f5 x4q#d)$ 		A1gG((':I##G\:DMM 	 			 r   c           	      R    ddi}| j                  |||| j                  ||            S )a  
        fetch all deposits made to an account

        https://doc.novadax.com/en-US/#wallet-records-of-deposits-and-withdraws

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :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  coin_infetch_deposits_withdrawalsrC  r   r  rk  r   r   rE  s         r   fetch_depositsznovadax.fetch_deposits=  s5     I
 ..tUE4;;wX^C_``r   c           	      R    ddi}| j                  |||| j                  ||            S )a$  
        fetch all withdrawals made from an account

        https://doc.novadax.com/en-US/#wallet-records-of-deposits-and-withdraws

        :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  coin_outr  r  s         r   fetch_withdrawalsznovadax.fetch_withdrawalsN  s5     J
 ..tUE4;;wX^C_``r   c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )av  
        fetch history of deposits and withdrawals

        https://doc.novadax.com/en-US/#wallet-records-of-deposits-and-withdraws

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   r`  sizer   )rA  r`  $privateGetWalletQueryDepositWithdrawrC  rn  parse_transactions)	r   r  rk  r   r   rE  r`  r   r   s	            r   r  z"novadax.fetch_deposits_withdrawals_  s     	
 }}T*H"*4.GJ#GFO<<T[[RX=YZ, ~~h3&&tXueDDr   c                 ~    |j                  d      }| j                  |d|      }ddddd}| j                  |||      S )N r   r  okr  )Pending
confirmingr  FAIL)splitr  )r   r   partsr  s       r   parse_transaction_statusz novadax.parse_transaction_status  sP    
 S!!!%F3 #	
 &&99r   transactionc                    | j                  |dd      }| j                  |d      }|dk(  rd}n|dk(  rd}| j                  |d      }| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j	                  ||      }| j                  | j                  |d            }| j                  |d      }i d|d|d|d|d|d	|d|dd d|d|dd d|d|d|
d|d|	d| j                  |	      d d d d d ddS )Nr   r   r  COIN_INdepositCOIN_OUTrw   r   r  
addressTagtxHash	createdAt	updatedAtr`  statechainr  network	addressToaddressFromr  tagTotagFromr   updatedtxidr#  r)  )r`  r  rate)commentinternalr\  )r  r  r  r   r  r!  r=  )r   r"  r`  r   r  r   r  r  r3  r#  r2  r  r  r   r-  s                  r   r  znovadax.parse_transaction  s   4 T6:V49DZD!!+x8"";	:{L9X6%%k;?	##K=%%k:>
&&z8<..t/?/?W/UV"";8
K
"
 
 f	

 w
 w
 
 4
 3
 S
 t
 f
 D
 w
 D
  !
" Y/#
$  )
 	
r   c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a  
        fetch all trades made by the user

        https://doc.novadax.com/en-US/#get-order-history

        :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>`
        Nr   r   r   r  r   )rA  r   privateGetOrdersFillsrC  rn  ro  r  s	            r   fetch_my_tradesznovadax.fetch_my_trades  s     		
 [[(F &tGH$GG',GO$--dkk'6.JK, ~~h3  vue<<r   r   GETc                 4   d| j                   z   dz   | j                  ||      z   }| j                  d   |   |z   }| j                  || j	                  |            }	|dk(  r|	r/|d| j                  |	      z   z  }n|dk(  r| j                          t        | j                               }
| j                  |
d}d }|dk(  r8| j                  |	      }| j                  | j                  |      d      }d	|d
<   n9|	r|d| j                  |	      z   z  }| j                  | j                  |	            }|dz   |z   dz   |z   dz   |
z   }| j                  | j                  |      | j                  | j                        t         j"                        |d<   ||||dS )Nr   r   r   ?r   )zX-Nova-Access-KeyzX-Nova-TimestampPOSTmd5zapplication/jsonzContent-Type
zX-Nova-Signature)urlmethodbodyheaders)r   implode_paramsr   r  extract_params	urlencodecheck_required_credentialsstrmillisecondsr   jsonhashencodekeysorthmacr   hashlibsha256)r   pathr   rA  r   rC  rB  rE  r@  queryr#  queryStringauths                r   signznovadax.sign  s   $s*T-@-@v-NNiis#g-		&$"5"5d";<(?sT^^E222I++-D--/0I%)[[$-G Kyy'"iiD(95A*<'3!666C"nnT\\%-@AD=7*T1K?$FRD*.))DKK4Et{{SWS^S^G_ahaoao*pG&'fdwOOr   reasonr@  rA  rC  rB  c
                    |y | j                  |d      }
|
dk7  ro| j                  |d      }| j                  dz   |z   }| j                  | j                  d   |
|       | j	                  | j                  d   ||       t        |      y )Nr  A10000r  r  r   r   )r  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  rV  r@  rA  rC  rB  r   requestHeadersrequestBody	errorCoder  feedbacks                r   handle_errorsznovadax.handle_errors9  s     $$Xv6	 &&x;Gww}t+H001I9V^_001I7T\]))r   )N)@__name__
__module____qualname__r   r   r	   r   r   r
   r   dictr   r   r?  rH  rF  r   r   rP  r   rV  r   rj  rp  listr  r  r   r  r  r   r   floatr   r  r   r  r  r   r  r  r  r  r  r  r   rv   r   r  r  r   rw   r   r  r  r  r  r!  r  r9  rU  intr_  __classcell__)r   s   @r   r)   r)      s   R# Rh !# 3s 3& $& ($v, (@8
4 8
F 8
t-4 - -6 -^ 02 #/3 #/f #/J 04B 'GW 'G7 'GR :>b (Xs (X3 (XY (XTK Kv K KZ 6:UW  =3  =s  =#  =\`af\g  =D 26DW[df 3H# 3Hc 3HQT 3Hkoptku 3Hj
 
4 
2) )$ $& ,( ,6 gksu \.3 \.i \.y \.RW \.`c \.| 37r &s &C &8 26b &&c &&3 &&P *.Dt\^ 7=3 7=c 7= 7=cghmcn 7=r /3TXac U U3 Uc Uhlmrhs U" 154VZce U# US UPS Ujnotju U" 9=4^bkm +=S +=# +=S +=X[ +=Z
: 
:E Ev E EN [] )S )% )c )c )an )V
t 
x 
= 
.<C <C < DHPR :S :% :# :Wb :B %' $4= $L *.Dt\^ a3 ac a acghsct a" -1tRV_a ac a aC afjkvfw a" 6:[_hj 1Es 1E# 1EUX 1Eost  pA 1Ef:s :C
T C
X C
Q\ C
J -1tRV_a 6=c 6= 6=C 6=p &eBSW P6# s  c TX `c r   r)   ).ccxt.base.exchanger   ccxt.abstract.novadaxr   rO  ccxt.base.typesr   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   r   r   r   r    r!   r"   r#   r$   r%   ccxt.base.decimal_to_precisionr&   ccxt.base.preciser'   r)    r   r   <module>rp     sq    ( -  y  y  y  y  y  * 0 - . - . ' & . ) * . * * 4 %ih ir   