
    !:hbH                        d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZ 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)ImplicitAPIN)AnyBalances
CurrenciesDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTradingFeeInterfaceTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)NotSupported)DDoSProtection)	TICK_SIZE)Precisec                       e Zd Zdef fdZddi ddfdZd Zi fdee   fdZ	d	e
defd
Zi fdedefdZd7de
d	edefdZdi fdededefdZdddi fdededefdZd7d	edefdZi fdefdZddi fdedededee   fdZd7defdZi fdefdZdi fdedededede f
dZ!di fdede"de#fdZ$dddi fde"dedefd Z%dddi fde"dedefd!Z&dddi fde"dededee#   fd"Z'd7de#fd#Z(di fdede"de#fd$Z)dddi fdede"dededee   f
d%Z*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de/fd*Z0d+edefd,Z1d- Z2de"fd.Z3ded/ede
fd0Z4d&e5d1ed2ed3ed4e
d5efd6Z6 xZ7S )8ellipxreturnc                 t	   | j                  t        t        |          i ddddddgddd	d
dddddi dd ddddddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBdi dCddDddEddFddGddHddIddJddKddLddMddNddOddPddQddRddSdi dTddUddVddWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddddddedfdgdhdidjdkdldmdndodpdqdrdrdsdtdudvdwdxdydzd{d{d{d|idzd{d{d{d{d{d{d}id{d{d{d{d{d{d{d{d~d{d{d{ddd{idddddzd| j	                  d      | j	                  d      | j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      gg	| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      g| j	                  d      | j	                  d      gg	dddd| j	                  d      | j	                  d      dddddddddddddddd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 ddid	d d dd d dddi dt
        t        t        t
        t        t        t        t        di ddt              S )Nidr    nameEllipx	countriesPL	rateLimit   versionv1	certifiedFprohasCORSspotTmarginswapfutureoption	addMargincancelAllOrderscancelAllOrdersAftercancelOrdercancelOrderscancelWithdrawclosePositioncreateConvertTradecreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrdercreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrder$createOrderWithTakeProfitAndStopLosscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingAmountOrdercreateTrailingPercentOrdercreateTriggerOrderfetchAccountsfetchBalancefetchCanceledAndClosedOrdersfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransfersfetchWithdrawalsreduceMarginsandboxsetLeverage)	setMarginsetPositionModetransferwithdraw
timeframes1m5m10m1h6h12h1d)r   r   r   r   r   r   r   urlszOhttps://github.com/user-attachments/assets/e07c3f40-281c-4cdf-bacf-fa1c58218a2czhttps://data.ellipx.comzhttps://app.ellipx.com/_rest)publicprivate_restzhttps://www.ellipx.comzOhttps://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syMz$https://www.ellipx.com/pages/pricing )logoapiwwwdocfeesreferralr   get   )r
   zMarket/{currencyPair}zCrypto/Token/Info)zMarket/{currencyPair}:getDepthzMarket/{currencyPair}:tickerzMarket/{currencyPair}:getTradeszMarket/{currencyPair}:getGraphzCMC:summaryzCMC/{currencyPair}:ticker)zUser/WalletMarket/{currencyPair}/OrderMarket/Order/{orderUuid}zMarket/{currencyPair}/TradezMarket/TradeFee:queryzUnit/{currency}zCrypto/Token/{currency}zCrypto/Token/{currency}:chains)r   zCrypto/Address:fetchzCrypto/Disbursement:withdrawr   )r   postdelete)r   r   r   r   z0.0025z0.0030010000z0.002050000z0.0015100000z0.00101000000z0.00085000000z0.000315000000z0.000075000000	100000000z0.0012z0.0005)makertaker)	tierBasedfeeSide
percentager   r   tiersz0.000015)r   r   r   r   )trading
stablecoinoptionsi  CCXTBitcoinERC20)r   EthereumdefaultNetworkr   )BTCETH)defaultType
recvWindowbrokernetworksr   defaultNetworkCodeReplacementsfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceiceberg)r   triggerr   symbolRequired)r   limitr   r   r   )r   r   daysBack	untilDaysr   r   r   r   d   )	r   rB   createOrdersrg   rl   rk   rn   rR   rh   )linearinverse)r0   r2   r3   commonCurrencies
exceptions)400401403404429418500504)exactbroadprecisionMode)deep_extendsuperr    describeparse_numberr   r   r   r   r   r   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/ellipx.pyr   zellipx.describe   sI
   fd < > dA
(dA
HdA
 $dA
 	dA

 tdA
 dA
 5dA
  ZZZ %Z 	Z
 %Z %Z UZ "5Z 'Z tZ Z !%Z  Z %eZ 'Z  /!Z" $U#Z$ ,U%Z& 0'Z( t)Z* 7+Z, (-Z. '/Z0 &u1Z2 (3Z4 "55Z6 (7Z8 ,U9Z: -e;Z< %e=Z>  ?Z@ AZB /CZD &uEZF #EGZH $UIZJ )%KZL $UMZN $UOZP +EQZR "4SZT &tUZV  WZX +EYZZ &u[Z\ #E]Z^ *5_Z` $UaZb "5cZd ueZf  gZh %eiZj /kZl "5mZn oZp !%qZr  sZt duZv +EwZx !%yZz "4{Z| d}Z~ !$Z@ tAZB #DCZD  EZF 'GZH $UIZJ !%KZL *5MZN (OZP )%QZR uSZT tUZV WZX UYZZ t[Z\ "4]Z^ #E_Z` $UaZb !%cZd #EeZf gZh 5iZj ukZl ##(! sZdA
F GdA
X i7=;
 0h>YdA
p "#12-. :;89;<:;'(56	 ()78457812+,34:;	 890189 3A!%&qdA
~ !%$"&!..x8!..x8 "..s3T5F5Fx5PQ!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..{;T=N=Nx=XY
" "..s3T5F5Fx5PQ!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..{;T=N=Nx=XY
"B "'"&!..x8!..z:	C'dA
N %& ( ' #3$%3OdA
j $&+(-,0,1).+06:#(#("'#(	( #(/4$)$)+/27#()$, %)%)&+#($)*/	# ',!%#($)*.( ',!%$(%)#($)*.$ *.#c4l ##
 ##u>kdA
h idA
j  &.+%)+((
 kdA
F	 YG	dA
 d d	    r   GETNc                 Z   | j                  ||      }| j                  d   |   dz   |z   }|dk(  r| j                          | j                         }t	        | j                               }	|dk(  rd}n| j                  |      }| j                  | j                  |	|d|      }| j                  |      }
| j                  | j                  |      d      }| j                  |      }| j                  dd	      }| j                  |      || j                  |      || j                  |
      ||g}| j                  |      }| j                  }| j!                  t#        |      d
      }|rd
|z
  nd}| j                  j%                  dd      }|j%                  dd      }|j'                  t#        | j                        |z   d      }| j)                  |      }| j+                  |dd      }| j-                  ||d      }||d<   |r|d| j                  |      z   z  }|dk(  rd }nddi}||||dS )Nr   /r   r   r   )_key_time_noncesha256r   r      -+_=    ed25519_sign?zContent-Typezapplication/json)urlmethodbodyheaders)implode_paramsr   check_required_credentialsuuidstrsecondsjsonextendapiKey	urlencodehashencodebase16_to_binarynumber_to_bebinary_concat_arraysecretcalculate_modlenreplaceljustbase64_to_binaryarray_sliceeddsa)r   pathr   r  paramsr  r  r  nonce	timestampquerybodyHashbodyHashBytesnulByte
components
signStringsec	remainderpaddingLengthsecretWithPaddingsecretBytesseed	signatures                          r   signzellipx.sign?  s2   ""40iis#c)D0)++-IIKEDLLN+Iyy([["" 	F
 NN6*EyyT!2H=H 11(;M''1-GF#D!E"J 11*=J++C**3s8Q7I-6A	MAM $ 3 3C = 1 9 9#s C 1 7 7DKK8H=8XZ] ^//0ABK##KB7D

:tY?I'F7O3///CU?D  2G fdwOOr   c                     ||z  S N )r   abs      r   r  zellipx.calculate_mods  s    1ur   c                 l    | j                  |      }| j                  |dg       }| j                  |      S )a  
        Fetches market information from the exchange.

        https://docs.ccxt.com/en/latest/manual.html#markets
        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.1a1t05wpgfof

        :param dict [params]: - Extra parameters specific to the exchange API endpoint
        :returns Promise<Market[]>: An array of market structures.
        data)_restGetMarket
safe_valueparse_markets)r   r  responsemarketss       r   fetch_marketszellipx.fetch_marketsw  s:     &&v.P //(FB7!!'**r   marketc                    | j                  |d      }| j                  |d   d      }| j                  |d   d      }| j                  |d   d      }| j                  |d   d      }| j                  |d      dk(  }| j                  |d   d      }| j                  | j                  | j                  |d   d	                  }	| j                  | j                  | j                  |d   d	                  }
| j                  }| j                  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#      S )$NKeyPrimary	SecondaryCrypto_Token__StatusactiveCreatedunixDecimalsr#   symbolr   basequotesettlebaseIdquoteIdsettleIdtyper0   Tr1   Fr2   r3   r4   contractr   r   r   r   )amountpriceminmax)rN  rO  cost)r   r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitsinfocreated)safe_stringsafe_timestampr   parse_precisionr   safe_market_structure)r   r:  r#   rF  rG  rI  rJ  statusr\  amountPrecisionpricePrecisionr   s               r   parse_marketzellipx.parse_market  sc   fe,y 159  !4e<!!&"35EF""6+#68HI!!&(3x?%%fY&7@++D,@,@AQAQRXYbRceoAp,qr**4+?+?@P@PQWXcQdfp@q+rsyy)) .+
".+
dSj5(.+
 D.+
 U	.+

 d.+
 f.+
 w.+
 .+
 F.+
 D.+
 e.+
 E.+
 e.+
 e.+
 f.+
  !.+
" d#.+
$ )_W-)_W- ")'  
  
   [.+
 . .	r   rE  c                     | j                          | j                  |      }|d   }d|i}| j                  | j                  ||            }| j	                  |d   di       }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.d2jylz4u6pmu

        :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#   currencyPairr3  ticker)load_marketsr:  !publicGetMarketCurrencyPairTickerr  r5  parse_ticker)r   rE  r  r:  marketIdrequestr7  rg  s           r   fetch_tickerzellipx.fetch_ticker  s}     	V$$<H
 99$++gv:VWn &!18R@  00r   rg  c                    | j                  |dd      }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j                  |d            }| j                  | j                  |d            }	| j                  | j                  |d	            }
| j                  | j                  |d
            }| j                  i d| j	                  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||
||d|      S )Ntime  openhighlowcloseavgvwapvolsecvolrE  r  datetimebid	bidVolumeask	askVolumelastpreviousClosechanger   average)
baseVolumequoteVolumer[  )safe_integer_productparse_amountr5  safe_tickersafe_symboliso8601)r   rg  r:  r  rq  rr  rs  rt  ru  rv  r  r  s               r   rj  zellipx.parse_tickerQ  s   --ffdC	  !@A  !@A >?!!$//&'"BC >?  !@A&&tvu'EF
''(IJ !
d&&tV4!
!
 Y/!
 D	!

 3!
 4!
 !
 4!
 !
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" s#!
$ %&)!
* + 	r   r   c           	         | j                          | j                  |      }|d   }d|i}| j                  | j                  ||            }| j	                  |di       }| j                         }	t        |d         }
t        |d         }t        d|
      D ]H  }| j                  |d   |   d         |d   |   d<   | j                  |d   |   d         |d   |   d<   J t        d|      D ]H  }| j                  |d   |   d         |d   |   d<   | j                  |d   |   d         |d   |   d<   J | j                  |||	dddd      S )	a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.bqmucewhkpdz

        :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 the exchange not supported yet.
        :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#   rf  r3  bidsasksr   rO  rN  )
rh  r:  #publicGetMarketCurrencyPairGetDepthr  r5  millisecondsr  ranger  parse_order_book)r   rE  r   r  r:  rk  rl  r7  r3  r  dataBidsLengthdataAsksLengthis                r   fetch_order_bookzellipx.fetch_order_books  s    	V$$<H
 ;;DKKQW<XYz x4%%'	T&\*T&\*q.) 	UA'+'8'8fa9Q'RDLOG$(,(9(9$v,q/(:S(TDLOH%	U q.) 	UA'+'8'8fa9Q'RDLOG$(,(9(9$v,q/(:S(TDLOH%	U $$T69ffgW_``r   r   sincec           	      :   | j                          d}d}| j                  ||d      \  }}|r| j                  d|||||d      S | j                  |      }|d   }	| j	                  | j
                  |d      }
|	|
d}|$t        t        j                  |dz              |d<   d}| j                  ||d	      \  }}|||d
<   | j                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  |||||      S )aC  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market, default will return the last 24h period.

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.w65baeuhxwt8

        :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 API endpoint
        :param int [params.until]: timestamp in ms of the earliest candle to fetch
        :returns OHLCV[]: A list of candles ordered, open, high, low, close, volume
        rh   Fpaginaterp  r#   N)rf  intervalstartuntilendr3  stats)rh  handle_option_and_params"fetch_paginated_call_deterministicr:  r]  r   intmathfloor#publicGetMarketCurrencyPairGetGraphr  	safe_dict	safe_listparse_ohlcvs)r   rE  	timeframer  r   r  
methodNamer  r:  rk  
time_framerl  r  r7  r3  ohlcvs                   r   fetch_ohlcvzellipx.fetch_ohlcv  s?    	!
88ZX&::<QVX]_hjprvwwV$$<%%dooy$G
$"
 "4::edl#;<GG55fj'Rv"GEN* ;;DKKQW<XY~~h3tWb1  	5%HHr   c                    | j                  |d      dz  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  gS )Nro  rp  rq  rr  rs  rt  rw  )safe_integerr   r  r  )r   r  r:  s      r   parse_ohlcvzellipx.parse_ohlcv  s    eV,t3d//uf0MNOd//uf0MNOd//ue0LMNd//ug0NOPd//ue0LMN
 	
r   c                    | j                  | j                  dddd|            }i }| j                  |dg       }t        dt	        |            D ]  }||   }| j                  |d      }| j                  |di       }| j                  | j                  |d	            }	|	|vr/||	g d
| j                  |d      d
d
d
d
d
d
d
dd
d
dd
d
ddi d||	<   | j                  |d      }
| j                  |d      }| j                  |dd      }| j                  |      }|
|| j                  |d      dk(  | j                  |d      dk(  d
| j                  | j                  |d               | j                  | j                  | j                  |d                  d
d
d| j                  |d         d
d| j                  |d         d
ddd||	   d   |<   | j                  ||	   dg       }|j                  |       |||	   d<    t        |j                               }t        dt	        |            D ]  }||   }	| j                  ||	         ||	<     |S )a  
        fetches information on all currencies from the exchange, including deposit/withdrawal details and available chains

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.x65f9s9j74jf

        :param dict [params]: extra parameters specific to the ellipx API endpoint
        :param str [params.Can_Deposit]: filter currencies by deposit availability, Y for available
        :param number [params.results_per_page]: number of results per page, default 100
        :param str [params._expand]: additional fields to expand in response, default '/Crypto_Token,/Crypto_Chain'
        :returns Promise<Currencies>: An object of currency structures indexed by currency codes
        Yr   z/Crypto_Token,/Crypto_Chain)Can_Depositresults_per_page_expandr3  r   r?  Crypto_TokenSymbolNNamerP  )rN  r   deposit)r#   coder[  rL  r$   rA  r  r   feerY  rZ  r   Crypto_Chain__Crypto_ChainTypedefaultr@  validr  Withdraw_FeerD  Minimum_WithdrawMinimum_Deposit)r#   networkrA  r  r   r  rY  rZ  r   r[  )_restGetCryptoTokenInfor  r  r  r  r]  r  safe_currency_codenetwork_id_to_coder   r  r_  appendlistkeyssafe_currency_structure)r   r  r7  resultr3  r  networkEntryr#   tokenr  	networkIdcryptoChainDictnetworkNamenetworkCodeinfosallKeyss                   r   fetch_currencieszellipx.fetch_currencies  s    // #4=
 	1 
 ~~h3q#d)$ d	)A7LN !!,0@ABNN<DE**4+;+;E8+LMDFN   ,,UF;"# $!% $(#'#
 $(#'%
 $(#'$ !#3 t6 ((7GHI"..|^LO**?FINK11+>K&**<BgM++L-HCO (():):<;W)XY!..t/C/CDDTDTUZ\fDg/hi  $#
  $00>P1QR#!
  $00>O1PQ# 5F4L$[1. NN6$<<ELL&#(F4L Id	)L v{{}%q#g,' 	FA1:D77tEF4L	F r   c                    | j                          | j                  |      }|d   }d|i}| j                  | j                  ||            }| j	                  |di       }	| j                  |	dg       }
| j                  |
|||      S )a  
        fetches all completed trades for a particular market/symbol
        :param str symbol: unified market symbol(e.g. 'BTC/USDT')
        :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 EllipX API endpoint
        :param str [params.before]: get trades before the given trade ID
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r#   rf  r3  trades)rh  r:  $publicGetMarketCurrencyPairGetTradesr  r  r  parse_trades)r   rE  r  r   r  r:  rk  rl  r7  r3  r  s              r   fetch_tradeszellipx.fetch_trades  s     	V$$<H
D <<T[[RX=YZ~~h3h3  >>r   c                 P   | j                  |d      }| j                  |d      }d }|"| j                  | j                  |d            }n| j                  |d      }| j                  |d      }|dk(  rdnd}| j                  |d      }| j                  |d	      }	| j	                  |      }
| j	                  |	      }| j                  |d
      }d }|/| j                  |d
      }|j                  d      \  }}|dz   |z   }n(| j                  |d      dz   | j                  |d      z   }| j                  |d      }| j                  |d      }|dk(  }|r| j                  |d      n| j                  |d      }| j                  |||| j                  |      |d ||d ||
d d d      S )Nr#   dateunixmsrL  rz  buysellrN  rO  pairr   r   r   r   r|  )r#   r[  r  ry  rE  rL  sideordertakerOrMakerrO  rN  rS  r  )	r]  r  	parse8601r  r  r  split
safe_trader  )r   trader:  r#   r  r  rL  r  rN  rO  amountFloat
priceFloatr  marketSymbolrE  rF  rG  bidOrderaskOrderisBuyorderIds                        r   parse_tradezellipx.parse_trade  s   eT*~~eV,	<t'7'7v'FGI))$9Iv.uVx0ug.''/&&u-
~~eV,<%%eV4F ,,s+KD%#:-L++D!4s:T=M=MdTU=VVL>>%/>>%/6;$""8T2AQAQRZ\`Aa"Y/" ! 
  	r   c                 \   | j                          | j                  |      }|ddd}| j                  |dg       }t        |      }|dkD  rD|d   }| j	                  |di       }| j                  |d      |d<   | j                  |d         |d<   t        dt        |            D ]v  }||   }	| j	                  |	d	i       }
| j                  |
d
      }|0| j                  |	d   d         | j                  |	d   d         | j                  |
d         d}|||<   x | j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.ihrjov144txg

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)r[  r  ry  r3  r   Balance_Dater  r  ry  BalancecurrencyUnencumbered_Balance
value_xintLiabilities)freeusedtotal)rh  privateGetUserWalletr  r  r  r  r  r  r]  r  safe_balance)r   r  r7  r  	dataArraydataArrayLength	firstItembalanceDater  entrybalancer  accounts                r   fetch_balancezellipx.fetch_balance1  sX    	,,V4F 

 NN8VR8	i.Q!!I..NBGK"&"3"3K"JF;!%f[.A!BF:q#i.) 
	'AaLEnnUIr:G##GZ8D --e4J.KL.YZ --eM.B<.PQ!..w|/DE
  't
	'   ((r   rL  r  rN  rO  c                    | j                          | j                  |      }|d   }d}	|dk(  rd}	nd}	||	d}
|| j                  ||      |
d<   || j                  ||      |
d<   | j	                  |d      }|'| j                  |d      }| j                  ||      |
d	<   | j                  | j                  |
|            }| j                  |d
i       }| j                  ||      S )ai  
        create a new order in a market

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.yzfak2n2bwpo

        :param str symbol: unified market symbol(e.g. 'BTC/USDT')
        :param str type: order type - the exchange automatically sets type to 'limit' if price defined, 'market' if None
        :param str side: 'buy' or 'sell'
        :param float [amount]: amount of base currency to trade(can be None if using Spend_Limit)
        :param float [price]: price per unit of base currency for limit orders
        :param dict [params]: extra parameters specific to the EllipX API endpoint
        :param float [params.cost]: maximum amount to spend in quote currency(required for market orders if amount None)
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r#   rz  r  r|  )rf  r  AmountPricerS  Spend_Limitr3  )
rh  r:  amount_to_precisionprice_to_precisionr]  omit"privatePostMarketCurrencyPairOrderr  r  parse_order)r   rE  rL  r  rN  rO  r  r:  rk  	orderTyperl  rS  r7  r  s                 r   create_orderzellipx.create_order  s	    	V$$<	5=II$
  $ 8 8 HGH#66vuEGG/YYvv.F%)%<%<VT%JGM"::4;;wPV;WXf x4v..r   r#   c                     | j                          d|i}| j                  | j                  ||            }| j                  |di       }| j	                  |d      S )ao  
        fetches information on an order made by the user
        :param str id: the order ID by createOrder or fetchOrders
        :param str|None symbol: not used by ellipx.fetchOrder
        :param dict [params]: extra parameters specific to the EllipX API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        	orderUuidr3  N)rh  privateGetMarketOrderOrderUuidr  r  r  )r   r#   rE  r  rl  r7  r3  s          r   fetch_orderzellipx.fetch_order  s^     	
 66t{{7F7ST~~h3d++r   c                    | j                          d}i }|| j                  |      }|d   }||d<   |||d<   | j                  | j                  ||            }	| j	                  |	dg       }
| j                  |
|||      S )ap  
        fetches a list of orders placed on the exchange

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.5z2nh2b5s81n

        :param str status: 'open' or 'closed', omit for all orders
        :param str symbol: unified market symbol
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum amount of orders to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr#   rf  r@  r3  )rh  r:  !privateGetMarketCurrencyPairOrderr  r5  parse_orders)r   ra  rE  r  r   r  r:  rl  rk  r7  r3  s              r   fetch_orders_by_statuszellipx.fetch_orders_by_status  s     	[[(Fd|H&.GN# &GH99$++gv:VWn x4  vue<<r   c                 `    |t        | j                  dz         | j                  d||||      S )a\  
        fetches information on multiple orders made by the user

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.5z2nh2b5s81n

        :param str symbol: unified market symbol of the market orders were made in
        :param int|None since: timestamp in ms of the earliest order
        :param int|None limit: the maximum amount of orders to fetch
        :param dict params: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrders requires a symbol parameterr   r#   r  r   rE  r  r   r  s        r   fetch_orderszellipx.fetch_ordersR  s7     >#DGG.X$XYY**4vNNr   c                 `    |t        | j                  dz         | j                  d||||      S )aX  
        fetches information on open orders made by the user

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.5z2nh2b5s81n

        :param str symbol: unified market symbol of the market orders were made in
        :param int|None since: timestamp in ms of the earliest order
        :param int|None limit: the maximum amount of orders to fetch
        :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>`
        z, fetchOpenOrders requires a symbol parameterrq  r  r  s        r   fetch_open_orderszellipx.fetch_open_ordersb  s7     >#DGG.\$\]]**665%PPr   c                    | j                  |d      }| j                  | j                  |d      d      }| j                  |d      }d}|dk(  rd}| j                  | j                  |d            }| j	                  | j                  | j                  |d	                  }| j	                  | j                  | j                  |d
                  }	|	dnd}
| j	                  | j                  | j                  |d                  }|}| j	                  | j                  | j                  |d                  }| j	                  | j                  | j                  |d                  }|r|d   nd }d }d}d}| j                  |di       }| j                  |dd       }| j                  i d|d|d|d|d| j                  |      d|d| j                  |      d|d|
d|d|d|d|	d d d!d d"|d#|||d d d$|      S )%NMarket_Order__rB  r  r  r  rz  r  r@  r  r  r:  r   ExecutedSecuredTotal_SpentrE  GTCFUpdatedr#   clientOrderIdr[  r  ry  lastTradeTimestampra  rL  r   postOnlyr  rO  r   r  rS  rN  filled	remainingr  r  )r]  r  r  parse_order_statusr   r  
safe_orderr  )r   r  r:  r#   r  r	  r  ra  rN  rO  rL  executedr$  r%  rS  rE  r   r   r"  updatedr!  s                        r   r  zellipx.parse_orderr  s   e%56%%dnnUI&FQ	$$UF3	D(()9)9%)JK""4#4#4T^^E85T#UV!!$"3"3DNN5'4R"ST!Mx$$T%6%6t~~eZ7X%YZ%%d&7&7ui8X&YZ	  !2!24>>%3W!XY%+!..	26!..w$G  
" 
] 
 E 
 	 

 Y/ 
 !"4 
 d--f5 
 f 
 D 
 ; 
  
 D 
 U 
 D 
 t 
  D! 
" f# 
$ "+ 
, - 	r   c                    | j                          d|i}| j                  | j                  ||            }| j                  |dd      }| j	                  |d      }d}|dus|d}| j                  i 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dddddddddddd      S )a  
        Cancels an open order on the exchange

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.f1qu1pb1rebn

        :param str id: - The order ID to cancel(format: mktor-xxxxx-xxxx-xxxx-xxxx-xxxxxxxx)
        :param str [symbol]: - ellipx.cancelOrder does not use the symbol parameter
        :param dict [params]: - Extra parameters specific to the exchange API
        :returns Promise<dict>: A Promise that resolves to the canceled order info
        r  warningNr3  canceledTclosedr#   r   r[  r  ry  r!  ra  rE  rL  r   r"  r  rO  r   r  rS  rN  r#  )rh  !privateDeleteMarketOrderOrderUuidr  r5  	safe_boolr'  r
  )	r   r#   rE  r  rl  r7  warningResponsestatusResponsera  s	            r   cancel_orderzellipx.cancel_order  ss    	
 99$++gv:VW //(ItD&9%)DF  
" 
T 
 DIIh' 
 	 

  
 !$ 
 f 
 d 
 D 
 4 
  
 D 
 T 
 D 
 t 
  D! 
" d# 
$ + 
, - 	r   c                     |t        d      | j                          | j                  |      }|d   }||d}| j                  | j	                  ||            }	| j                  |	d      }
| j                  |
|||      S )a  
        fetch all the trades made from a single order
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        z)fetchMyTrades requires a symbol parameterr#   )r  rf  r3  )r   rh  r:  !privateGetMarketCurrencyPairTrader  r  r  )r   r#   rE  r  r   r  r:  rf  rl  r7  r3  s              r   fetch_order_tradeszellipx.fetch_order_trades  s     >#$OPPV$d| (
 99$++gv:VWR ~~h/  vue<<r   r  c                    | j                          | j                  |      }| j                  |d   dd      }| j                  |d      | j                  |d      d}| j	                  | j                  ||            }| j                  |di       }| j                  |d      }| j                  |d	      }	| j                  |       |||	||d
S )a  
        fetches a crypto deposit address for a specific currency

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.k7qe5aricayh

        :param str code: unified currency code(e.g. "BTC", "ETH", "USDT")
        :param dict [params]: extra parameters specific to the EllipX API endpoint
        :returns dict: an address structure {
     'currency': string,  # unified currency code
     'address': string,  # the address for deposits
     'tag': string|None,  # tag/memo for deposits if needed
     'network': object,  # network object from currency info
     'info': object  # raw response from exchange
}
        :throws ExchangeError if: currency does not support deposits
        r[  r  Nr?  r  )r?  r  r3  Addressmemo)r  addresstagr  r[  )rh  r  r5  r]  privatePostCryptoAddressFetchr  check_address)
r   r  r  r  r  rl  r7  r3  r9  r:  s
             r   fetch_deposit_addresszellipx.fetch_deposit_address  s    " 	==&//(6"2NDI"..w8HI"..w8HI
 55dkk'66RSx4""43tV,7#
 	
r   c                     | j                          | j                  |      }| j                  |di       }| j                  |d      }| j                  |d      }||dz  nd}||dz  nd}|d||dddS )aT  
        Fetches the current trading fees(maker and taker) applicable to the user.

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.kki5jay2c8it

        :param str [symbol]: Not used by EllipX are not symbol-specific.
        :param dict [params]: Extra parameters specific to the EllipX API endpoint.
        :returns Promise<dict>: A promise resolving to a unified trading fee structure:
 {
     'info': object,        # the raw response from the exchange
     'symbol': None,   # symbol is not used for self exchange
     'maker': number,       # maker fee rate in decimal form
     'taker': number,       # taker fee rate in decimal form
     'percentage': True,    # indicates fees are in percentage
     'tierBased': False,    # indicates fees do not vary by volume tiers
}
        r3  r   r   Ni'  T)r[  rE  r   r   r   r   )rh  privateGetMarketTradeFeeQueryr5  safe_number)	r   rE  r  r7  r3  r   r   makerFeetakerFees	            r   fetch_trading_feezellipx.fetch_trading_fee  s    $ 	55f= x4  w/  w/%*%655=T%*%655=T
 	
r   r9  c                 T   | j                  |       | j                          | j                  |      }| j                  |d      }|t	        | j
                  dz   |z   dz         | j                  d|d   i      }| j                  |dg       }	| j                  |	d      }
| j                  |d       | j                  |d	       t        |      }|
|||d
   d}|||d<   | j                  | j                  ||            }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }i d|d
|ddd|d| j                  |      d| j                  |d	      d| j                  |d      d| j                  |d      ddd|d|ddddd | j                  |d!      d|d"| j!                  | j                  |d#            d$| j#                  |d%      d&d|ddd'd(S ))a[  
        Make a withdrawal request

        https://docs.google.com/document/d/1ZXzTQYffKE_EglTaKptxGQERRnunuLHEMmar7VC9syM/edit?tab=t.0#heading=h.zegupoa8g4t9

        :param str code: unified currency code
        :param number amount: Amount to withdraw
        :param str address: Destination wallet address
        :param str [tag]: Additional tag/memo for currencies that require it
        :param dict params: Extra parameters specific to the EllipX API endpoint(Crypto_Chain__, Unit__)
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   Nz withdraw() for z is not supportedr  r  r3  Unit__r  r#   )rE  rN  r9  r  r8  r  	Requested	ProcessedCrypto_Disbursement__r  r[  txidr  ry  r  r9  r7  	addressToaddressFromr:  tagTotagFromrL  
withdrawalrN  valuera  r@  r)  rC  F)r  rS  rate)internalcommentr  )r<  rh  r  r5  r   r#   privateGetUnitCurrencyr]  r  r  %privatePostCryptoDisbursementWithdrawr  r  r  r  r@  parse_transaction_statusr^  )r   r  rN  r9  r:  r  r  r   chainsResponse
chainsDataunitamountStringrl  r7  r3  amountResponse	requested	processed
withdrawIdr  s                       r   r   zellipx.withdraw  s    	7#==&??8Z8tww);;dBEXXYY44j(6BR5ST__^VR@

H5		&(#		&*+6{"&tn	
 ?!GFO==dkk'SY>Z[v ~~h/h7NN45	NN45	%%d,CD
%%i:	
H
*
 D
 	

 Y/
 t''.>?
 t''i8
 ))$	:
 4
 3
 S
 t
 L
 d&&~w?
 
  d33D4D4DT84TU!
" t**9f=#
$  )
 	
r   ra  c                 6    ddddd}| j                  |||      S )Npendingokfailedr,  )r_  	completedra  	cancelledr]  r   ra  statusess      r   rU  zellipx.parse_transaction_status  s,     #	
 &&99r   c           
      @    dddddddddd	}| j                  |||      S )Nrq  rejectedr-  r,  )	r_  runningzpost-pendingrq  stopinvaliddonecancelr,  rd  re  s      r   r&  zellipx.parse_order_status  s;    "! "

 &&99r   c                     | j                  |dd       }| j                  |dd       }||y t        |      }||_        |j	                          t        |      }|S )Nve)r]  r  r   decimalsreducer  )r   rN  ro  rp  preciserY  s         r   r  zellipx.parse_amount  s`    VS$/fc409	!*7|r   rY  c                 &    t        |      }|}||dS )N)ro  rp  )r  )r   rN  rY  ro  rp  s        r   	to_amountzellipx.to_amount  s     K
 	
r   reasonr  r  r  r  c
                     | j                  |d      }
| j                  |d      }|
;| j                  | j                  d   |
|       t        | j                  dz   |z         y )Nr  messager    )r]  throw_exactly_matched_exceptionr   r   r#   )r   r  rv  r  r  r  r  r7  requestHeadersrequestBody	errorCoderx  s               r   handle_errorszellipx.handle_errors  se     $$Xv6	""8Y7 001I9V]^# 788r   r.  )8__name__
__module____qualname__r   r   r,  r  r   r
   r9  dictrd  r  r   rm  rj  r	   r   r  r  r  r  r   r  r   r  r  r   r  r   r   floatr   r
  r   r   r  r  r  r  r  r2  r5  r   r=  r   rC  r   r   rU  r&  r  ru  r  r~  __classcell__)r   s   @r   r    r       s   e# eN	 &eBSW 2Ph $& S+$v, S+j94 9F 9v 02 H13 H1f H1T 4    6  D :>b Xas Xa3 XaY Xat 26DW[df 8I# 8Ic 8IQT 8It
 
4 
 ') }Z }~ 6:UW 2?3 2?s 2?# 2?\`af\g 2?h+ +Z $& e)( e)N gksu X/3 X/i X/y X/RW X/`c X/t 26b ,c ,3 ,U ,  <@daenp N=S N= N=[^ N=` *.Dt\^ O3 Oc O O  /3TXac Q Q3 Qc Qhlmrhs Q + +Z 37r 8s 8C 8e 8t 9=4^bkm }=S }=# }=S }=X[ }=rvw|r} }=~ 79 #
# #
^ #
J 57 .
 .
;N .
` DHPR \
S \
% \
# \
Wb \
|:s :s ::	c 	
 
% 
D 
# s  c TX `c r   r    )%ccxt.base.exchanger   ccxt.abstract.ellipxr   r  ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r/  r   r   <module>r     s\    ( ,  v  v  v  v  v  * 0 - . ' ) + 4 %oX{ or   