
    !:h7&                    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    D/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/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                 L    | j                  |      }| j                  |      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_timee  s,     **62   *T11r   c                 F    | j                  |      }| j                  |      S )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
        )publicGetMarketsparse_marketsr  s      r   fetch_marketsztimex.fetch_marketsq  s'     ((0, !!(++r   c                 F    | j                  |      }| j                  |      S )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
        )publicGetCurrenciesparse_currenciesr  s      r   fetch_currenciesztimex.fetch_currencies  s'     ++F34 $$X..r   Ncodesincer   c                    | j                  |d      }| j                  |d      }|t        | j                  dz         d|i}| j	                  | j                  ||            }| j                  |      }| j                  ||||      S )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   . 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
 **4;;w+GH %%d+&&x5%HHr   c                    | j                  |d      }| j                  |d      }|t        | j                  dz         d|i}| j	                  | j                  ||            }| j                  |      }| j                  ||||      S )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   r  )r  r  r   r   managerGetWithdrawalsr  r  r  r  s	            r   fetch_withdrawalsztimex.fetch_withdrawals  s     ""69569-?#DGG.^$^__w
 --dkk'6.JK %%d+&&x5%HHr   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  r.  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                     | j                          | j                  | j                  d   dd      }d| j                  |   i}| j	                  | j                  ||            }| j                  ||      S )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>`
        rc   r   r   )load_marketsr  r   r   publicGetTickersr  parse_tickers)r   rE  r  r   r  r  s         r   fetch_tickersztimex.fetch_tickers,  st     	!!$,,~">$Odoof-
 ((Wf)EF$ !!(G44r   symbolc                 8   | j                          | j                  |      }| j                  | j                  d   dd      }|d   | j                  |   d}| j                  | j                  ||            }| j                  |d      }| j                  ||      S )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>`
        rc   r   r   r   marketr   r   )	rG  rN  r  r   r   rH  r  	safe_dictparse_ticker)r   rK  r  rN  r   r  r  tickers           r   fetch_tickerztimex.fetch_tickerO  s     	V$!!$,,~">$OTloof-
 ((Wf)EF$ !,  00r   c           	         | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  | j                  |d            }| j                  |||dddd      S )	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
        rN  r   r   r*  bidaskpricebaseTokenAmount)rG  rN  publicGetOrderbookV2r  r@  r  parse_order_book)r   rK  r   r  rN  r  r  r*  s           r   fetch_order_bookztimex.fetch_order_booku  s     	V$fTl
 $GG,,T[[&-IJ2 NN4#3#3Hk#JK	$$Xvy%PWYjkkr   c                    | j                          | j                  |      }| j                  | j                  di       }| j                  |dd      }| j	                  |d|      }| j                  |d      }	|d   |d}
|| j                  |      |
d<   |||
d<   | j                  | j                  |
|	            }| j                  ||||      S )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>`
        re   r   r   r   )rN  r   r3  size)
rG  rN  r$  r   r  r  iso8601publicGetTradesr  parse_trades)r   rK  r  r   r  rN  r   r   r   queryr  r  s               r   fetch_tradesztimex.fetch_trades  s     	V$//$,,rBoogvG<		&&)
 Tl 	
 "ll51GFO#GFO''GU(CD   65%@@r   rx   c           	      l   | j                          | 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                  ||            }| j                  |||||      S )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
        r   rM  untilr   r3  r   till)rG  rN  r  r   parse_timeframesafe_integerr]  summillisecondsr  publicGetCandlesr  parse_ohlcvs)r   rK  	timeframer  r   r  rN  r  durationrc  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+((Wf)EF   69eUKKr   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*  r.  r   r  totalBalancetotallockedBalanceused)r"  r#  r  rB  accountsafe_balance)r   r  resultr%  balance
currencyIdr  ru  s           r   parse_balanceztimex.parse_balance	  s    

 q#h-( 	#AqkG))':>J**:6DllnG#//HGG"..wHGFO"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://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>`
        )rG  tradingGetBalancesrz  r  s      r   fetch_balanceztimex.fetch_balance  s3     	**62 !!(++r   r7  sider8  rV  c                    | j                          | 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                  ||            }| j                  |dg       }| j                  |di       }| j                  ||      S )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>`
        postOnlyF	POST_ONLYr   )rK  quantityr~  
orderTypesLIMITrV  r   
expireTimezD createOrder() method requires a expireTime or expireIn param for a z: order, you can also set the expireIn exchange-wide optionr   r   )rG  rN  upper	safe_boolr  amount_to_precisionprice_to_precisionrf  r   r$  r   r   tradingPostOrdersr  rO  parse_order)r   rK  r7  r~  r8  rV  r  rN  uppercaseSideuppercaseTyper  r  r`  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))$++gu*EF, 8R8vq"-v..r   r   c                    | j                          | j                  |      }d|i}	|| j                  ||      |	d<   || j                  ||      |	d<   | j	                  | j                  |	|            }
d|
v r9| j                  |
dg       }| j                  |d      }| j                  ||
d      S | j                  |
dg       }| j                  |di       }| j                  |di       }| j                  ||      S )	Nr   r  rV  unchangedOrdersr   )r   r!  changedOrdersnewOrder)rG  rN  r  r  tradingPutOrdersr  r$  r  
safe_orderrO  r  )r   r   rK  r7  r~  r8  rV  r  rN  r  r  orderIdsorderIdr   
firstOrderr  s                   r   
edit_orderztimex.edit_orderw  s   V$"
 "&":":66"JGJ#66vuEGG((Wf)EF4 (x1BBGH&&x3G?? $   ?B?__VQ3
z:r:v..r   c                 n    | j                          | j                  |g||      }| j                  |d      S )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>`
        r   )rG  cancel_ordersrO  )r   r   rK  r  r   s        r   cancel_orderztimex.cancel_order  s7     	##RD&&9~~fa((r   c           	         | j                          d|i}| j                  | j                  ||            }| 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 )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>`
        r   r  r  r   r  	unchanged)r!  r   r:  )
rG  tradingDeleteOrdersr  	safe_listr"  r#  rO  appendr  r  )r   idsrK  r  r  r  r  r  r   r%  r  s              r   r  ztimex.cancel_orders  s     	#
 ++DKK,HI4 x"E..3DbIq#m,- 	6A~~mA&6
CHMM$**845	6 q#o./ 	AMM$//'*%a(%+  	 r   c                     | j                          d|i}| j                  |      }| j                  |di       }| j                  |dg       }| j	                  | j                  |d|i            S )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>`
        	orderHashr  r   )rG  historyGetOrdersDetailsr$  r  r  r  )r   r   rK  r  r  r  r  r   s           r   fetch_orderztimex.fetch_order  sv     	
 //8D '26(B7EHf3E FGGr   c                    | j                          | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }d|i}	d}
|| j                  |      }
|
d   |	d<   |||	d<   | j                  | j                  |	|            }| j                  |dg       }| j                  ||
||      S )	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>`
        rW   r   r   Nr   rK  r\  r   )
rG  r$  r   r  r  rN  tradingGetOrdersr  r  parse_ordersr   rK  r  r   r  r   r   r   r`  r  rN  r  r   s                r   fetch_open_ordersztimex.fetch_open_orders"  s     	//$,,0A2FoogvG<		&&) D

 [[(F &tGH#GFO((We)DE, (B7  >>r   c                    | j                          | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }|dd}	d}
|| j                  |      }
|
d   |	d<   || j                  |      |	d	<   |||	d
<   | j                  | j                  |	|            }| j                  |dg       }| j                  ||
||      S )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>`
        r?   r   r   BUY)r   r~  Nr   rK  r3  r\  r   )rG  r$  r   r  r  rN  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((We)DE, (B7  >>r   c                    | j                          | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }d|i}	d}
|| j                  |      }
|
d   |	d<   || j                  |      |	d<   |||	d<   | j                  | j                  |	|            }| j                  |d	g       }| j                  ||
||      S )
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>`
        rT   r   r   Nr   rK  r3  r\  r   )rG  r$  r   r  r  rN  r]  historyGetTradesr  r  r_  )r   rK  r  r   r  r   r   r   r`  r  rN  r  r   s                r   fetch_my_tradesztimex.fetch_my_trades  s     	//$,,DoogvG<		&&) D
 [[(F &tGH"ll51GFO#GFO((We)DE& (B7  >>r   r?  rN  c                 |    | j                  |d      }| j                  |d      }|| j                  ||      ||d d dS )NrN  r?  )r!  rK  makertaker
percentage	tierBased)r  rA  safe_symbol)r   r?  rN  marketIdrates        r   parse_trading_feeztimex.parse_trading_fee  sQ     ##C2U+&&x8
 	
r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )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>`
        r   r   r   )rG  rN  tradingGetFeesr  r$  r  )r   rK  r  rN  r  r  rw  s          r   fetch_trading_feeztimex.fetch_trading_fee  sr     	V$vd|
 &&t{{7F'CD 1b1%%ff55r   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lockedrK  baseCurrencyquoteCurrencyquantityIncrementbaseMinSizetickSizequoteMinSizer   /basequotesettlebaseIdquoteIdsettleIdr7  r.   Tr/   Fr0   r1   r2   activecontractr   takerFeemakerFee)r8  rV  minmax)r   r8  rV  cost)r   r  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr!  )r$  r  rB  r%   
string_maxrA  parse_number)r   rN  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 )NrK  r   depositEnabledwithdrawalEnabledr  withdrawalFeetradeDecimalsr   .r   decimalsr  )withdrawr8  )r   r  r!  r7  r   r  depositr  r?  r  r  networks)	r  rB  r$  rf  r#  r  r"  safe_currency_structureparse_precision)r   r  r   r  r   r  withdrawEnabledisActiver  	feeStringr  r?  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   rQ  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 )NrN  r  r*  lastopenrK  r!  r.  highlowrT  	bidVolumerU  	askVolumevwapclosepreviousClosechanger  volumevolumeQuote)average
baseVolumequoteVolume)r  r  r@  safe_tickerr]  )r   rQ  rN  r  rK  r*  r  r  s           r   rP  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 )NrK  r*  rV  r  r   	directionr~  makerOrTakerOrderIdr?  feeToken)r  r  )r!  r   r*  r.  rK  r  r7  r~  rV  r8  r  takerOrMakerr?  )r  r  r@  r  r%   
string_mulsafe_string_lower_2safe_string_lowerrA  rB  
safe_trader]  )r   r  rN  r  rK  r*  priceStringamountStringrV  r8  r  r   r~  r  r  r?  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  )r@  r  rA  )r   ohlcvrN  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   r7  r~  rK  	createdAtrV  r  filledQuantitycancelledQuantityclosedcanceledr  r   clientOrderIdr!  r*  r.  lastTradeTimestampr   r  r   r8  r  r  filled)	remainingr:  r?  r   )
r  r  r  r@  	omit_zeror%   string_equalsr$  r  r]  )r   r  rN  r   r7  r~  r  rK  r*  rV  r8  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                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )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>`
        rK  r  r  )rG  r  currenciesGetSSymbolr  rO  parse_deposit_address)r   r  r  r  r  r  datas          r   fetch_deposit_addressztimex.fetch_deposit_address^  ss     	==&hv&
 ,,T[[&-IJ$ ~~h
B7))$99r   c                 v    | j                  |d      }|| j                  ||      d | j                  |d      d dS )NrK  r   )r!  r  r/  r   r4  )r  rB  )r   depositAddressr  ry  s       r   r/  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;  paramsToExtractr9  authrC  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
statusTextr9  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   rH  rI  r9  r:  rJ  responseBodyr  requestHeadersrequestBodyfeedbackrM  r  rN  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   rD  r   r   rJ  strr   rR  r   rZ  r   ra  listro  r   rz  r}  r   r   floatr   r  r  r  r  r  r   r  r  r  r   r  r  r  r  rP  r  r  r  r	   r1  r/  rG  intrW  __classcell__)r   s   @r   r'   r'      s`   H# HT
 !# 
2s 
2 $& ,$v, ,B ') #/Z #/J *.Dt\^ !I3 !Ic !I !Icghsct !IF -1tRV_a !Ic !I !IC !Ifjkvfw !IF#
T #
X #
Q\ #
J 04B !5W !57 !5F 02 $13 $1f $1L :>b ,ls ,l3 ,lY ,l\ 6:UW ,A3 ,As ,A# ,A\`af\g ,A\ 26DW[df 6L# 6Lc 6LQT 6Lkoptku 6Lp) )  $& ,( ,, gksu F/3 F/i F/y F/RW F/`c F/P `drv  @B ./S ./# ./Y ./i ./Y\ ./lo ./` 37r )s )C ) 04B 5 5n 26b 3Hc 3H3 3Hj /3TXac 3? 3?3 3?c 3?hlmrhs 3?j 154VZce 7?# 7?S 7?PS 7?jnotju 7?r -1tRV_a :?c :? :?C :?x
T 
6 
EX 
$ 57 6 6;N 66Q
4 Q
F Q
fMt M M^*4 * *6 *X@ @v @ @D
 
4 
*> >v > >@ 79 ":# ":^ ":H
h 
R` 
0 &eBSW P  3 PS fj 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   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>ri     sk    ( + R  R  R  R  R  R  * 0 - . ' . ) * ) . 1 4 %aHk ar   