
    i                    0   d dl mZ d dlm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'  G d dee          Z(dS )    )Exchange)ImplicitAPI)Balances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)	TICK_SIZE)Precisec                   :    e Zd Z fdZi fdZi fdee         fdZi f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 Zd5d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i fded	edefdZddi fdeded	edee         fdZdddi fdeded	edee         fdZ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di fde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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fd%Z-d5d&ede.fd'Z/i fdede.fd(Z0defd)Z1d* Z2d5d&edefd+Z3d5d&edefd,Z4d5d&edefd-Z5d5d&ede*fd.Z6i fdefd/Z7d5defd0Z8d1d2i ddfd3Z9d4 Z: xZ;S )6timexc                 .   |                      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ddddd
dd
d
d
d
d;
d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJidKdLdMdNdOgg dPdQdRg dSidRg dTig dUg dVdQdRg dWidXdYgg dVdQdRg dZidRd[gig d\d]d^gd]d^gd]d^gd_dRg d`ida
t          i dbt
          dct          ddt          det          dft          dgt          dht          dit          djt          dkt          dlt          dmt          dnt          dot          dpt
          dqt          drt          t          t          t          t
          t          dsdtt          idudvdwdxidydzidydzidyd{idyd{idzd{d|d}          S )~Nr%   TimeXAUv1i  CORSspotTmarginFswapfutureoption	addMargincancelOrdercancelOrderscreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchTicker)
fetchTickers	fetchTimefetchTradesfetchTradingFeefetchWithdrawalfetchWithdrawalsreduceMarginsetLeveragesetMarginModesetPositionModeI1I5I15I30H1H2H4H6H12D1W1)1m5m15m30m1h2h4h6h12h1d1wzchttps://user-images.githubusercontent.com/1294454/70423869-6839ab00-1a7f-11ea-8f94-13ae72c31115.jpgrestz%https://plasma-relay-backend.timex.iozhttps://timex.ioz;https://plasma-relay-backend.timex.io/swagger-ui/index.htmlz+https://timex.io/?refcode=1x27vNkTbP1uwkCck)logoapiwwwdocreferralme) zid/{id}zid/{id}/remove)getpostr   )credentialszcredentials/h/{hash}zcredentials/k/{key}zcredentials/mezcredentials/me/addresszdeposit-addresseszdeposit-addresses/h/{hash})orderszorders/detailszorders/export/csvtradesztrades/export/csv)za/{address}i/{id}
s/{symbol})performpreparezremove/performzs/{symbol}/remove/preparezs/{symbol}/update/performzs/{symbol}/update/prepare)deposits	transferswithdrawalsr   r   )candles
currenciesmarkets	orderbookzorderbook/rawzorderbook/v2tickersr   address)balancesfeesr   r   zorders/json)r   r   putdelete)confighistorysymbol_infotime)
addressbookcustodyr   r   managerr   public
statisticstradingtradingview014000400140024003400440054006400743004100440050015002400401)403404429500503Insufficient)exactbroadi3periodr{   sorttimestamp,asccreatedAt,asc)expireInr]   r_   rQ   rT   r<   defaultSortdefaultSortOrders)idname	countriesversion	rateLimithas
timeframesurlsr   precisionMode
exceptionsoptions)deep_extendsuperr%   describer"   r   r   r   r   r   r   r   r   r    r!   )self	__class__s    P/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/timex.pyr   ztimex.describe   s*   eT 2 2 ; ; = =>>> %> 	>
 %> %> U> t> > t> (> '> (> "5> T>  !>" +E#> >$ )%%>& $T'>( ')>* (+>, "4->. />0 &t1>2 (3>4 1%5>6  7>8 &u9>: #E;>< *5=>> $U?>@ "5A>B *5C>D +EE> > >F  G>H %eI>J "5K>L M>N !%O>P  Q>R dS>T +EU>V "4W>X dY>Z !$[>\  ]>^ $U_>` !%a>b %ec>d )%e>f tg> >h !%!##'#($( %$!&#({> > >@   ~C *TI    		  	     
      
         !$     	 	 	 !   !%
 !%
 !% (     Oo o` ' J J	
 - / / J J J , / M L M  :!" .#$ ,(,(/-  2 #$53 < %d! O  O" O$ O&  /%4% S}@
 }@
 } } }	    c                 \    |                      |          }|                     |          dz  S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
          )tradingviewGetTimeparse_to_intr   paramsresponses      r   
fetch_timeztimex.fetch_time  s2     **622   **T11r   returnc                 V    |                      |          }|                     |          S )aI  
        retrieves data on all markets for timex
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listMarkets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )publicGetMarketsparse_marketsr   s      r   fetch_marketsztimex.fetch_markets'  s-     ((00, !!(+++r   c                     |                      |          }g }t          dt          |                    D ]2}||         }|                    |                     |                     3|                     |d          S )aM  
        fetches all available currencies on an exchange
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listCurrencies
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   code)publicGetCurrenciesrangelenappendparse_currencyindex_by)r   r   r   resulticurrencys         r   fetch_currenciesztimex.fetch_currenciesF  s}     ++F334 q#h--(( 	9 	9A{HMM$--h778888}}VV,,,r   Nr   sincelimitc                 @   |                      |d          }|                     |d          }|t          | j        dz             d|i}|                     |                     ||                    }|                     |          }|                     ||||          S )a=  
        fetch all deposits made to an account
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Manager/getDeposits
        :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   N. fetchDeposits() requires an address parameter)safe_stringomitr   r   managerGetDepositsextendsafe_currencyparse_transactions	r   r   r   r   r   r   requestr   r   s	            r   fetch_depositsztimex.fetch_depositsm  s     ""695569--?#DG.^$^___w
 **4;;w+G+GHH %%d++&&x5%HHHr   c                 @   |                      |d          }|                     |d          }|t          | j        dz             d|i}|                     |                     ||                    }|                     |          }|                     ||||          S )aG  
        fetch all withdrawals made to an account
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Manager/getWithdraws
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of transaction 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   Nr   )r   r   r   r   managerGetWithdrawalsr   r   r   r   s	            r   fetch_withdrawalsztimex.fetch_withdrawals  s     ""695569--?#DG.^$^___w
 --dkk'6.J.JKK %%d++&&x5%HHHr   c                     | j         }t          dt          |                    D ]A}||         }|                     |di           }|                     |d          }||k    r|c S Bd S )Nr   infor   )r   r   r   
safe_valuer   )r   r   r   r   r   r  as          r   get_currency_by_addressztimex.get_currency_by_address  sw    _
q#j//** 	  	 A!!}H??8VR88D  y11AG|| tr   r   c                    |                      |d          }|                      |dd          }|                     |          }i d|d|                      |d          d|                      |d          d|                     |          d|d	d d
d d|                      |d          d|                      |d          dd dd dd dd d|                     |d          d|                     d |          dddd d d d dS )N	timestamptokenr   r  r   transferHashtxiddatetimenetworkr   	addressTotoaddressFromfromtagtagTotagFromtypeamountvaluer   statusokupdated)internalcommentfee)r   r  	parse8601safe_numbersafe_currency_code)r   transactionr   r  currencyAddressss        r   parse_transactionztimex.parse_transaction  s    ##K==++K"EE//0@AA
K
$"";??
 D$$[&99
 11	

 
 t
 t
 ))+t<<
 4++K@@
 4
 T
 t
 D
 d&&{G<<
 //h??
  d!
" t#
$ )
 
 
 	
r   symbolsc                 
   |                                   |                     | j        d         dd          }d| j        |         i}|                     |                     ||                    }|                     ||          S )aF  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listTickers
        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r]   r   r{   )load_marketsr   r   r   publicGetTickersr   parse_tickers)r   r#  r   r   r   r   s         r   fetch_tickersztimex.fetch_tickers  s     	!!$,~">$OOdof-
 ((Wf)E)EFF$ !!(G444r   symbolc                 n   |                                   |                     |          }|                     | j        d         dd          }|d         | j        |         d}|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listTickers
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r]   r   r{   r   marketr   r   )	r%  r,  r   r   r   r&  r   	safe_dictparse_ticker)r   r)  r   r,  r   r   r   tickers           r   fetch_tickerztimex.fetch_ticker  s     	V$$!!$,~">$OOTlof-
 
 ((Wf)E)EFF$ !,,  000r   c           	      P   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |                     |d                    }|                     |||dddd	          S )
ah  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/orderbookV2
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r,  r   Nr   r  bidaskpricebaseTokenAmount)r%  r,  publicGetOrderbookV2r   r  r   parse_order_book)r   r)  r   r   r,  r   r   r  s           r   fetch_order_bookztimex.fetch_order_book#  s     	V$$fTl
 $GG,,T[[&-I-IJJ2 NN4#3#3Hk#J#JKK	$$Xvy%PWYjkkkr   c                    |                                   |                     |          }|                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }	|d         |d}
||                     |          |
d<   |||
d<   |                     |                     |
|	                    }| 	                    ||||          S )	aQ  
        get the list of most recent trades for a particular symbol
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listTrades
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r_   r   r   r   )r,  r   Nr  size)
r%  r,  r  r   r   r   iso8601publicGetTradesr   parse_trades)r   r)  r   r   r   r,  r   r   r   queryr   r   s               r   fetch_tradesztimex.fetch_tradesO  s     	V$$//$,rBBoogvGG<<		&&))
 Tl 	
 	
 "ll511GFO#GFO''GU(C(CDD   65%@@@r   rr   c           	         |                                   |                     |          }|d         |                     | j        ||          d}|                     |          }|d}|_|                     |          |d<   |                     |                     ||                     |d          |z  dz                      |d<   nP|                                 }	|                     |	          |d<   |                     |	||z  dz  z
  dz
            |d<   |                     | 	                    ||                    }
| 
                    |
||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Public/listCandles
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   r+  Nr   r     till)r%  r,  r   r   parse_timeframer;  summillisecondspublicGetCandlesr   parse_ohlcvs)r   r)  	timeframer   r   r   r,  r   durationnowr   s              r   fetch_ohlcvztimex.fetch_ohlcv{  sX    	V$$Tl&&t	9MM
 

 ''	22=E"ll511GFO"ll488E488E1;M;MPX;X[_;_+`+`aaGFOO##%%C"ll3//GFO"ll31AD1H+H1+LMMGFO((Wf)E)EFF   69eUKKKr   c                 t   |d d d}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )N)r  r  r  r   r   totalBalancetotallockedBalanceused)r   r   r   r  accountsafe_balance)r   r   r   r   balance
currencyIdr   rQ  s           r   parse_balanceztimex.parse_balance  s    
 

 q#h--(( 	# 	#AqkG))':>>J**:66DllnnG#//HHGG"..wHHGFO"F4LL  (((r   c                 ~    |                                   |                     |          }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/getBalances
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )r%  tradingGetBalancesrU  r   s      r   fetch_balanceztimex.fetch_balance  s?     	**622 !!(+++r   r  sider  r4  c                    |                                   |                     |          }|                                }|                                }	|                     |dd          }
|
rd}	|                     |dg          }|d         |                     ||          ||	d}|}|	dk    s|	dk    r|                     ||          |d<   |                     | j        d          }| 	                    |d	          }| 	                    |d|          }|||d	<   n%|||d<   nt          | j        dz   |z   dz             |                     |d	dg          }nd|d<   |                     |                     ||                    }| 	                    |dg           }|                     |di           }|                     ||          S )a  
        create a trade order
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/createOrder
        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        postOnlyF	POST_ONLYr   )r)  quantityrY  
orderTypesLIMITr4  r   
expireTimeNzD createOrder() method requires a expireTime or expireIn param for a z: order, you can also set the expireIn exchange-wide optionr   r   )r%  r,  upper	safe_boolr   amount_to_precisionprice_to_precisionsafe_integerr   r  r   r   tradingPostOrdersr   r-  parse_order)r   r)  r  rY  r  r4  r   r,  uppercaseSideuppercaseTyper[  r   r>  defaultExpireInr`  r   r   r   orders                      r   create_orderztimex.create_order  s    	V$$



>>&*e<< 	5'MYYv
|44FTl00@@!'	
 
 W$$-;*F*F#66vuEEGG"//jIIO>>Jvz?KKH%(2%%%&.
##"47-s#svz#z  ~z  $z  {  {  {IIf|Z&@AAEE GG))$++gu*E*EFF, 8R88vq"--v...r   r   c                 b   |                                   |                     |          }d|i}	||                     ||          |	d<   ||                     ||          |	d<   |                     |                     |	|                    }
d|
v rE|                     |
dg           }|                     |d          }|                     ||
d          S |                     |
dg           }|                     |di           }| 	                    |di           }| 
                    ||          S )	Nr   r]  r4  unchangedOrdersr   )r   r  changedOrdersnewOrder)r%  r,  rc  rd  tradingPutOrdersr   r  r   
safe_orderr-  rg  )r   r   r)  r  rY  r  r4  r   r,  r   r   orderIdsorderIdr   
firstOrderrk  s                   r   
edit_orderztimex.edit_order  sI   V$$"
 "&":":66"J"JGJ#66vuEEGG((Wf)E)EFF4 ((x1BBGGH&&x33G?? $ $    ?B??__VQ33
z:r::v...r   c                 Z    |                                   |                     |g||          S )a  
        cancels an open order
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/deleteOrders
        :param str id: order id
        :param str symbol: not used by timex cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        )r%  cancel_orders)r   r   r)  r   s       r   cancel_orderztimex.cancel_orderA  s0     	!!2$777r   c                     |                                   d|i}|                     |                     ||                    }|S )a  
        cancel multiple orders
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/deleteOrders
        :param str[] ids: order ids
        :param str symbol: unified market symbol, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r%  tradingDeleteOrdersr   )r   idsr)  r   r   r   s         r   rx  ztimex.cancel_ordersM  sL     	#
 ++DKK,H,HII2 r   c                    |                                   d|i}|                     |          }|                     |di           }|                     |dg           }|                     |                     |d|i                    S )a  
        fetches information on an order made by the user
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/History/getOrderDetails
        :param str symbol: not used by timex fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        	orderHashrk  r   )r%  historyGetOrdersDetailsr  	safe_listrg  r   )r   r   r)  r   r   r   rk  r   s           r   fetch_orderztimex.fetch_orderu  s     	
 //88D '266(B77EHf3E F FGGGr   c                    |                                   |                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }d|i}	d}
| |                     |          }
|
d         |	d<   |||	d<   |                     |                     |	|                    }|                     |dg           }| 	                    ||
||          S )	a@  
        fetch all unfilled currently open orders
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/getOpenOrders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rT   r   r   Nr   r)  r:  r   )
r%  r  r   r   r   r,  tradingGetOrdersr   r  parse_ordersr   r)  r   r   r   r   r   r   r>  r   r,  r   r   s                r   fetch_open_ordersztimex.fetch_open_orders  s    	//$,0A2FFoogvGG<<		&&)) D

 [[((F &tGH#GFO((We)D)DEE, (B77  >>>r   c                 .   |                                   |                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }|dd}	d}
| |                     |          }
|
d         |	d<   ||                     |          |	d	<   |||	d
<   |                     |                     |	|                    }| 	                    |dg           }| 
                    ||
||          S )ah  
        fetches information on multiple closed orders made by the user
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/History/getOrders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r<   r   r   BUY)r   rY  Nr   r)  r  r:  r   )r%  r  r   r   r   r,  r;  historyGetOrdersr   r  r  r  s                r   fetch_closed_ordersztimex.fetch_closed_orders  s)    	//$,0CRHHoogvGG<<		&&)) 	
 
 [[((F &tGH"ll511GFO#GFO((We)D)DEE, (B77  >>>r   c                 ,   |                                   |                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }d|i}	d}
| |                     |          }
|
d         |	d<   ||                     |          |	d<   |||	d<   |                     |                     |	|                    }| 	                    |d	g           }| 
                    ||
||          S )
a,  
        fetch all trades made by the user
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/History/getTrades_1
        :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>`
        rQ   r   r   Nr   r)  r  r:  r   )r%  r  r   r   r   r,  r;  historyGetTradesr   r  r=  )r   r)  r   r   r   r   r   r   r>  r   r,  r   r   s                r   fetch_my_tradesztimex.fetch_my_trades  s"    	//$,DDoogvGG<<		&&)) D
 [[((F &tGH"ll511GFO#GFO((We)D)DEE& (B77  >>>r   r,  c                     |                      |d          }|                     |d          }||                     ||          ||d d dS )Nr,  r  )r  r)  makertaker
percentage	tierBased)r   r  safe_symbol)r   r  r,  marketIdrates        r   parse_trading_feeztimex.parse_trading_feeK  s_     ##C22U++&&x88
 
 	
r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetch the trading fees for a market
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Trading/getFees
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r   r   )r%  r,  tradingGetFeesr   r  r  )r   r)  r   r,  r   r   r   s          r   fetch_trading_feeztimex.fetch_trading_fee]  s     	V$$vd|
 &&t{{7F'C'CDD 1b11%%ff555r   c                    |                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     |d          }|                     |d          }	t          j        ||	          }
|                     |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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lockedr)  baseCurrencyquoteCurrencyquantityIncrementbaseMinSizetickSizequoteMinSizer   /basequotesettlebaseIdquoteIdsettleIdr  r+   Tr,   Fr-   r.   r/   activecontractlineartakerFeemakerFee)r  r4  minmax)leverager  r4  cost)inverser  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr  )r  r   r  r#   
string_maxr  parse_number)r   r,  r  r   r  r  r  r  amountIncrementminBase	minAmountpriceIncrementminCosts                r   parse_marketztimex.parse_marketv  s   ( 22fh//!!&.99""6?;;&&v..''00**63FGG""6=99&@@	))&*==""6>::2
"2
dSj5(2
 D2
 U	2

 d2
 f2
 w2
 2
 F2
 D2
 e2
 E2
 e2
 e2
 &j2
  !2
" d#2
$ %%fj99%%fj99 "**63FGG))&*==    
  ,,Y77 
  ,,^<< 
 #  $ c2
 2
 2
 2	
r   c                    |                      |d          }|                     |          }|                      |d          }|                     |d          }|                     |d          }|                     |d          }|o|o|}|                      |d          }	|                     |d          }
d }|	|
~t	          |	          }||
z
  }|dk    r1|	d|         }|	| d          }|                     |d	z   |z             }n3d	}t          d|           D ]}|d
z  }|                     ||	z             }|||d ||||||                     |                     |                      |d                              |d dd d ddi dS )Nr)  r   depositEnabledwithdrawalEnabledr  withdrawalFeetradeDecimalsr   .r   decimalsr  )withdrawr  )r   r   r  r  r   r  depositr  r  r  r  networks)r   r  r  re  r   r  r   parse_precision)r   r   r   r   r   r  withdrawEnabledisActiver  	feeStringr  r  feeStringLendotIndexwholefractionr   s                    r   r   ztimex.parse_currency  s   L h11&&r**&113CDD//(4GHH??8X66@O@$$X??	))(ODD!(Ay>>L#m3H!||!!H*-$hYZZ0''h(>??q8),, $ $AOHH''9(<==%'**4+?+?@P@PQY[e@f@f+g+ghh$'55"&t44  
 
 	
r   c           	         |                      |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|          S )Nr,  r  r  lastopenr)  r  r  highlowr2  	bidVolumer3  	askVolumevwapclosepreviousClosechanger  volumevolumeQuote)average
baseVolumequoteVolume)r   r  r  safe_tickerr;  )r   r/  r,  r  r)  r  r  r  s           r   r.  ztimex.parse_ticker  s     ##FH55!!(FC88NN4#3#3FK#H#HII	//// !
f!
F!
 !
 Y//	!

 D$$VV44!
 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
  d!!
" $#!
$ **68<<++FMBB)!
 !
 !
* +  	r   c                 >   |                      |d          }|                     ||          }|                     |                      |d                    }|                      |d          }|                      |d          }|                     |          }|                     |          }	|                     t	          j        ||                    }
|                      |d          }|                     |dd          }|                     |d          }d }||                      ||d	z             }d }|                     |d
          }| 	                    |                      |d                    }|||d}|||| 
                    |          ||d |||	|
||dS )Nr)  r  r4  r]  r   	directionrY  makerOrTakerOrderIdr  feeToken)r  r   )r  r   r  r  r)  rk  r  rY  r4  r  r  takerOrMakerr  )r   r  r  r  r#   
string_mulsafe_string_lower_2safe_string_lowerr  r  r;  )r   trader,  r  r)  r  priceStringamountStringr4  r  r  r   rY  r  rt  r  feeCostfeeCurrencys                     r   parse_tradeztimex.parse_tradeD  s   8 ##E844!!(F33NN4#3#3E;#G#GHH	&&ug66''z::!!+..""<00  !3K!N!NOOeT**''{FCC--e^DD#&&ulY.FGGG""5%00--d.>.>uj.Q.QRR' C
 "Y//(
 
 	
r   c           	      (   |                      |                     |d                    |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr  r  r  r  r  r  )r  r   r  )r   ohlcvr,  s      r   parse_ohlcvztimex.parse_ohlcv  s     NN4++E;??@@UF++UF++UE**UG,,UH--
 	
r   c           	      f   |                      |d          }|                     |d          }|                     |d          }|                      |d          }|                     ||          }|                     |                      |d                    }|                      |d          }	|                      |d          }
|                      |d          }|                     |                      |d	                    }t          j        ||
          rd
}n|d}nd}|                     |dg           }|                      |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   r  rY  r)  	createdAtr4  r]  filledQuantitycancelledQuantityclosedcanceledr  r   clientOrderIdr  r  r  lastTradeTimestamptimeInForcer[  	stopPricetriggerPricer  r  r  )filled	remainingr  r  r   )
r   r  r  r  	omit_zeror#   string_equalsr  rr  r;  )r   rk  r,  r   r  rY  r  r)  r  r4  r  r  canceledQuantityr  	rawTradesr  s                   r   rg  ztimex.parse_order  s]   * eT**%%eV44%%eV44##E844!!(F33NN4#3#3E;#G#GHH	  00!!%44!!%)9::>>$*:*:5BU*V*VWW 00 	FF)FFFOOE8R88	((@@  
E 
" 
 ] 
 	 

 Y// 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
  
 D 
 f 
  D! 
" t# 
$ - 
  
  
. /  	r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetch the deposit address for a currency associated with self account, does not accept params["network"]
        :see: https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/Currency/selectCurrencyBySymbol
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r)  r   r   )r%  r   currenciesGetSSymbolr   r-  parse_deposit_address)r   r   r   r   r   r   datas          r   fetch_deposit_addressztimex.fetch_deposit_address  s     	==&&hv&
 ,,T[[&-I-IJJ$ ~~h
B77))$999r   c                     |                      |d          }||                     ||          |                      |d          d d dS )Nr)  r   )r  r   r   r  r  )r   r  )r   depositAddressr   rT  s       r   r  ztimex.parse_deposit_address  sW     %%nh??
"//
HEE''	BB
 
 	
r   r   GETc                    |                      |          }|                     ||          }|                     ||          }| j        d         d         dz   |z   dz   |z   }|r|d|                     |          z   z  }|dk    rH|dk    rB|                                  |                     | j        dz   | j        z             }	d|	z   }
d	|
i}||||d
S )Nr   r}   r  ?r   r   :zBasic authorization)urlmethodbodyheaders)	extract_paramsimplode_paramsr   r   urlencode_with_array_repeatcheck_required_credentialsstring_to_base64apiKeysecret)r   pathr   r  r   r  r  paramsToExtractr  authr   s              r   signz
timex.sign  s    --d33""4006?33iv&,s2S84? 	B399&AAAAC(??sm33++---((s):T[)HIID_F&/GfdwOOOr   c
                    |d S |dk    r| j         dz   |z   }
|                     |d          }||}|                     |dd          }|                     |dd          }|                     | j        d         ||
           |                     | j        d	         ||
           |                     | j        d	         ||
           t          |
          d S )
Ni   errorr   r  messagedebugMessager   r   )r   r  safe_string_2throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r   
statusCode
statusTextr  r  responseHeadersresponseBodyr   requestHeadersrequestBodyfeedbackr'  r   r(  s                 r   handle_errorsztimex.handle_errors$  s    4
 w}|3HOOHg66E} %%eVX>>D((	>JJG001I7T\]]]001I4QYZZZ001I7T\]]])))tr   )N)<__name__
__module____qualname__r   r   r   r	   r   r   r   r   r   r   r   r   r  r   r"  r   r   r(  strr   r0  r   r8  r   r?  listrK  r   rU  rX  r   r   floatr
   rl  rv  ry  rx  r  r   r  r  r  r   r  r  r  r   r.  r  r  rg  r  r  r$  r4  __classcell__)r   s   @r   r%   r%      s       ~ ~ ~ ~ ~@ !# 
2 
2 
2 
2 $& , ,$v, , , , ,> ') %- %-Z %- %- %- %-N *.Dt\^ I I3 Ic I Icghsct I I I IB -1tRV_a I Ic I IC Ifjkvfw I I I IB  #
 #
x #
; #
 #
 #
 #
J 04B 5 5W 57 5 5 5 5B 02 "1 "13 "1f "1 "1 "1 "1H :>b *l *ls *l3 *lY *l *l *l *lX 6:UW *A *A3 *As *A# *A\`af\g *A *A *A *AX 26DW[df *L *L# *Lc *LQT *Lkoptku *L *L *L *LX) ) ) ) )  $& , ,( , , , ,( gksu D/ D/3 D/i D/y D/RW D/`c D/ D/ D/ D/L `drv  @B ./ ./S ./# ./Y ./i ./Y\ ./lo ./ ./ ./ ./` 37r 
8 
8s 
8C 
8 
8 
8 
8 04B & & & & & &P 26b 0H 0Hc 0H3 0H 0H 0H 0Hd /3TXac 1? 1? 1?3 1?c 1?hlmrhs 1? 1? 1? 1?f 154VZce 5? 5?# 5?S 5?PS 5?jnotju 5? 5? 5? 5?n -1tRV_a 8? 8?c 8? 8?C 8? 8? 8? 8?t
 
V 
?R 
 
 
 
$ 57 6 6 6;N 6 6 6 62Q
f Q
 Q
 Q
 Q
fM
 M
 M
^* *6 *V * * * *X@
 @
 @
5 @
 @
 @
 @
D
 
 
4 
 
 
 
*? ? ?5 ? ? ? ?B 79  :  :#  :  :  :  :D
 
h 
 
 
 
0 &eBSW P P P P      r   r%   N))ccxt.base.exchanger   ccxt.abstract.timexr   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!   ccxt.base.decimal_to_precisionr"   ccxt.base.preciser#   r%    r   r   <module>rD     sK   ( ' ' ' ' ' + + + + + + }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }  }       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 4 4 4 4 4 4 % % % % % %] ] ] ] ]Hk ] ] ] ] ]r   