
    !:h'                    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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*y)    )Exchange)ImplicitAPI)AnyBalances
CurrenciesCurrencyDepositAddress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def fdZi fde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d?de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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/d?d'ed(ede0fd)Z1i fdede0fd*Z2d(edefd+Z3dedefd,Z4d?d-ed(edefd.Z5d?d/ed(edefd0Z6d?d(edefd1Z7d?d2ed(ede,fd3Z8i fdede9fd4Z:d?dede9fd5Z;d6d7i ddfd8Z<d9e=d:ed;ed<ed=ef
d>Z> xZ?S )@timexreturnc                  ^   | j                  t        t        |          dddgddi dd ddd	d
dd
dd
dd
dd
dddddddd
dd
dd
dd
dddddd
i dd
dddd
dd
dddd
ddd d
d!d
d"dd#d
d$d
d%d
d&d
d'd
d(d
d)d
i d*d
d+d
d,d
d-dd.d
d/dd0dd1d
d2dd3dd4dd5d
d6d
d7d
d8d
d9d
d:d
d
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
d
d
d
d d
d
d ddd
dd}d
d
d
d
d
d
d
d~d d
dddd
dd
d
d
d
dd
dd
d
d
dd d
ddddd
d
d
ddd id	d d dd d d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fetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistory)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)expireInrc   re   rT   rW   r?   defaultSortdefaultSortOrders)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergd   i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r      )r   r   r   daysBackCanceledr   r   r   r   r   )	sandboxr6   createOrdersrT   rX   rW   fetchOrdersr?   rU   )linearinverse)r.   r0   r1   )idname	countriesversion	rateLimithas
timeframesurlsr   precisionMode
exceptionsoptionsfeatures)deep_extendsuperr'   describer$   r   r!   r   r   r   r   r    r   r"   r#   )self	__class__s    R/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/timex.pyr   ztimex.describe   sv   eT ; =AAA %A 	A
 %A %A UA tA A tA (A 'A (A "5A TA  !A" +E#A$ )%%A& $T'A( ')A* (+A, "4-A. /A0 &t1A2 (3A4 1%5A6  7A8 &u9A: #E;A< *5=A> $U?A@ "5AAB *5CAD +EEAF  GAH %eIAJ "5KAL MAN !%OAP  QAR dSAT +EUAV "4WAX dYAZ !$[A\  ]A^ '_A` $UaAb !%cAd *5eAf (gAh ',*/# $!##'#($( %$!&#(AAF  ~C *TI 		   
  
    !$  	 ! !%
 !%
 !%(   Oo` ' J J	
 - / / J J J , / M L M  :!" .#$ ,(,(/-2 #$53< %d! O  O" O$ O&  /%4%,  %&+(-,1,0).+06: $(#'"'#'	( #($)$)+027/4#(+$. %)&+!$$*%+*/& ',#($)*/	# ',!$#($)*/( $(&+!$$*,-%+#($)*/	*  #s<| ##
 ##EFAG@
 G G	    c                 h   K   | j                  |       d{   }| j                  |      dz  S 7 w)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
        N  )tradingviewGetTimeparse_to_intr   paramsresponses      r   
fetch_timeztimex.fetch_timee  s8      0088   *T11	 9s   202c                 b   K   | j                  |       d{   }| j                  |      S 7 w)aE  
        retrieves data on all markets for timex

        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
        N)publicGetMarketsparse_marketsr  s      r   fetch_marketsztimex.fetch_marketsq  s3      ..v66, !!(++- 7   /-/c                 b   K   | j                  |       d{   }| j                  |      S 7 w)aI  
        fetches all available currencies on an exchange

        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
        N)publicGetCurrenciesparse_currenciesr  s      r   fetch_currenciesztimex.fetch_currencies  s3      11&994 $$X..5 :r  Ncodesincer   c                 .  K   | j                  |d      }| j                  |d      }|t        | j                  dz         d|i}| j	                  | j                  ||             d{   }| j                  |      }| j                  ||||      S 7 )w)a9  
        fetch all deposits made to an account

        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  currencys	            r   fetch_depositsztimex.fetch_deposits  s      ""69569-?#DGG.^$^__w
 00Wf1MNN %%d+&&x5%HH O   A'B)B**Bc                 .  K   | j                  |d      }| j                  |d      }|t        | j                  dz         d|i}| j	                  | j                  ||             d{   }| j                  |      }| j                  ||||      S 7 )w)aC  
        fetch all withdrawals made to an account

        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69-?#DGG.^$^__w
 33DKK4PQQ %%d+&&x5%HH Rr  c                     | j                   }t        dt        |            D ]5  }||   }| j                  |di       }| j	                  |d      }||k(  s3|c S  y )Nr   infor   )r   rangelen
safe_valuer  )r   r   r   ir  r#  as          r   get_currency_by_addressztimex.get_currency_by_address  sc    __
q#j/* 	 A!!}H??8VR8D  y1AG|	  r   transactionr  c                    | j                  |d      }| j                  |dd      }| j                  |      }i d|d| j                  |d      d| j                  |d      d| j                  |      d|d	d d
d d| j                  |d      d| j                  |d      dd dd dd dd d| j                  |d      d| j	                  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   r*  r  r0  currencyAddressss        r   parse_transactionztimex.parse_transaction  su    ##K=++K"E//0@A
K
$"";?
 D$$[&9
 1	

 
 t
 t
 ))+t<
 4++K@
 4
 T
 t
 D
 d&&{G<
 //h?
  d!
" t#
$ )
 	
r   symbolsc                   K   | j                          d{    | j                  | j                  d   dd      }d| j                  |   i}| j	                  | j                  ||             d{   }| j                  ||      S 7 p7 w)aB  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        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>`
        Nrc   r   r   )load_marketsr  r   r   publicGetTickersr  parse_tickers)r   rG  r  r   r  r  s         r   fetch_tickersztimex.fetch_tickers,  s      !!!!!$,,~">$Odoof-
 ..t{{7F/KLL$ !!(G44/ 	"
 Ms"   BBAB0B	1B	Bsymbolc                 h  K   | j                          d{    | j                  |      }| j                  | j                  d   dd      }|d   | j                  |   d}| j                  | j                  ||             d{   }| j                  |d      }| j                  ||      S 7 7 *w)a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        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>`
        Nrc   r   r   r   marketr   r   )	rI  rP  r  r   r   rJ  r  	safe_dictparse_ticker)r   rM  r  rP  r   r  r  tickers           r   fetch_tickerztimex.fetch_tickerO  s      !!!V$!!$,,~">$OTloof-
 ..t{{7F/KLL$ !,  005 	" Ms"   B2B.A.B2B0)B20B2c           	      B  K   | j                          d{    | j                  |      }d|d   i}|||d<   | j                  | j                  ||             d{   }| j	                  | j                  |d            }| j                  |||dddd	      S 7 7 >w)
ad  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        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
        NrP  r   r   r,  bidaskpricebaseTokenAmount)rI  rP  publicGetOrderbookV2r  rB  r  parse_order_book)r   rM  r   r  rP  r  r  r,  s           r   fetch_order_bookztimex.fetch_order_booku  s      !!!V$fTl
 $GG224;;w3OPP2 NN4#3#3Hk#JK	$$Xvy%PWYjkkC 	" Qs"   BBABB=BBc                   K   | j                          d{    | j                  |      }| j                  | j                  di       }| j                  |dd      }| j	                  |d|      }| j                  |d      }	|d   |d}
|| j                  |      |
d<   |||
d<   | j                  | j                  |
|	             d{   }| j                  ||||      S 7 7 w)	aM  
        get the list of most recent trades for a particular symbol

        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>`
        Nre   r   r   r   )rP  r   r5  size)
rI  rP  r&  r   r  r  iso8601publicGetTradesr  parse_trades)r   rM  r  r   r  rP  r   r   r   queryr  r  s               r   fetch_tradesztimex.fetch_trades  s      !!!V$//$,,rBoogvG<		&&)
 Tl 	
 "ll51GFO#GFO--dkk'5.IJJ   65%@@A 	"( Ks"   C'C#B3C'
C%C'%C'rx   c           	        K   | j                          d{    | j                  |      }|d   | j                  | j                  ||      d}| j	                  |      }| j                  |d      }	|d}|f| j                  |      |d<   |	;| j                  | j                  || j                  |d      |z  dz              |d<   n| j                  |	      |d<   n|	D| j                  |	      |d<   |	| j                  |d      |z  dz  z
  }
| j                  |
      |d<   nT| j                         }| j                  |      |d<   | j                  || j                  |d      |z  dz  z
  dz
        |d<   | j                  |d      }| j                  | j                  ||             d{   }| j                  |||||      S 7 7 w)	a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        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
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   rO  untilr   r5  r   till)rI  rP  r  r   parse_timeframesafe_integerr_  summillisecondsr  publicGetCandlesr  parse_ohlcvs)r   rM  	timeframer  r   r  rP  r  durationre  fromTimestampnowr  s                r   fetch_ohlcvztimex.fetch_ohlcv  s     !!!V$Tl&&t	9M

 ''	2!!&'2=E"ll51GFO}"&,,txxtxxq?QT\?\_c?c/d"e"&,,u"5"ll51GFO!DHHUA$6$AD$HHM"ll=9GFO##%C"ll3/GFO"ll3%1Ch1NQU1U+UXY+YZGFO67+..t{{7F/KLL   69eUKKQ 	"4 Ms"   GGFG.G/GGc                 2   |d d d}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )N)r#  r,  r0  r   r  totalBalancetotallockedBalanceused)r$  r%  r  rD  accountsafe_balance)r   r  resultr'  balance
currencyIdr  rw  s           r   parse_balanceztimex.parse_balance	  s    

 q#h-( 	#AqkG))':>J**:6DllnG#//HGG"..wHGFO"F4L	#   ((r   c                    K   | j                          d{    | j                  |       d{   }| j                  |      S 7 .7 w)a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        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>`
        N)rI  tradingGetBalancesr|  r  s      r   fetch_balanceztimex.fetch_balance  sI      !!!0088 !!(++ 	"8s   A	AA	AA	A	r9  sider:  rX  c                 D  K   | j                          d{    | j                  |      }|j                         }|j                         }	| j                  |dd      }
|
rd}	| j	                  |dg      }|d   | j                  ||      ||	d}|}|	dk(  s|	dk(  r| j                  ||      |d<   | j                  | j                  d	      }| j                  |d
      }| j                  |d	|      }|||d
<   n&|||d	<   nt        | j                  dz   |z   dz         | j	                  |d
d	g      }nd|d<   | j                  | j                  ||             d{   }| j                  |dg       }| j                  |di       }| j                  ||      S 7 7 ?w)a  
        create a trade order

        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 fulfilled, 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>`
        NpostOnlyF	POST_ONLYr   )rM  quantityr  
orderTypesLIMITrX  r   
expireTimezD createOrder() method requires a expireTime or expireIn param for a z: order, you can also set the expireIn exchange-wide optionr   r   )rI  rP  upper	safe_boolr  amount_to_precisionprice_to_precisionrh  r   r&  r   r   tradingPostOrdersr  rQ  parse_order)r   rM  r9  r  r:  rX  r  rP  uppercaseSideuppercaseTyper  r  rb  defaultExpireInr  r   r  r   orders                      r   create_orderztimex.create_order/  s     !!!V$



>>&*e<'MYYv
|4FTl00@!'	
 W$-;*F#66vuEGG"//jIO>Jvz?KH%(2%%&.
#"477-s#svz#z  ~z  $z  {  {IIf|Z&@AE GG//GU0KLL, 8R8vq"-v..q 	"@ Ms"   F FEF F=F F r   c                 *  K   | j                          d {    | j                  |      }d|i}	|| j                  ||      |	d<   || j                  ||      |	d<   | j	                  | j                  |	|             d {   }
d|
v r9| j                  |
dg       }| j                  |d      }| j                  ||
d      S | j                  |
dg       }| j                  |di       }| j                  |di       }| j                  ||      S 7 7 w)	Nr   r  rX  unchangedOrdersr   )r   r#  changedOrdersnewOrder)rI  rP  r  r  tradingPutOrdersr  r&  r  
safe_orderrQ  r  )r   r   rM  r9  r  r:  rX  r  rP  r  r  orderIdsorderIdr   
firstOrderr  s                   r   
edit_orderztimex.edit_orderw  s/    !!!V$"
 "&":":66"JGJ#66vuEGG..t{{7F/KLL4 (x1BBGH&&x3G?? $   ?B?__VQ3
z:r:v..[ 	" Ms#   DDA+DDBDDc                    K   | j                          d{    | j                  |g||       d{   }| j                  |d      S 7 27 w)a  
        cancels an open order

        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>`
        Nr   )rI  cancel_ordersrQ  )r   r   rM  r  r   s        r   cancel_orderztimex.cancel_order  sM      !!!))2$??~~fa(( 	"?s   AA	AAAAc           	        K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  |dg       }| j                  |dg       }g }t	        dt        |            D ]7  }	| j                  ||	   d      }
|j                  | j                  |
             9 t	        dt        |            D ],  }	|j                  | j                  ||	   ||	   dd             . |S 7 7 íw)	a  
        cancel multiple orders

        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>`
        Nr   r  r  r   r  	unchanged)r#  r   r<  )
rI  tradingDeleteOrdersr  	safe_listr$  r%  rQ  appendr  r  )r   idsrM  r  r  r  r  r  r   r'  r  s              r   r  ztimex.cancel_orders  s     !!!#
 11$++gv2NOO4 x"E..3DbIq#m,- 	6A~~mA&6
CHMM$**845	6 q#o./ 	AMM$//'*%a(%+  	 U 	" Ps"   D	D,D	DCD	D	c                   K   | j                          d{    d|i}| j                  |       d{   }| j                  |di       }| j                  |dg       }| j	                  | j                  |d|i            S 7 j7 Ow)a  
        fetches information on an order made by the user

        https://plasma-relay-backend.timex.io/swagger-ui/index.html?urls.primaryName=Relay#/History/getOrderDetails

        :param str id: order id
        :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>`
        N	orderHashr  r   )rI  historyGetOrdersDetailsr&  r  r  r  )r   r   rM  r  r  r  r  r   s           r   fetch_orderztimex.fetch_order  s      !!!
 55g>>D '26(B7EHf3E FGGQ 	" ?s    BBBBABBc                   K   | j                          d{    | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }d|i}	d}
|| j                  |      }
|
d   |	d<   |||	d<   | j                  | j                  |	|             d{   }| j                  |dg       }| j                  ||
||      S 7 7 -w)	a<  
        fetch all unfilled currently open orders

        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>`
        NrW   r   r   r   rM  r^  r   )
rI  r&  r   r  r  rP  tradingGetOrdersr  r  parse_ordersr   rM  r  r   r  r   r   r   rb  r  rP  r  r   s                r   fetch_open_ordersztimex.fetch_open_orders"  s     !!!//$,,0A2FoogvG<		&&) D

 [[(F &tGH#GFO..t{{7E/JKK, (B7  >>O 	"  Ls"   C,C(B%C,<C*=,C,*C,c                 
  K   | j                          d{    | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }|dd}	d}
|| j                  |      }
|
d   |	d<   || j                  |      |	d	<   |||	d
<   | j                  | j                  |	|             d{   }| j                  |dg       }| j                  ||
||      S 7 7 -w)ad  
        fetches information on multiple closed orders made by the user

        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>`
        Nr?   r   r   BUY)r   r  r   rM  r5  r^  r   )rI  r&  r   r  r  rP  r_  historyGetOrdersr  r  r  r  s                r   fetch_closed_ordersztimex.fetch_closed_ordersW  s     !!!//$,,0CRHoogvG<		&&) 	
 [[(F &tGH"ll51GFO#GFO..t{{7E/JKK, (B7  >>W 	"( Ls"   DC?B<DD,DDc                   K   | j                          d{    | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }d|i}	d}
|| j                  |      }
|
d   |	d<   || j                  |      |	d<   |||	d<   | j                  | j                  |	|             d{   }| j                  |d	g       }| j                  ||
||      S 7 7 -w)
a(  
        fetch all trades made by the user

        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>`
        NrT   r   r   r   rM  r5  r^  r   )rI  r&  r   r  r  rP  r_  historyGetTradesr  r  ra  )r   rM  r  r   r  r   r   r   rb  r  rP  r  r   s                r   fetch_my_tradesztimex.fetch_my_trades  s     !!!//$,,DoogvG<		&&) D
 [[(F &tGH"ll51GFO#GFO..t{{7E/JKK& (B7  >>] 	"4 Ls"   DC>B;DD ,D DrA  rP  c                 |    | j                  |d      }| j                  |d      }|| j                  ||      ||d d dS )NrP  rA  )r#  rM  makertaker
percentage	tierBased)r  rC  safe_symbol)r   rA  rP  marketIdrates        r   parse_trading_feeztimex.parse_trading_fee  sQ     ##C2U+&&x8
 	
r   c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)a~  
        fetch the trading fees for a market

        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>`
        Nr   r   r   )rI  rP  tradingGetFeesr  r&  r  )r   rM  r  rP  r  r  ry  s          r   fetch_trading_feeztimex.fetch_trading_fee  s      !!!V$vd|
 ,,T[[&-IJJ 1b1%%ff55 	"
 K"   BBA BB*BBc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }| j                  |d      }	t        j                  ||	      }
| j                  |d      }| j                  |d      }i d	|d|d
z   |z   d|d|dd d|d|dd ddddddddddddd| dddd d | j                  |d      | j                  |d      d d d d d | j                  |d      | j                  |d      dd d d| j                  |
      d d| j                  |      d d|d dd d |d!S )"NlockedrM  baseCurrencyquoteCurrencyquantityIncrementbaseMinSizetickSizequoteMinSizer   /basequotesettlebaseIdquoteIdsettleIdr9  r.   Tr/   Fr0   r1   r2   activecontractr   takerFeemakerFee)r:  rX  minmax)r   r:  rX  cost)r   r  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr#  )r&  r  rD  r%   
string_maxrC  parse_number)r   rP  r  r   r  r  r  r  amountIncrementminBase	minAmountpriceIncrementminCosts                r   parse_marketztimex.parse_market  sY   ( 2fh/!!&.9""6?;&&v.''0**63FG""6=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%%fj9 "**63FG))&*=  
  ,,Y7
  ,,^<
 #$ c2
 2	
r   c                    | j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|xr |xr |}| j                  |d      }	| j                  |d      }
d }|	g|
et	        |	      }||
z
  }|dkD  r#|	d| }|	| d  }| j                  |d	z   |z         }n-d	}t        d|       D ]  }|d
z  }	 | j                  ||	z         }| j                  |||d |||||| j                  | j                  | j                  |d                  |d dd d ddi d      S )NrM  r   depositEnabledwithdrawalEnabledr  withdrawalFeetradeDecimalsr   .r   decimalsr  )withdrawr:  )r   r  r#  r9  r   r  depositr  rA  r  r  networks)	r  rD  r&  rh  r%  r  r$  safe_currency_structureparse_precision)r   r  r   r  r   r  withdrawEnabledisActiver  	feeStringr  rA  feeStringLendotIndexwholefractionr'  s                    r   parse_currencyztimex.parse_currencyL  s   L h1&&r*&13CD//(4GH??8X6@O@$$X?	))(OD!(Ay>L#m3H!|!!H-$hYZ0''h(>?q8), $AOH$''9(<=++%'**4+?+?@P@PQY[e@f+gh$'5"&t4 -
  	r   rS  c           	      J   | j                  |d      }| j                  ||d      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  i d|d|d|d| j	                  |      d	| j                  |d	      d
| j                  |d
      d| j                  |d      dd d| j                  |d      dd dd d|d|d|dd dd dd d | j                  |d      | j                  |d      d|      S )NrP  r  r,  lastopenrM  r#  r0  highlowrV  	bidVolumerW  	askVolumevwapclosepreviousClosechanger  volumevolumeQuote)average
baseVolumequoteVolume)r  r  rB  safe_tickerr_  )r   rS  rP  r  rM  r,  r  r   s           r   rR  ztimex.parse_ticker  s     ##FH5!!(FC8NN4#3#3FK#HI	// !
f!
F!
 !
 Y/	!

 D$$VV4!
 4##FE2!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
  d!!
" $#!
$ **68<++FMB)!
* + 	r   tradec                    | j                  |d      }| j                  ||      }| j                  | j                  |d            }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }	| j                  t	        j
                  ||            }
| j                  |d      }| j                  |dd      }| j                  |d      }d }|| j                  ||d	z         }d }| j                  |d
      }| j                  | j                  |d            }|||d}| j                  |||| j                  |      ||d |||	|
||d      S )NrM  r,  rX  r  r   	directionr  makerOrTakerOrderIdrA  feeToken)r  r  )r#  r   r,  r0  rM  r  r9  r  rX  r:  r  takerOrMakerrA  )r  r  rB  r  r%   
string_mulsafe_string_lower_2safe_string_lowerrC  rD  
safe_trader_  )r   r  rP  r  rM  r,  priceStringamountStringrX  r:  r  r   r  r  r  rA  feeCostfeeCurrencys                     r   parse_tradeztimex.parse_trade  s   8 ##E84!!(F3NN4#3#3E;#GH	&&ug6''z:!!+.""<0  !3!3K!NOeT*''{FC--e^D#&&ulY.FGG""5%0--d.>.>uj.QR'C "Y/( 
  	r   c           	          | j                  | j                  |d            | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr,  r   r  r  r  r	  )rB  r  rC  )r   ohlcvrP  s      r   parse_ohlcvztimex.parse_ohlcv	  sw     NN4++E;?@UF+UF+UE*UG,UH-
 	
r   r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  | j                  |d            }| j                  |d      }	| j                  |d      }
| j                  |d      }| j	                  | j                  |d	            }t        j                  ||
      rd
}n|d}nd}| j                  |dg       }| j                  |d      }| j                  i d|d|d|d|d| j                  |      dd d|d|dd dd d|d|	dd d|
dd dd d|d |d |d|      S )Nr   r9  r  rM  	createdAtrX  r  filledQuantitycancelledQuantityclosedcanceledr   r   clientOrderIdr#  r,  r0  lastTradeTimestampr   r  r   r:  r  r  filled)	remainingr<  rA  r   )
r  r  r  rB  	omit_zeror%   string_equalsr&  r  r_  )r   r  rP  r   r9  r  r  rM  r,  rX  r:  r*  canceledQuantityr<  	rawTradesr(  s                   r   r  ztimex.parse_order  s   * eT*%%eV4%%eV4##E84!!(F3NN4#3#3E;#GH	  0!!%4!!%)9:>>$*:*:5BU*VW  0F)FFOOE8R8	((@  
E 
" 
 ] 
 	 

 Y/ 
 !$ 
 f 
 D 
 4 
  
 D 
 U 
 D 
 f 
 D 
  t! 
" f# 
$ + 
, - 	r   c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)a  
        fetch the deposit address for a currency associated with self account, does not accept params["network"]

        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>`
        NrM  r  r  )rI  r  currenciesGetSSymbolr  rQ  parse_deposit_address)r   r  r  r  r  r  datas          r   fetch_deposit_addressztimex.fetch_deposit_address^  s      !!!==&hv&
 224;;w3OPP$ ~~h
B7))$991 	"
 Qr  c                 v    | j                  |d      }|| j                  ||      d | j                  |d      d dS )NrM  r   )r#  r  r1  r   r6  )r  rD  )r   depositAddressr  r{  s       r   r2  ztimex.parse_deposit_address  sI     %%nh?
"//
HE''	B
 	
r   r   GETc                    | j                  |      }| j                  ||      }| j                  ||      }| j                  d   d   dz   |z   dz   |z   }|r|d| j	                  |      z   z  }|dk7  rI|dk7  rD| j                          | j                  | 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<  authrF  s              r   signz
timex.sign  s    --d3""406?3iiv&,s2S84?399&AAAC(?sm3++-((s):T[[)HID_F&/GfdwOOr   
statusCode
statusTextr<  r=  responseHeadersc
                    |y |dk\  r| j                   dz   |z   }
| j                  |d      }||}| j                  |dd      }| j                  |dd      }| j                  | j                  d   ||
       | j                  | j                  d	   ||
       | j                  | j                  d	   ||
       t        |
      y )
Ni   errorr  r<  messagedebugMessager   r   )r   r&  safe_string_2throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r   rK  rL  r<  r=  rM  responseBodyr  requestHeadersrequestBodyfeedbackrP  r  rQ  s                 r   handle_errorsztimex.handle_errors  s    
 ww}|3HOOHg6E} %%eVX>D((	>JG001I7T\]001I4QYZ001I7T\]))r   )N)@__name__
__module____qualname__r   r   r
   r  r   r   r
  r   r  r   r   r  r!  r)  dictr   rF  r   r   rL  strr   rT  r   r\  r   rc  listrq  r   r|  r  r   r   floatr   r  r  r  r  r  r   r  r  r  r   r  r  r  r  rR  r  r!  r  r	   r4  r2  rJ  intrZ  __classcell__)r   s   @r   r'   r'      sh   H# HT
 ') 
2S 
2 *, ,V ,B -/ #/: #/J 04$UYbd !I !IC !Is !Iimnyiz !IF 37TX\eg !IC !Is !IRU !Ilpq|l} !IF#
T #
X #
Q\ #
J 6:" !57 !5 !5F 68 $1 $1F $1L @DB ,lS ,l ,lS\ ,l\ <@d[] ,A ,AS ,A ,Abfglbm ,A\ 8<$]ajl 6L 6LC 6LWZ 6Lquvzq{ 6Lp) )  *, , ,, mqy{ F/ F/I F/Y F/X] F/fi F/P fjx|  FH ./3 ./ ./9 ./I ./_b ./ru ./` 9=R )S )# ) 6:" 5s 5n 8<B 3HC 3H 3Hj 59tZ^gi 3?c 3? 3?TW 3?nrsxny 3?j 7;\`ik 7? 7?3 7?VY 7?ptuzp{ 7?r 37TX\eg :?C :?s :?RU :?x
T 
6 
EX 
$ ;= 6c 6AT 66Q
4 Q
F Q
fMt M M^*4 * *6 *X@ @v @ @D
 
4 
*> >v > >@ =? ": ":> ":H
h 
R` 
0 &eBSW P  3 PS fj r   r'   N)+ ccxt.async_support.base.exchanger   ccxt.abstract.timexr   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r    r!   r"   r#   ccxt.base.decimal_to_precisionr$   ccxt.base.preciser%   r'    r   r   <module>rl     sk    6 + R  R  R  R  R  R  * 0 - . ' . ) * ) . 1 4 %aHk ar   