
    is                    8   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZ 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)Balances
CurrenciesIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFees)List)ExchangeError)AuthenticationError)ArgumentsRequired)	BadSymbol)NullResponse)InsufficientFunds)InvalidOrder)OrderNotFound)DDoSProtection)RateLimitExceeded)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi fdefdZi fdee         fdZ	de
fdZi fde
fdZdi fd	ed
edefdZd.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edefdZdi fdedefdZi fd	edefdZd.dedefdZddi fd	eded
edee         fdZi fde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$fdZ&d.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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% Z-ddi fded	edede de"de"fd&Z.i fd'efd(Z/d) Z0d*d+i ddfd,Z1d- Z2 xZ3S )/cexc                 T   |                      t          t          |                                           ddg dddi dd dddd	d
d	dd	dd	dd	dddddd	dd	dddd	dd	dddd	dd	i dd	dddddddddd	dddd	d d	d!d	d"d	d#d	d$d	d%d	d&d	d'd	d(di d)d	d*dd+d	d,dd-dd.dd/dd0d	d1d	d2dd3dd4dd5d	d6dd7d	d8d	d9d	d	d	d	d	d	d	d	d	d	d:	d;d<d=d>d?d@dAidBdCdDdEgdFdGddddHg dIdJdKgdLdMg dNidO|                     dP          |                     dQ          dRi dSdSdSdSdSdSdSdSdTdUdVt
          i t          t          t          t          t          t          t          t          t          t          dW
dXdddYdZd[dZd\d]id^d_d`idadbdcdddedfdg          S )hNr#   zCEX.IO)GBEUCYRUi  TCORSspotmarginFswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchBalancefetchClosedOrdersfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchMarginModefetchMarketsfetchMarkOHLCV
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionModefetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransfers)	fetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginsetLeverage	setMarginsetMarginModetransferwithdraw1m1h1d)re   rf   rg   zchttps://user-images.githubusercontent.com/1294454/27766442-8ddc33b0-5ed8-11e7-8b98-f786aef0f3c9.jpgrestzhttps://cex.io/apizhttps://cex.iozhttps://cex.io/cex-apizhttps://cex.io/fee-schedulez!https://cex.io/limits-commissionsz!https://cex.io/r/0/up105393824/0/)logoapiwwwdocfeesreferral)apiKeysecretuid)	currency_profilezcurrency_limits/zlast_price/{pair}/zlast_prices/{currencies}/zohlcv/hd/{yyyymmdd}/{pair}zorder_book/{pair}/zticker/{pair}/ztickers/{currencies}/ztrade_history/{pair}/zconvert/{pair}zprice_stats/{pair})getpostrt   )zactive_orders_status/zarchived_orders/{pair}/zbalance/zcancel_order/zcancel_orders/{pair}/zcancel_replace_order/{pair}/zclose_position/{pair}/zget_address/get_crypto_addressz
get_myfee/z
get_order/zget_order_tx/zopen_orders/{pair}/zopen_orders/zopen_position/{pair}/zopen_positions/{pair}/zplace_order/{pair}/raw_tx_history)publicprivatez0.0016z0.0025)makertakerg        )BTCETHBCHDASHBTGZECXRPXLM)rd   deposit)tradingfunding)
zInsufficient fundszNonce must be incrementedzInvalid OrderzOrder not foundzlimit exceededzInvalid API keyz+There was an error while placing your orderzSorry, too many clients alreadyzInvalid Symbols PairzWrong currency pair)exactbroadstatuscanceledclosedopen)cdcdaERC20USDTTRC20Ethereumr{   zBinance Smart ChainTron)r   r{   BEP20r   )fetchOHLCVWarning!createMarketBuyOrderRequiresPriceorderdefaultNetworkdefaultNetworksnetworks)idname	countries	rateLimitprohas
timeframesurlsrequiredCredentialsrj   rm   precisionMode
exceptionsoptions)deep_extendsuperr#   describeparse_numberr    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/cex.pyr   zcex.describe   s   c4 0 0 9 9 ; ;111=== %= 	=
 %= %= U= "4= t= = '= /= ,U= 0= t=  '!=" (#= =$ "5%=& T'=( )=* $T+=, "4-=. /=0 &t1=2 (3=4  5=6 +E7=8 &u9=: #E;=< *5==> $U?=@ "5A=B "5C=D E= = =F !%G=H dI=J +EK=L "4M=N dO=P !$Q=R tS=T $UU=V )%W=X tY=Z [=\ t]=^ "5_=` #Da=b $Uc=d  e=f !%g= =h $)$),1 %$"!&!!y= = =~   ~0 (/17 @  $ $
 
 
 ), $    %( (V "..x88!..x88 
 !#  #"" #""""     . '*;1=%1'4&7':CO7E,5+4    &*59'%(#	  #*G$ ( 2#	  WA>
 A>
 A A A	    c                   K   |                      | j        di           }|                     |d          }|                     |dd          }|                                 }|	||z
  |k    r<|                     |           d {V }|                     |||d          | j        d<   |                      | j        d         d          S )Nr>   	timestampexpiresi  )responser   r   )
safe_valuer   safe_integermillisecondspublicGetCurrencyProfileextend)r   paramsr   r   r   nowr   s          r   fetch_currencies_from_cachezcex.fetch_currencies_from_cache   s       //$,0A2FF%%g{;;	##GY==!!C)Ow#>#>!::6BBBBBBBBH.2kk'$ D D / /DL*+ t|,=>
KKKr   returnc                 ~  K   |                      |           d{V }|                                 |d| j        d<   |                     |dg           }|                     |dg           }i }t	          dt          |                    D ]}||         }|                     |d          }|                     |          }	d}
||	||
dd|                     | 	                    |                     |d	                              d| 
                    |d
          dd| 
                    |d          ddd|d
||	<   |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        N)r   r   
currenciesdatasymbolsr   codeT	precisionminimumCurrencyAmountminmaxminimalWithdrawalAmount)amountrd   )
r   r   r   activer   rd   r   feelimitsinfo)r   r   r   r   rangelensafe_stringsafe_currency_coder   parse_precisionsafe_number)r   r   r   r   r   resulticurrencyr   r   r   s              r   fetch_currencieszcex.fetch_currencies   s      99&AAAAAAAA**,, &
 &
\"B x44__T9b99
q#j//** 	 	A!!}H!!(F33B**2..DF  !..t/C/CDDTDTU]_jDkDk/l/lmm  $//:QRR# 
  $//:STT#! !	 	 !' F4LL* r   c                 p  K   |                      |           d{V }|                     |di           }|                     |dg           }|                     |d          }|                     |dg           }|                     |           d{V }g }|                     |d         d          }	t	          dt          |	                    D ]e}
|	|
         }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     ||i           }|                     ||i           }|                     |d	d
          }t	          dt          |                    D ]9}||         }|d         |k    r#|d         |k    r|                     |d|          }:|                     |d	d
          }|                     |dd          }t          j	        ||          }|
                    i d|dz   |z   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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*
           g|S )+z
        retrieves data on all markets for cex
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   r   pairsr   symbol1symbol2r   8pricePrecisionscale0r   /symbolbasequotesettlebaseIdquoteIdsettleIdtyper*   Tr+   r,   Fr-   r.   r   contractlinear)r   pricer   
minLotSize
maxLotSizeminPricemaxPriceminLotSizeS2)leverager   r   cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionTyper   r   createdr   )r   r   index_bypublicGetCurrencyLimitsr   r   r   r   r!   
string_subappendr   r   r   )r   r   currenciesResponsecurrenciesDatar   currenciesByIdr   r   r   marketsr   marketr   r   r   r   baseCurrencyquoteCurrencypricePrecisionStringjpairbaseCurrencyPrecisionbaseCurrencyScaleamountPrecisionStrings                           r   fetch_marketszcex.fetch_marketsW  sD      $(#C#CF#K#KKKKKKK);VRHH__^YCC
z6::<<55f========: //(6"2G<<q#g,,'' A	 A	AQZF%%fi88F&&vy99G**622D++G44E??>62FFL OONGRHHM#'#3#3M;PS#T#T 1c%jj)) j jQxOv--DOw4N4N+/+;+;DBRTh+i+i($($4$4\;PS$T$T! $ 0 0w L L$+$67LN_$`$`!MM 0fslW,0$*u,0 0 	0
 $0 &0 70 D0 0 0 $0 0 %0 %0 $0  E!0" $#0$   $"&""//0D0DEZ0[0[\\!..t/C/CDX/Y/YZZ   $#! !
  $//EE#//EE 
  $//
CC#//
CC 
  $//GG#  $  _0 0 0 0 0 0 0b r   c                    d|i}ddg}|                      ||          }t          |                                          }t          dt	          |                    D ]}||         }|                     ||i           }|                                 }	|                     |d          |	d<   |                     |dd          |	d	<   |                     |          }
|	||
<   | 	                    |          S )
Nr   usernamer   r   	availablefreeordersr   used)
omitlistkeysr   r   r   accountr   r   safe_balance)r   r   r   ommitedbalancescurrencyIdsr   
currencyIdbalancer  r   s              r   parse_balancezcex.parse_balance  s    (#{+99Xw//8==??++q#k**++ 	# 	#A$QJooh
B??GllnnG"..wDDGFO"..w#FFGFO**:66D"F4LL  (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )aT  
        :see: https://docs.cex.io/#account-balance
        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)load_marketsprivatePostBalancer  )r   r   r   s      r   fetch_balancezcex.fetch_balance  se       !!!!!!!!!0088888888!!(+++r   Nr   limitc                 J  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||d         |          S )a   
        :see: https://docs.cex.io/#orderbook
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :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   depthr   r   )r  r  publicGetOrderBookPairr   safe_timestampparse_order_book)r   r   r   r   r  requestr   r   s           r   fetch_order_bookzcex.fetch_order_book  s       !!!!!!!!!V$$F4L
 $GG44T[[&5Q5QRRRRRRRR''+>>	$$Xvh/?KKKr   r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr                  )r$  r   )r   ohlcvr  s      r   parse_ohlcvzcex.parse_ohlcv  s     q))UA&&UA&&UA&&UA&&UA&&
 	
r   re   sincec                   K   |                                   d{V  |                     |          }||                                 dz
  }n$| j        d         rt	          | j        dz             |d         |                     |d          d}	 |                     |                     ||                     d{V }d| 	                    | j
        ||          z   }	| 	                    ||	          }
t          j        |
          }|                     |||||          S # t          $ r&}t          |t                     rg cY d}~S Y d}~nd}~ww xY wdS )	a  
        :see: https://docs.cex.io/#historical-ohlcv-chart
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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
        Ni \&r   a   fetchOHLCV warning: CEX can return historical candles for a certain date only, self might produce an empty or None reply. Set exchange.options['fetchOHLCVWarning'] = False or add({'options': {'fetchOHLCVWarning': False}}) to constructor params to suppress self warning message.r    )r  yyyymmddr   )r  r  r   r   r   r   r3  publicGetOhlcvHdYyyymmddPairr   r   r   jsonloadsparse_ohlcvs	Exception
isinstancer   )r   r   	timeframer0  r   r   r  r&  r   keyr   ohlcvses                r   fetch_ohlcvzcex.fetch_ohlcv  s      !!!!!!!!!V$$=%%''(2EE|/0 H#DG  /G  %G  H  H  H4LeR00
 
	!>>t{{7TZ?[?[\\\\\\\\H 4++DOY	RRRC##Hc22DZ%%F$$VVYuMMM 	 	 	!\** 						    	 ts   BD! !
E+EEEc                 &   |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     d |          }
|                     i d|
d|d	|                     |          d|d|d|d
d d|dd dd dd d|	d|	dd dd dd dd |d |d|          S )Nr   volumehighlowbidasklastr   datetime	bidVolume	askVolumevwapr   closepreviousClosechange
percentageaverage)
baseVolumequoteVolumer   )r$  r   safe_symbolsafe_tickeriso8601)r   tickerr  r   r@  rA  rB  rC  rD  rE  r   s              r   parse_tickerzcex.parse_ticker/  s   ''<<	!!&(33//vu--vu--vu--//!!$// !
f!
!
 Y//!
 D	!

 3!
 3!
 !
 3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ !)!
 !
 !
* +  	r   r   c                   K   |                                   d{V  |                     |          }t          | j                                                  }dd                    |          i}|                     |                     ||                     d{V }|                     |dg           }i }t          dt          |                    D ]X}||         }	|                     |	d          }
|                     |
dd          }|d         }|                     |	|          ||<   Y|                     |d|          S )	a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :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   r  :r   )r  market_symbolsr  r   r  joinpublicGetTickersCurrenciesr   r   r   r   r   safe_marketrU  filter_by_array_tickers)r   r   r   r   r&  r   tickersr   trT  marketIdr  r   s                r   fetch_tickerszcex.fetch_tickersO  sR      !!!!!!!!!%%g..$/..0011
#((:..
 88Wf9U9UVVVVVVVV//(FB77q#g,,'' 	? 	?AQZF''77H%%hc::FH%F!..vv>>F6NN++FHgFFFr   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a  
        :see: https://docs.cex.io/#ticker
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :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  r  publicGetTickerPairr   rU  )r   r   r   r  r&  rT  s         r   fetch_tickerzcex.fetch_tickerg  s       !!!!!!!!!V$$F4L
 //GV0L0LMMMMMMMM  000r   c                    |                      |d          }|                     |d          }d }|                     |d          }|                     |d          }|                     |d          }|                     d |          }|                     ||||                     |          |d         ||d d ||d d d|          S )Ndatetidr   r   r   r   )r   r   r   rF  r   r   sider   takerOrMakerr   r   r   r   )r$  r   r[  
safe_traderS  )	r   trader  r   r   r   rg  priceStringamountStrings	            r   parse_tradezcex.parse_tradew  s     ''v66	eU++v..&&ug66''x88!!$//"Y//X&  " 
  
   	r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||||          S )a  
        :see: https://docs.cex.io/#trade-history
        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        Nr  r   )r  r  publicGetTradeHistoryPairr   parse_tradesr   r   r0  r   r   r  r&  r   s           r   fetch_tradeszcex.fetch_trades  s       !!!!!!!!!V$$F4L
 77GV8T8TUUUUUUUU  65%@@@r   c                 |  K   |                                   d{V  |                     |           d{V }|                     |di           }i }t          dt	          | j                            D ]}| j        |         }|                     |          }|                     ||d         i           }|                     |d          }	|                     |d          }
|                     t          j
        |	d                    }|                     t          j
        |
d                    }||||dd	||<   |S )
a>  
        :see: https://docs.cex.io/#get-my-fee
        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        Nr   r   r   buyMakerbuy100T)r   r   ry   rz   rM  )r  privatePostGetMyfeer   r   r   r   r  r   r   r!   
string_div)r   r   r   r   r   r   r   r  r   makerStringtakerStringry   rz   s                r   fetch_trading_feeszcex.fetch_trading_fees  sW      !!!!!!!!!11&99999999 x44q#dl++,, 	 	A\!_F[[((F//$tb99C**3
;;K**366K%%g&8e&L&LMME%%g&8e&L&LMME " F6NN r   r   rg  r   r   c                   K   |                                   d{V  |                     |          }|d         |d}|dk    r|dk    rd}	d}
|                     |ddd          \  }
}|                     |d	          }|                     |d	          }||                     ||          }	n|
ro|t          | j        d
z             |                     |          }|                     |          }t          j
        ||          }|                     ||          }	n|                     ||          }	|	|d<   n|                     ||          |d<   |dk    r|                     |          |d<   n||d<   |                     |                     ||                     d{V }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|rdnd}d}|*|(t          j        t          j        ||          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i          S )#a:  
        :see: https://docs.cex.io/#place-order
        create a trade order
        :see: https://cex.io/rest-api#place-order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   )r  r   r  ru  Tr7   r   r   z 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 in the amount argumentr   r   r   
order_typependingtimecompleter   r   r   r   clientOrderIdr   rF  lastTradeTimestampr   rg  r   r   rN  	remainingfilledr   trades)r  r  handle_option_and_paramsr   r  cost_to_precisionr   r   number_to_stringr!   
string_mulamount_to_precisionprivatePostPlaceOrderPairr   r   
string_maxr   
safe_orderrS  )r   r   r   rg  r   r   r   r  r&  quoteAmountr   r   rl  rk  costRequestr   placedAmountr  r   r  r   r  s                         r   create_orderzcex.create_order  s      !!!!!!!!!V$$4L
 

 H45==K04-8<8U8UV\^k  nQ  SW  9X  9X5-v##FF33DYYvv..F"44VTBB2 	E=&tw  2m  (m  n  n  n#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK"&"8"8"M"MKK"44VVDD +GH $ 8 8 H HGH7??#44U;;GG$(GL!77GV8T8TUUUUUUUU ''(;;$$Xy99	OOHf55	??8Z88%16$9+@'(:<(S(SUXYYF  
$""8T22 
H 
 T 
 	 

 Y// 
 !$ 
 D 
 D$$Xv66 
 fX& 
 f 
 T%%h88 
 l 
 D 
 t 
  
  f! 
" 4# 
$ d% 
  
   	r   r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |                     i           |d|dd          S )a_  
        :see: https://docs.cex.io/#cancel-order
        cancels an open order
        :param str id: order id
        :param str symbol: not used by cex 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   r   r   r   )r  privatePostCancelOrderr   parse_order)r   r   r   r   r&  r   s         r   cancel_orderzcex.cancel_order*  s       !!!!!!!!!"
 44T[[&5Q5QRRRRRRRR{{4++B//(DXZfp1q1qrrrr   c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|S )a  
        :see: https://docs.cex.io/#cancel-all-orders-for-given-pair
        cancel all open orders in a market
        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the cex api endpoint
        :param str [params.marginMode]: 'cross' or 'isolated', for spot margin trading
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz# cancelAllOrders requires a symbol.r  r   )r   r   r  r  privatePostCancelOrdersPairr   )r   r   r   r  r&  r  s         r   cancel_all_orderszcex.cancel_all_orders;  s       >#DG.S$STTT!!!!!!!!!V$$F4L
 77GV8T8TUUUUUUUU r   c                 <   |                      |d          }t          |t                    r/|                    d          dk    r|                     |          }n|t          |          }d }|                     |d          }|                     |d          }|X|V|T|                     |          }|                     |          }|
||dz   |z   }|| j        v r| 	                    |          }| 
                    |                     |d                    }	|                     |d          }
|                     |                     |d	                    }|t          j        |          }n8|6d
|d         z   dz   }t          j        |                     ||                    }|                     |dd          }t          j        ||          }d }d }|J|d         }|                     |d|d         z             }|                     |d|d         z             }t          j        ||          }d|d         z   }d|d         z   }d|d         z   }d|d         z   }|                     |d          }|s|                     |d|          }|rt          j        |d          }||v s||v r7|                     |||          }|d         |                     |          |d}n>||v s||v r6|                     |||          }|d         |                     |          |d}|st          j        |
|          }|                     |d          }d }|                     |d          }d|v rg }t+          dt-          |d                             D ]}|d         |         }|                     |d          }|dk    r.|                     |d          } | G|dk    rN|                     |                     |d                    }!|                     |d	          }"|                     |d          }#t          j        |"          }$d }%|dk    r+|$}%t          j        t          j        |#|%          |           }$nt          j        |$|           }%|                    |                     |d          |!|                     |!          |||                     |           |                     |$          |                     |%          ||                     |#          |d         d |d d d!           |                     i d"|d|d#d d$|                     |          d%|d&d d|	d|d|
d'nd(d)d d*d d+|d|
d,d d-d d.|d	|||||d d/          S )0Nr  Tr   r   r   r   r   r   r   a:r   zcds:r~  remainsr   ta:r   tta:fa:tfa:tradingFeeMakertradingFeeTakerrv  )r   rater   r   r   vtxcancelcostsNothing
fee_amountsellr   r   )r   r   rF  r   r   r   r   r   rg  r   r   r   rh  r   r  rF  r   r  r  r   timeInForcepostOnlyrg  	stopPricetriggerPricer   )r  r  r  r   rN  )r   r9  strfind	parse8601intr   r   r   r  parse_order_status	omit_zeror!   
string_abssafe_string_2r   
string_addrx  safe_number_2r   r  r   r   r   rS  r  )&r   r   r  r   r   r   r   r   r   r   r   r   	amountKeyr  r  r   r   taCostttaCostbaseFeebaseTakerFeequoteFeequoteTakerFeefeeRatebaseFeeCostquoteFeeCostrg  r  orderIdr   item	tradeSide
tradePricetradeTimestamptradeAmountfeeCostabsTradeAmount	tradeCosts&                                         r   r  zcex.parse_orderV  s    OOE622	i%% 	')..*=*=*B*By11II"II!!%33""5)44>f0W5H**622D++G44E u'8e+%%V,,(()9)9%)J)JKK  00 0 0 A ABB '//FFvf~-6I'(8(8	(J(JKKF&&uiCC	#FI66H%F%%eUVG_-DEEF&&ufvg.FGGG%fg66DfVn,G!F6N2Lvg.H"VG_4M&&u.?@@G N**52CWMM =!,We<<5  le&;&;"00NN &v --g66' 
 e##%)?)?#11%=QQ &w --g66( 
  	5%eV44Dv..""5$//E>>F1c%,//00 W WU|A ,,T6::	((& !--dG<<
%( ..Z "&0@0@v0N0N!O!O"..tX>>**4>>!(!3K!@!@ 	&& .I%,%78J7T]8^8^`j%k%kNN ' 2>: N NI**466!/ $^ < <$$!..z::"//?? --i88% $ 1 1' : :$*7O  ! $(!     $   
E 
' 
 T 
 Y//	 

  
 !$ 
 f 
 f 
 HHW 
 4 
  
 D 
 U 
  
 D 
  D! 
" f# 
$ "- 
  
  
   	r   c                   K   |                                   d{V  i }d}d}|P|                     |          }|d         |d<   |                     |                     ||                     d{V }n/|                     |                     ||                     d{V }t          dt          |                    D ]#}|                     ||         ddi          ||<   $|                     ||||          S )a  
        :see: https://docs.cex.io/#open-orders
        fetch all unfilled currently open orders
        :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>`
        Nr   r  r   r   r   )r  r  privatePostOpenOrdersPairr   privatePostOpenOrdersr   r   parse_orders)	r   r   r0  r   r   r&  r  r  r   s	            r   fetch_open_orderszcex.fetch_open_ordersL  s$      !!!!!!!!![[((F$TlGFO99$++gv:V:VWWWWWWWWFF55dkk'66R6RSSSSSSSSFq#f++&& 	C 	CAF1I&/ABBF1II  >>>r   c                 8  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||||          S )a'  
        :see: https://docs.cex.io/#archived-orders
        fetches information on multiple closed orders made by the user
        :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>`
        Nz/ fetchClosedOrders() requires a symbol argumentr  r   )r   r   r  r  privatePostArchivedOrdersPairr   r  rq  s           r   fetch_closed_orderszcex.fetch_closed_ordersd  s       >#DG._$_```!!!!!!!!!V$$6$<(;;DKKQW<X<XYYYYYYYY  65%@@@r   c                   K   |                                   d{V  dt          |          i}|                     |                     ||                     d{V }|                     |di           }|                     |          S )ac  
        :see: https://docs.cex.io/?python#get-order-details
        fetches information on an order made by the user
        :param str symbol: not used by cex 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  r  privatePostGetOrderTxr   r   r  )r   r   r   r   r&  r   r   s          r   fetch_orderzcex.fetch_orderv  s       !!!!!!!!!#b''
 33DKK4P4PQQQQQQQQx44J %%%r   c           	        K   |                                   d{V  |                     |          }||d         |d}|                     |                     ||                     d{V }g }t	          dt          |                    D ]O}	||	         }
|                     |                     |
d                    }|                     |
d          }|                     |
d          }|                     |          }|                     |          }|dz   |z   }|                     |
d	          }| 	                    |
d
|z   dz             }| 	                    |
d
|z   dz             }| 	                    |
d|z   dz             }|                     |
d          }|                     |
d          }|                     |
d          }t          j        ||          }d}d}d}d}|sd}|}|}t          j        ||          }n|                     |
d|z   d          }|                     |
d|z   d          }|                     |
d|z   d          }|                     |
d|z   d          } |dk    r<t          j        t          j        ||          t          j        ||                     }n;t          j        t          j        ||          t          j        ||                     }d}|}t          j        ||          }|                     |
d          }!|                     |
d          }"|                     |!          }#|                     i d|
d|                     |
d          d|#d|                     |#          d|                     |"          d|d|d|d|d|d |d	|d!|d"|d#|d$||d%          }$|                    |$           Q|S )&a   
        :see: https://docs.cex.io/#archived-orders
        fetches information on multiple orders made by the user
        :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  dateFromr   r   r   r   r   r   r  z:cdszf:r   r   r  r  r  r   r  r  r  r  r   r  
lastTxTimer   r   rF  lastUpdatedr   rg  rN  r  r   r  r   r  )r  r  r  r   r   r   r  r   r   r   r!   r   rx  r  r  r  rS  r   )%r   r   r0  r   r   r  r&  r   resultsr   r   r   r   r   r   r   symbolInnerrg  
baseAmountr  r   r   r   r  r  orderAmountr   rN  r   tattafatfar  r  r   	safeOrders%                                        r   fetch_orderszcex.fetch_orders  s      !!!!!!!!!V$$4L
 

 ;;DKKQW<X<XYYYYYYYYq#h--(( B	& B	&AL QKE,,T-=-=eX-N-NOOF%%eY77F&&ui88G**622D++G44E*u,K##E622D))%1GHHJ**5$.62IJJK""5$.6*ABBC%%eX66F$$UG44E((	::I'	::FKDGD ;("!,[$??%%eUW_cBB&&ufw.>DD%%eUW_cBB&&ufw.>DD6>>"-g.@S.I.I7K]^`beKfKfggDD"-g.@S.I.I7K]^`beKfKfggD$!,T6::##E622D))%>>Jt,,I ))d&&ud33) Y) DLL33	)
 t~~j99) &) +) ) ) +) 7) ) &) ) Y)   % !)  I* NN9%%%%r   c                 R    |                      | j        d         d         ||          S )Nr   r   )r   r   )r   r   s     r   r  zcex.parse_order_status  s&    W 5h ?PPPr   c                 n  K   |t          | j        dz             |t          | j        dz             |                                  d{V  |                     |          }|d         ||||d}	|                     |                     |	|                     d{V }
|                     |
|          S )a  
        edit a trade order
        :see: https://docs.cex.io/#cancel-replace-order
        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of the currency you want to trade in units of the base currency
        :param float|None [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 cex api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/en/latest/manual.html#order-structure>`
        Nz' editOrder() requires a amount argumentz& editOrder() requires a price argumentr   )r  r   r   r   order_id)r   r   r  r  !privatePostCancelReplaceOrderPairr   r  )r   r   r   r   rg  r   r   r   r  r&  r   s              r   
edit_orderzcex.edit_order  s       >#DG.W$WXXX=#DG.V$VWWW!!!!!!!!!V$$ 4L
 
 ??GU[@\@\]]]]]]]]&111r   r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |          \  }}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	d          }
|                     |||
          }|                     |
|i           }|                     |dd          }| 	                    |           |||                     |d	d
          | 
                    |          |dS )ao  
        :see: https://docs.cex.io/#get-crypto-address
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr   r   r   	addresses
blockchainaddressdestinationdestinationTagmemo)r   r  tagnetworkr   )r  r   handle_network_code_and_paramsprivatePostGetCryptoAddressr   r   r   #select_network_id_from_raw_networksr  check_addressnetwork_id_to_code)r   r   r   r   r&  networkCodequeryr   r   r  chainsIndexedByIdselectedNetworkIdaddressObjectr  s                 r   fetch_deposit_addresszcex.fetch_deposit_address  su      !!!!!!!!!==&&
 "@@HHU99$++gu:U:UVVVVVVVV* x44OOD+r::	 MM)\BB DDT;Xijj(9;LbQQ$$]I}MM7###%%m5EvNN../@AA
 
 	
r   c                 *    |                                  S N)r   )r   s    r   noncez	cex.nonce  s      """r   rw   GETc                    | j         d         d         dz   |                     ||          z   }|                     ||                     |                    }|dk    r|r|d|                     |          z   z  }n|                                  t          |                                           }	|	| j        z   | j	        z   }
| 
                    |                     |
          |                     | j                  t          j                  }|                     |                     | j	        |                                |	d|                    }ddi}||||d	S )
Nrj   rh   r   rw   ?)r;  	signaturer  zContent-Typezapplication/json)urlmethodbodyheaders)r   implode_paramsr  extract_params	urlencodecheck_required_credentialsr  r  rq   ro   hmacencoderp   hashlibsha256r5  r   upper)r   pathrj   r  r   r  r  r  r  r  authr  s               r   signzcex.sign  sP   iv&,t/B/B4/P/PP		&$"5"5d";";<<(?? 3sT^^E2222++---

%%E48#dk1D		$++d"3"3T[[5M5Mw~^^I99T[[{&__..* * 	   D  2G fdwOOOr   c
                    t          |t                    r|S |dk    rd S |-t          | j        dz   |                     |          z             d|v rd|v r|d         dk    rd S d|v rv|                     |d          }
| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         |
|           t          |          d S )	Ntruez
 returned r=  okerror r   r   )
r9  r  r   r   r5  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r   reasonr  r  r  r  r   requestHeadersrequestBodymessagefeedbacks               r   handle_errorszcex.handle_errors.  s    h%% 	O6>>4tw5		(8K8KKLLL(??xD>T))4h&&x99Gw}t+H001I7T\]]]001I7T\]]])))tr   r  )4__name__
__module____qualname__r   r   r   r   r   r   r
  r   r  r  r  r   r   r'  r  r/  r>  r   rU  r   r   r`  rc  r   rm  rr  r   r{  r   r   floatr	   r  r   r  r  r
   r  r  r  r  r  r  r  r  r  r  r   __classcell__)r   s   @r   r#   r#      s       B B B B BH 8: L L L L -/ e e: e e e eN *, l lV l l l l\) ) ) ) )  *, 	, 	, 	, 	, 	, 	, @DB L LS L LS\ L L L L(
 
 
4 
 
 
 
( 8<$]ajl % % %C %WZ %quvzq{ % % % %N 6 V    @ 6:" G G7 G G G G G0 68 1 1 1F 1 1 1 1 ! ! !5 ! ! ! !F <@d[] A A AS A Abfglbm A A A A$ /1 % %[ % % % %N mqy{ U U UI UY UX] Ufi U U U Un 9=R s sS s# s s s s" 59  c    6t t t5 t t t tl 59tZ^gi ? ?c ? ?TW ?nrsxny ? ? ? ?0 7;\`ik A A A3 AVY Aptuzp{ A A A A$ 8<B r& r&C r& r& r& r& r&h 04$UYbd V V VC Vs Vimnsit V V V VpQ Q Q fjx|  FH 2 23 2 29 2I 2_b 2ru 2 2 2 2< =? 1
 1
 1
 1
 1
 1
f# # # &eBSW P P P P*      r   r#   )) ccxt.async_support.base.exchanger   ccxt.abstract.cexr   r  r5  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr    ccxt.base.preciser!   r#    r   r   <module>r.     sE   6 5 5 5 5 5 ) ) ) ) ) )   ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^       * * * * * * 0 0 0 0 0 0 . . . . . . & & & & & & ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) * * * * * * + + + + + + . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %d d d d d(K d d d d dr   