
    i                     \   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 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,dS )    )Exchange)ImplicitAPIN)Account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)CancelPending)RateLimitExceeded)OnMaintenance)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi fdee         fdZdefdZd8d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d8d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d8d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# Z)d8dede$fd$Z*i fd%eded&ed'ede+f
d(Z,d8d)e-fd*Z.d+ Z/di fd%edefd,Z0i fdee1         fd-Z2dddi fd%e!dededee3         fd.Z4dddi fd%e!dededee3         fd/Z5dddi fd%e!dededee3         fd0Z6d1 Z7d8d)e-de3fd2Z8dddi fd	e!dedefd3Z9d4d5i ddfd6Z:d7 Z; xZ<S )9novadaxc                    |                      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
dCdDdEddFd
dGd
dHd
dId
dJddKddLdMdNdOdPdQdRdSdTdUdVdVdWdXdYgdZd[d\d]d^d^d^d_d^d^d_d_d`id^ddadd^d^d^ddadb	d_dcd^ddd_dadadddedWdfd
d|                     dg          |                     dh          diidddjt
          i dkt          dlt          dmt          dnt          dot          dpt          dqt          drt          dst          dtt          dut          dvt          dwt           dxt           dyt           dzt           d{t           t"          t           t           t$          t           t           t"          d|i d}d~diddi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fetchPositions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)rX   rp   )idname	countries	rateLimitversionhas
timeframesurlsr   r   requiredCredentialsprecisionMode
exceptionsoptions)deep_extendsuperr(   describeparse_numberr%   r   r   r   r#   r   r   r   r   r$   r!   r    r   r"   )self	__class__s    `/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/novadax.pyr   znovadax.describe   s   gt 4 4 = = ? ? DDD %D 	D
 %D %D UD tD $UD  D /D ,UD 0D tD (D  '!D" (#D D$ "4%D&  'D( )D* +E+D, )%-D. $T/D0 '1D2 (3D4 &u5D6 (7D8 1%9D:  ;D< +D=D> &u?D@ #EADB *5CDD $UED D DF "5GDH *5IDJ +EKDL  MDN %eODP QDR !%SDT  UDV dWDX +EYDZ "4[D\ d]D^ !$_D` taDb #DcDd  eDf !%gD D Dh %eiDj )%kDl tmDn oDp TqDr tsDt "5uDv #EwDx $ZyDz #D{D| }D~ uD@  ADB "5CDD DEDF DGD DL   $!	 	 ~78  44 E@  )**+,-*+)*())*01	 	 '(')'((*./()018:9:
 
 *+/1)*/135120112	 	 $ $L !&"&!..w77!..x88	  $ $ 'm j m	
 1 / . . / i i m m l l  l!" l#$ l%& 0**+**/3  69 B h .t	 m~B
 ~B
 ~ ~ ~	    c                 h   K   |                      |           d{V }|                     |d          S )aW  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: 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
        Ndata)publicGetCommonTimestampsafe_integerr   paramsresponses      r   
fetch_timeznovadax.fetch_time   sE       66v>>>>>>>>   6222r   returnc                    K   |                      |           d{V }|                     |dg           }|                     |          S )a$  
        retrieves data on all markets for novadax
        :see: 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
        Nr   )publicGetCommonSymbols
safe_valueparse_markets)r   r   r   r   s       r   fetch_marketsznovadax.fetch_markets   sX       44V<<<<<<<<( x44!!$'''r   c                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                      |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 |                     |                     |                      |d                              |                     |                     |                      |d                              dd d d|                     |d          d dd d d|                     |d          d ddd |d 
S )!NbaseCurrencyquoteCurrencysymbolstatusr   /basequotesettlebaseIdquoteIdsettleIdtyper/   Tr0   Fr1   r2   r3   activeONLINEcontractlinearamountPrecisionpricePrecision)r   price)minmaxminOrderAmountminOrderValue)leverager   r   cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)safe_stringsafe_currency_coder   parse_precisionsafe_number)r   marketr   r   r   r   r   r   s           r   parse_marketznovadax.parse_market  sg   !!&.99""6?;;fh//&&v..''00!!&(3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,@,@AQAQRXZkAlAl,m,mnn**4+?+?@P@PQWYi@j@j+k+kll    
  ++F4DEE 
   
  ++FODD  $ a1
 1
 1
 1	
r   Nr   c                    |                      |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|          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   tickerr   r  marketIdr   r  r  r  r  s
             r   parse_tickerznovadax.parse_tickerI  s   " %%fk::	##FH55!!(FC88	2244%%fo>>
&&v/?@@ !
f!
!
 Y//!
 D$$VY77	!

 4##FH55!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %&)!
 !
 !
* +  	r   r   c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        Nr   r   r   )load_marketsr   publicGetMarketTickerextend	safe_dictr  )r   r   r   r   requestr   r   s          r   fetch_tickerznovadax.fetch_tickerx  s       !!!!!!!!!V$$fTl
 33DKK4P4PQQQQQQQQ& ~~h33  v...r   symbolsc                   K   |                                   d{V  |                     |          }|                     |           d{V }|                     |dg           }i }t	          dt          |                    D ]*}|                     ||                   }|d         }|||<   +|                     |d|          S )a'  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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>`
        Nr   r   r   )r   market_symbolspublicGetMarketTickersr   rangelenr  filter_by_array_tickers)	r   r&  r   r   r   resultir  r   s	            r   fetch_tickersznovadax.fetch_tickers  s       !!!!!!!!!%%g..44V<<<<<<<<* x44q#d))$$ 	$ 	$A&&tAw//FH%F#F6NN++FHgFFFr   limitc                 |  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |di           }|                     |d          }|                     ||d         |dd          S )	a1  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        Nr   r   r0  r   r  bidsasks)r   r   publicGetMarketDepthr"  r   r   parse_order_book)	r   r   r0  r   r   r$  r   r   r  s	            r   fetch_order_bookznovadax.fetch_order_book  s       !!!!!!!!!V$$fTl
 $GG224;;w3O3OPPPPPPPP( x44%%dK88	$$T6(+;YPVWWWr   c                    |                      |d          }|                      |d          }|                     |d          }|                     |d          }|                      |d          }|                      |d          }|                      |d          }	|                     |	|d          }
|                     |d	          }|                      |d
          }d }|D|                      |d          }|                     |          }|                      |d          |d}|                     ||||                     |          |
d |||d |||d|          S )Nr   orderIdr  sider   r   r   r  rolefeefeeCurrency	feeAmountr   currency)r   orderr  r  r   r   r9  r   r   r   takerOrMakerr;  r   )r   r   safe_string_lowerr  r   
safe_trader  )r   trader   r   r8  r  r9  priceStringamountStringr  r   rA  	feeStringr;  feeCurrencyIdfeeCurrencyCodes                   r   parse_tradeznovadax.parse_trade  s   V eT**""5)44%%e[99	%%eV44&&ug66''x88##E844!!(FC88--eV<<$$UE22	  ,,UMBBM"55mDDO((<<+ C "Y// "( 
  
   	r   sincec                 B  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :see: 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>`
        Nr   r   r0  r   )r   r   publicGetMarketTradesr"  	safe_listparse_trades)	r   r   rK  r0  r   r   r$  r   r   s	            r   fetch_tradesznovadax.fetch_trades7  s       !!!!!!!!!V$$fTl
 $GG33DKK4P4PQQQQQQQQ ~~h33  vue<<<r   rz   c                 ^  K   |                                   d{V  |                     |          }|d         |                     | j        ||          d}|                     |          }|                                 }	|d}||	||z  z
  |d<   |	|d<   n9|                     |dz            }
|
|d<   |                     |
||z            |d<   |                     | 	                    ||                     d{V }| 
                    |dg           }|                     |||||          S )	a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: 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
        Nr   )r   uniti  fromtoi  r   )r   r   r   r   parse_timeframesecondsparse_to_intsumpublicGetMarketKlineHistoryr"  rN  parse_ohlcvs)r   r   	timeframerK  r0  r   r   r$  durationnow	startFromr   r   s                r   fetch_ohlcvznovadax.fetch_ohlcvW  sX      !!!!!!!!!V$$Tl$$T_iKK
 
 ''	22llnn=E=!EH$44GFOGDMM))%$,77I'GFO HHY0@AAGDM99$++gv:V:VWWWWWWWW( ~~h33  vy%GGGr   c           	      h   |                      | j        di           }|                     |dd          }|                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     ||          gS )	NrX   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A&&w(CCw//UK00UK00UJ//UL11UK00
 	
r   c                    |                      |dg           }|d d d}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d	          |d
<   |||<   |                     |          S )Nr   )r   r  r  r   r?  balancetotal	availablefreeholdused)r   r*  r+  r   r   accountsafe_balance)	r   r   r   r-  r.  rk  
currencyIdcoderq  s	            r   parse_balanceznovadax.parse_balance  s    x44
 

 q#d))$$ 	# 	#A1gG))':>>J**:66DllnnG#//CCGG"..wDDGFO"..w??GFO"F4LL  (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )ab  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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>`
        N)r   privateGetAccountGetBalanceru  r   s      r   fetch_balanceznovadax.fetch_balance  sg       !!!!!!!!!99&AAAAAAAA !!(+++r   r   r9  r   r   c                   K   |                                   d{V  |                     |          }|                                }|                                }	|d         |	d}
|                     |dd          }|*|dk    s|dk    rt	          | j        dz   |z   d	z             nf|d
k    rd}n|dk    rd}|	dk    rdnd}|                     |d|          |
d<   |                     ||          |
d<   |                     |ddg          }|d
k    s|dk    r4|                     ||          |
d<   | 	                    ||          |
d<   n$|dk    s|dk    r|	dk    r| 	                    ||          |
d<   n|	dk    rd}d}| 
                    |ddd          \  }}|                     |dd          }|                     |d          }||                     ||          }n|ro|t          | j        dz             |                     |          }|                     |          }t          j        ||          }|                     ||          }n|                     ||          }||
d<   ||
d<   |                     |                     |
|                     d{V }|                     |di           }|                     ||          S )a  
        create a trade order
        :see: 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 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.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>`
        Nr   )r   r9  triggerPrice	stopPrice
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   )r   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privatePostOrdersCreater"  r#  parse_order)r   r   r   r9  r   r   r   r   uppercaseTypeuppercaseSider$  r{  defaultOperatorquoteAmountr  r   rF  rE  costRequestr   r   s                        r   create_orderznovadax.create_order  s      !!!!!!!!!V$$



Tl!
 
 %%fnkJJ	--=M3Q3Q'2f(fiv(v  zC  )C  D  D  D 4R '' ,(** -(5(>(>eeUO"&"2"26:"W"WGJ#'#:#:69#M#MGK YYv'DEEFW$$-<*G*G#66vuEEGG $ 8 8 H HGHx'']m-K-K&&$($<$<VV$L$L!!%''"481<@<Y<YZ`bo  rU  W[  =\  =\916))&&'BB6622#"&"8"8"F"FKK6 	I}*47  6A  ,A  B  B  B'+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S&*&<&<V[&Q&Q"&"8"8"H"HK#. '55dkk'66R6RSSSSSSSS0 ~~h33f---r   r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |di           }|                     |          S )ap  
        cancels an open order
        :see: 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>`
        Nr   r   )r   privatePostOrdersCancelr"  r#  r  r   r   r   r   r$  r   r   s          r   cancel_orderznovadax.cancel_order*  s       !!!!!!!!!"
 55dkk'66R6RSSSSSSSS ~~h33%%%r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |di           }|                     |          S )aj  
        fetches information on an order made by the user
        :see: https://doc.novadax.com/en-US/#get-order-details
        :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>`
        Nr   r   )r   privateGetOrdersGetr"  r#  r  r  s          r   fetch_orderznovadax.fetch_orderD  s       !!!!!!!!!"
 11$++gv2N2NOOOOOOOO, ~~h33%%%r   c                 ^  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a,  
        fetches information on multiple orders made by the user
        :see: 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   r0  fromTimestampr   )r   r   privateGetOrdersListr"  rN  parse_orders	r   r   rK  r0  r   r$  r   r   r   s	            r   fetch_ordersznovadax.fetch_ordersi  s       !!!!!!!!!
 [[((F &tGH$GG',GO$224;;w3O3OPPPPPPPP0 ~~h33  vue<<<r   c           	      r   K   ddi}|                      ||||                     ||                     d{V S )a  
        fetch all unfilled currently open orders
        :see: 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,CANCELINGNr  r"  r   r   rK  r0  r   r$  s         r   fetch_open_ordersznovadax.fetch_open_orders  sR       E
 &&vueT[[RX=Y=YZZZZZZZZZr   c           	      r   K   ddi}|                      ||||                     ||                     d{V S )a3  
        fetches information on multiple closed orders made by the user
        :see: 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,REJECTEDNr  r  s         r   fetch_closed_ordersznovadax.fetch_closed_orders  sR       0
 &&vueT[[RX=Y=YZZZZZZZZZr   c                 0  K   |                                   d{V  d|i}|                     |                     ||                     d{V }d}||                     |          }|                     |dg           }	|                     |	|||          S )a  
        fetch all the trades made from a single order
        :see: 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>`
        Nr   r   )r   privateGetOrdersFillr"  r   r   rO  )
r   r   r   rK  r0  r   r$  r   r   r   s
             r   fetch_order_tradesznovadax.fetch_order_trades  s       !!!!!!!!!"
 224;;w3O3OPPPPPPPP[[((Fx44,   vue<<<r   c                 D    dddddddd}|                      |||          S )Nr  closedcanceledrejected)	SUBMITTED
PROCESSINGPARTIAL_FILLED	CANCELINGFILLEDCANCELEDREJECTEDr   r   r   statusess      r   parse_order_statusznovadax.parse_order_status  s=     $""
 
 &&999r   c           	      n   |                      |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|          S )Nr   r   r   filledValuer  r   r9  r   r  averagePricefilledAmount	filledFeer>  r   r  r{  clientOrderIdr   r  lastTradeTimestamptimeInForcepostOnlyrz  r   r  )filled	remainingr   r;  trades)	r   safe_string_2rB  r  r   r   r  
safe_orderr  )r   r@  r   r   r   r   r   r   r9  r   r  r  r  r;  feeCostr  r   r{  s                     r   r  znovadax.parse_order  so   8 eT**!!%22  00!!%@@%%eV44%%eV44(()9)9%)J)JKK%%e[99	""5.99!!%88""5+66  C ##E844!!(FC88$$UK88	  
" 
T 
 E 
 	 

 Y// 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
  
 I 
 f 
  D! 
" w# 
$ - 
  
  
. /  	r   rt  fromAccount	toAccountc                 &  K   |                                   d{V  |                     |          }|dk    r|dk    rt          | j        dz             |dk    rdnd}|                     ||          |d         |dk    r|n||d}|                     |                     ||                     d{V }	|                     |	|          }
|                     | j	        di           }| 
                    |d	d
          }|r||
d<   ||
d<   ||
d<   |
S )a  
        transfer currency internally between wallets on the same account
        :see: 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>`
        NmainzH transfer() supports transfers between main account and subaccounts onlyzmaster-transfer-inzmaster-transfer-outr   )transferAmountr?  subIdtransferTyperp   r   Tr  r  r   )r   r?  r   r   currency_to_precisionprivatePostAccountSubsTransferr"  parse_transferr   r   	safe_bool)r   rt  r   r  r  r   r?  r   r$  r   rp   transferOptionsr   s                r   rp   znovadax.transfer>  sb      !!!!!!!!!==&&&  Y&%8%8*t tuuu )4v(=(=##DY"88vFF #'+?#?#?YYk 	
 
 <<T[[RX=Y=YZZZZZZZZ &&x:://$,
BGG"&..B[]a"b"b" 	(&1H]#$-H[!!'HXr   r?  c                     |                      |d          }|                      |d          }|                     d |          }||d ||d d d d |d
S )Nr   message)
r   r   r   rt  r?  r  r  r  r  r   )r   r   )r   rp   r?  r   r   currencyCodes         r   r  znovadax.parse_transferg  sp     h//!!(I66..tX>> $
 
 	
r   c                 8    ddi}|                      ||d          S )NSUCCESSpendingfailedr  r  s      r   parse_transfer_statusznovadax.parse_transfer_status  s(    y
 &(;;;r   c                 n  K   |                      ||          \  }}|                                  d{V  |                     |          }|d         |                     ||          |d}|||d<   |                     |                     ||                     d{V }|                     ||          S )a  
        make a withdrawal
        :see: 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>`
        Nr   )rt  r   wallettag)handle_withdraw_tag_and_paramsr   r?  r  privatePostAccountWithdrawCoinr"  parse_transaction)	r   rt  r   addressr  r   r?  r$  r   s	            r   rq   znovadax.withdraw  s       99#vFFV!!!!!!!!!==&&TN00v>>
 

 ? GEN<<T[[RX=Y=YZZZZZZZZ %%h999r   c                 N  K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]P}||         }|                     |d          }|                     |d          }|                    ||d|d           Q|S )aa  
        fetch all the accounts associated with a profile
        :see: 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
        Nr   r   r  
subAccount)r   r   r?  r   )privateGetAccountSubsr   r*  r+  r   append)	r   r   r   r   r-  r.  rq  	accountIdr   s	            r   fetch_accountsznovadax.fetch_accounts  s       33F;;;;;;;; x44q#d))$$ 		 		A1gG(('::I##G\::DMM 	      r   c           	      r   K   ddi}|                      ||||                     ||                     d{V S )a  
        fetch all deposits made to an account
        :see: 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_inNfetch_deposits_withdrawalsr"  r   rt  rK  r0  r   r$  s         r   fetch_depositsznovadax.fetch_deposits  sR       I
 44T5%U\^dIeIefffffffffr   c           	      r   K   ddi}|                      ||||                     ||                     d{V S )a(  
        fetch all withdrawals made from an account
        :see: 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_outNr  r  s         r   fetch_withdrawalsznovadax.fetch_withdrawals  sR       J
 44T5%U\^dIeIefffffffffr   c                 P  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )az  
        fetch history of deposits and withdrawals
        :see: 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   )r   r?  $privateGetWalletQueryDepositWithdrawr"  rN  parse_transactions)	r   rt  rK  r0  r   r$  r?  r   r   s	            r   r  z"novadax.fetch_deposits_withdrawals  s       !!!!!!!!!
 }}T**H"*4.GJ#GFOBB4;;wX^C_C_````````, ~~h33&&tXueDDDr   c                     |                     d          }|                     |d|          }ddddd}|                     |||          S )N r   r  okr  )Pending
confirmingr  FAIL)splitr   )r   r   partsr  s       r   parse_transaction_statusz novadax.parse_transaction_status  s^    
 S!!!!%F33 #	
 
 &&999r   c                     |                      |dd          }|                     |d          }|dk    rd}n|dk    r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S )Nr   r   r   COIN_INdepositCOIN_OUTrq   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   transactionr?  r   r   r   r  r  r  r  r  rs  rt  r   r  s                  r   r  znovadax.parse_transaction&  s:   4 T6::V449DDZD!!+x88"";	::{L99X66%%k;??	##K==%%k:>>
&&z8<<..t/?/?W/U/UVV"";88
K
"
 
 f	

 w
 w
 
 4
 3
 S
 t
 f
 D
 w
 D
  !
" Y//#
$   )
 
 
 	
r   c                 ^  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        fetch all trades made by the user
        :see: 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   r0  r  r   )r   r   privateGetOrdersFillsr"  rN  rO  r  s	            r   fetch_my_tradesznovadax.fetch_my_tradesk  s       !!!!!!!!!	
 [[((F &tGH$GG',GO$33DKK4P4PQQQQQQQQ, ~~h33  vue<<<r   r   GETc                    d| j         z   dz   |                     ||          z   }| j        d         |         |z   }|                     ||                     |                    }	|dk    r|	r|d|                     |	          z   z  }n:|dk    r3|                                  t          |                                           }
| j	        |
d}d }|dk    rD| 
                    |	          }|                     |                     |          d          }d	|d
<   nE|	r|d|                     |	          z   z  }|                     |                     |	                    }|dz   |z   dz   |z   dz   |
z   }|                     |                     |          |                     | 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   r#  r   r%  r$  r$  r"  queryr  queryStringauths                r   signznovadax.sign  s   $s*T-@-@v-N-NNis#g-		&$"5"5d";";<<(?? 3sT^^E2222I++---D--//00I%)[$- G Kyy''"iiD(9(95AA*<'' 73!6!666C"nnT\\%-@-@AAD=7*T1K?$FRD*.))DKK4E4Et{{SWS^G_G_ahao*p*pG&'fdwOOOr   c
                 2   |d S |                      |d          }
|
dk    rv|                      |d          }| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         ||           t          |          d S )Nrt  A10000r  r  r   r   )r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   rt  reasonr"  r#  r%  r$  r   requestHeadersrequestBody	errorCoder  feedbacks                r   handle_errorsznovadax.handle_errors  s    4 $$Xv66	  &&x;;Gw}t+H001I9V^___001I7T\]]])))tr   )N)=__name__
__module____qualname__r   r   r   r	   r   r   r   r  r*  r%  r   r   r/  r   r   r6  r   rJ  rP  listr_  ri  r   ru  rx  r   r   floatr
   r  r   r  r  r   r  r  r  r  r  r  r   rp   r   r  r  rq   r   r  r   r  r  r  r  r  r  r7  rA  __classcell__)r   s   @r   r(   r(      s@           B ') 3 3 3 3" *, ( (V ( ( ( (<8
f 8
 8
 8
 8
t- -6 -V - - - -^ 68 !/ !/ !/F !/ !/ !/ !/F 6:" %G %G7 %G %G %G %G %GN @DB &X &XS &X &XS\ &X &X &X &XPK K K5 K K K KZ <@d[] = = =S = =bfglbm = = = =@ 8<$]ajl 1H 1H 1HC 1HWZ 1Hquvzq{ 1H 1H 1H 1Hf
 
 
4 
 
 
 
2) ) ) ) )$ *, , , , , , ,2 mqy{ Z. Z. Z.I Z.Y Z.X] Z.fi Z. Z. Z. Z.x 9=R & &S &# & & & &4 8<B #& #&C #& #& #& #& #&J 04$UYbd 5= 5= 5=C 5=s 5=imnsit 5= 5= 5= 5=n 59tZ^gi [ [c [ [TW [nrsxny [ [ [ [ 7;\`ik [ [ [3 [VY [ptuzp{ [ [ [ [ ?CQUdhqs )= )=3 )= )=3 )=^a )= )= )= )=V
: 
: 
:G G G5 G G G GR ac ' '3 ' 'C 'TW 'gt ' ' ' 'R
 
 
 
 
 
0< < < EIQS : :3 : : : : :> +- " "g " " " "H 04$UYbd g g gC gs gimnyiz g g g g 37TX\eg g gC gs gRU glpq|l} g g g g <@daenp /E /ES /E /E[^ /Euy  {F  vG /E /E /E /Eb: : :C
 C
x C
; C
 C
 C
 C
J 37TX\eg 4= 4=C 4=s 4=RU 4= 4= 4= 4=l &eBSW P P P P6      r   r(   )- ccxt.async_support.base.exchanger   ccxt.abstract.novadaxr   r1  ccxt.base.typesr   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     s   6 5 5 5 5 5 - - - - - -  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) * * * * * * * * * * * * . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %l l l l lh l l l l lr   