
    !:hk                    `   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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(m0Z0 d dl(m1Z1 d dl(m2Z2 d dl3m4Z4 d dl5m6Z6  G d dee      Z7y)    )Exchange)ImplicitAPIN) AccountAnyBalances
CurrenciesCurrencyDepositAddressIntLeverage	LeveragesLeverageTierLeverageTiers
MarginModeMarginModesMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)NotSupported)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdZi fdefdZi fdee	   fdZ
i fdee	   fdZi fdee	   fdZi fdefdZi fdee   fd	Zdefd
Zd Zd Zi fdefdZdi fdededefdZdedede	defdZi fdedefdZdi fdedefdZdede	de fdZ!dddi fdedededee    fdZ"ded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e&fd Z'ded!ede	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(Z0di fded$e,d%e-d&e.d'e/f
d)Z1i fd*ee2   fd+Z3di fd,ede&fd-Z4dddi fde&dededee(   fd.Z5dddi fde&dededee(   fd/Z6di fd,ede&fd0Z7di fde&fd1Z8ded2e9de:fd3Z;i fd4ede:fd5Z<dddi fd4e&dededee=   fd6Z>dddi fd4e&dededee=   fd7Z?dddi fd4e&dededee=   fd8Z@de&fd9ZAded:ed2e9de=fd;ZBdi fdedeeC   fd<ZDded=ede	fd>ZEdede	deFfd?ZGdi fdedeHfd@ZIi fdedeJfdAZKdedBede	deJfdCZLi fded&e.deJfdDZMi fded&e.deJfdEZNdi fdFede&fdGZOdi fdHede&fdIZPdi fdedeQfdJZRdede	deeS   fdKZTded2e9fdLZUdi fdMefdNZVi fd4ed&e.dOedPedeWf
dQZXdedRed2e9deWfdSZYde&de&fdTZZdddi fde&dedefdUZ[dede	fdVZ\di fdede]fdWZ^dedHede_fdXZ`di fdedeafdYZbdedFede	decfdZZdd[d\i ddfd]Zed^efd_ed`edaedbedcefddZg xZhS )fascendexreturnc                    | j                  t        t        |          i ddddddg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
d/d
d0d(i d1dd2dd3d(d4dd5d(d6dd7d
d8d
d9dd:d
d;d
d<dd=d
d>d
d?dd@ddAd
i dBd
dCd
dDddEd
dFd
dGd
dHddIddJddKddLd
dMddNd
dOd
dPd(dQd
dRd
d
d
dddddd
ddS	dTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgidfdhidgdigdjdkdldmdndodpi dqdrdsdrdtdrdudrdvdrdwdrdxdrdydrdzdrd{drd|drd}drd~drddrddrddrddrddriidrdrdrdrdrddrdrdrdrdrddrdrddrdrdrdddrdrdrdrdrdrdrdrdrd	drdrdrdddddpdrdrdrdrdrdrdidpddriiddridrdrdrdrdrdrdrddrdrdrdrdrdrdrdrdrdrd
drdrdrddddddddpdd| j	                  d      | j	                  d      didt
        ddd ddidddddddidddddddddddddddddd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
d d
d
dd
dd d ddid	dd
dddrdd
d
d
dddddd
d
dd
dÜid
dd d d d
d
d
ddĜddid dǜd d dǜdȜdi dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        t        t        t        t        t        t        t        t        t        d	i ddd dddddd      S (  Nidr3   nameAscendEX	countriesSG	rateLimiti  	certifiedFproThasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAccountsfetchBalancefetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistory
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfers)	fetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsreduceMarginsandboxsetLeveragesetMarginModesetPositionModetransfer
timeframes151530601202403607201d1w1m)r   5m15m30m1h2h4h6h12hr   r   1Mversionv2urlszOhttps://github.com/user-attachments/assets/55bab6b9-d4ca-42a8-a0e6-fac81ae557f1restzhttps://ascendex.comz%https://api-test.ascendex-sandbox.comzKhttps://ascendex.github.io/ascendex-pro-api/#ascendex-pro-api-documentationz8https://ascendex.com/en/feerate/transactionfee-traderatez7https://ascendex.com/en-us/register?inviteCode=EL6BXBQMg      ?)urldiscount)logoapitestwwwdocfeesreferralr   getassets   productstickerzbarhist/infobarhistdepthtradeszcash/assetszcash/productszmargin/assetszmargin/productsfutures/collateralzfutures/contractszfutures/ref-pxzfutures/market-datazfutures/funding-ratesrisk-limit-infozexchange-info)infozwallet/transactionszwallet/deposit/addresszdata/balance/snapshotzdata/balance/history)balancez
order/openzorder/statuszorder/hist/currentrisk)orderorder/batch)r   z	order/allr   )r   postdelete)	cash/balancemargin/balancezmargin/riskzfutures/collateral-balancefutures/positionzfutures/riskfutures/funding-payments
order/histspot/fee)r   futures/transfer/depositfutures/transfer/withdraw)r   r   )r   accountCategoryaccountGroup)publicprivate)r   zfutures/contractr   zfutures/pricing-datazfutures/tickerr   r   zaccount/info)r   r   zfutures/free-marginzfutures/order/hist/currentr   futures/order/openzfutures/order/status)
z futures/isolated-position-marginzfutures/margin-typezfutures/leverager   r   futures/orderfutures/order/batchr   zsubuser/subuser-transferzsubuser/subuser-transfer-hist)r   r   zfutures/order/all)datar   r   )v1r   r   tradingz0.002)feeSide	tierBased
percentagetakermakerprecisionModeoptionscashmethodv2PrivateDataGetOrderHistfutures)r@   rB   rA   fillResponseFromRequestzBEP20 (BSC)arbitrumSolanazavalanche C chainOmniTRC20ERC20GO20BEP2BitcoinzBitcoin ABCLitecoinzMatic NetworkAkash)BSCARBSOLAVAXOMNIr   r   r   r   BTCBCHLTCMATICAKT)account-categoryaccount-grouprQ   defaultTypeaccountsByTyper   networksfeatures)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventionicebergmax
   )r   triggerr  
marketTypesymbolRequired)r   limitr  r  r  r  r    )	r   rH   rI   fetchMyTradesrp   rm   rr   rQ   rj   default  i )r   r  daysBackdaysBackCanceled	untilDaysr  r  r  )extendsrQ   r  )lastmarkindex)r   price)r  rH   rQ   r  forDerivatives)linearinverse)r  r@   r  rB   rC   
exceptions1900210050026001601060060600503100001100002100003100004100005100006100007100008100009100010100011100012100013100101150001200001200002200003200004200005200006200007200008200009200010200011200012200013200014200015300001300002300003300004300005300006300007300008300009300011300012300013300014300020)	300021300031310001310002310003310004310005510001900001)exactbroadcommonCurrenciesXBTBONDEDBEARBULLBeyondFiPollen)ra  BONDBTCBEARBTCBULLBYNPLN)deep_extendsuperr3   describeparse_numberr0   r+   r'   r,   r-   r.   r&   r(   r)   )self	__class__s    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/ascendex.pyrn  zascendex.describe   s7   h > @ KC
*KC
JKC
 $KC
 KC
 KC
 4KC
  NNN $N 	N
 %N %N TN "4N tN tN N &tN (N 'N (N  "4!N"  #N$ %N& $T'N( "4)N* &t+N, (-N. 1%/N0  1N2 +D3N4 *:5N6 +D7N8 &t9N: #J;N< *5=N> $T?N@ uANB "5CND  ENF !$GNH %dINJ ":KNL #DMNN +JONP QNR !%SNT +EUNV dWNX $UYNZ +E[N\ "4]N^ u_N` #EaNb dcNd !$eNf ugNh  iNj $UkNl !$mNn %eoNp )%qNr )%sNt tuNv wNx TyNz t{N| "5}N~ #DN@ &uANB 'CND $ZENF  GNH !%INJ +0#($( $#!%#( [NKC
r sKC
N tOKC
P i2 C .a ST $QKC
t    $a &  %a  +A	 
 &q  $Q  %a  *1  ,Q  ,Q  .q  1!  0  -a  21   4Q! " .q# $ ,Q% 0 %&34675645  ,-./0167()$ *+/0%
 *+-./0',( 1223/0>?4501<=./,-
$ -.<==>%)5, /DN &'012345.//0 	 " ,a$! +A 
 /04578>?<=6789$ EF7845<==>127867<=AB% 237856'-)% 1MxuKC
f $!%"&!..w7!..w7gKC
x YyKC
z $*!%9&  &"%&# .t .%#/"$$""$(%," {KC
| #&*(,,0,1).+06:#'#'"&#(	( #($)$)27+0/4#()$. r% &*&+#($)&**/# ',!%#($)&**/( $()-#[0d  )&+!%$*,-%+#($)*/	*  ) 5(,(-).1
 &+7
$ ',!%$(,0%)#($)*/	*#4 "#3  $	 ##{a}KC
@ ?J? /? I	?
 I? -? \? l? j? j? j? j? j? j?  j!?" i#?$ 1%?& j'?( j)?* j+?, j-?. m/?0 j1?2 13?4 m5?6 m7?8 m9?: m;?< m=?> m??@ mA?B mC?D 1E?F mG?H mI?J mK?L .M?N .O?P lQ?R lS?T lU?V lW?X lY?Z l[?\ l]?^ l_?` la?b /c?d ie?f lg?h li?j lk?l /*/**'*++}?@ CBAKC
F  !!!!GKC
 K K	    c                     | j                  |d| j                  d         }|j                         }| j                  |      S )Naccount)
safe_valuer   lower
capitalize)rp  paramsru  lowercaseAccounts       rr  get_accountzascendex.get_account  s9    //&)T\\)5LM"==?/00rs  c                 P   | j                  |      }| j                  |dg       }i }t        dt        |            D ]f  }||   }| j	                  |d      }| j                  |      }| j                  |dg       }	| j                  | j                  | j	                  |d                  }
i }t        dt        |	            D ]  }|	|   }| j	                  |d      }| j                  |      }| j                  |d      d| j                  |d	      | j                  |d
      |
ddd| j                  |d      dd| j                  |d      dddd||<    | j                  |||dd| j	                  |d      dddd|
ddd| j                  |d      ddd|d      ||<   i |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r   	assetCode
blockChainnativeScale	chainNamewithdrawFeeNallowWithdrawallowDepositminr  minWithdrawalminDepositAmt)amountwithdrawdeposit)feeactiver  r  	precisionlimits	assetNameminWithdrawalAmt)r  r  )r6   coder   typerA   r7   r  r  r  r  r  r  r   )v2PublicGetAssets	safe_listrangelensafe_stringsafe_currency_codero  parse_precisionnetwork_code_to_idsafe_number	safe_boolsafe_currency_structure)rp  ry  responser   resulticurrencyr6   r  chainsr  r   jnetworkEtnry	networkIdnetworkCodes                   rr  fetch_currencieszascendex.fetch_currencies  s     ))&14 ~~h3q#d)$ 8	AAwH!!(K8B**2.D^^HlB?F))$*>*>t?O?OPXZg?h*ijIH1c&k* %ay ,,\;G	"55i@++L-H" $|_ M#~~lNK!* $(#'#
 $(#3#3L/#R#'%
 $(#3#3L/#R#'$)%	4  77 ((;? &  $#
  $//:LM#!	 %-9 F4LC8	r rs  c                 x    | j                  |      }| j                  |      }||g\  }}| j                  ||      S )z
        retrieves data on all markets for ascendex
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )fetch_spot_marketsfetch_contract_marketsarray_concat)rp  ry  spotPromisecontractPromisespotMarketscontractMarketss         rr  fetch_marketszascendex.fetch_marketsL  sF     --f555f=(3_'E$_  o>>rs  c                 2   | j                  |      }| j                  |      }||g\  }}| j                  |dg       }| j                  |d      }| j                  |dg       }| j                  |d      }	| j	                  ||	      }
t        |
j                               }g }t        dt        |            D ]  }||   }|j                  d      dk\  r|
|   }| j                  |d      }| j                  |d      }d}|dk(  s|d	k(  r|d
k7  rd}| j                  |d      }| j                  |d      }| j                  |d      }d }| j                  |dd      }|j                  d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }| j                  |d      }| j                  |dd      }|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 | j                  |d$      | j                  |d      d%d d d&||d&||d&| j                  |d'      | j                  |d(      d&d)| j#                  |d*      |d+        |S ),Nr   symbolr   z-PERPstatusdomainFNormalInternalTradingLeveragedETFTminQtymaxQtytickSize
underlying/r   commissionReserveRatemarginTradabler6   basebaseIdquotequoteIdsettlesettleIdr  r@   rA   rB   rC   rD   r  contractr  lotSizer  r  r  minNotionalmaxNotionalr  r  r  costtradingStartTimer   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr   )v1PublicGetProductsv1PublicGetCashProductsr  index_byrl  listkeysr  r  findr  r  safe_string_2splitr  r  appendsafe_integer)rp  ry  productsPromisecashPromiser   r   productsDataproductsByIdcashDatacashAndPerpetualsByIddataByIdidsr  r  r6   marketr  r  r  r  r  minPricemaxPricer  partsr  r  r  r  r  r  s                                  rr  r  zascendex.fetch_spot_marketsW  s   226:* 226:< *;7$~~h;}}\8<>>$3 $h A##L2GH8==?#q#c(# H	AQBwww1$b\F%%fh7F%%fh7FF8#3D)DFVdLd%%fh7F%%fh7F''
;H H++FL(KJ$$S)E%%eQ/F&&ua0G**62D++G4E""6+BCC!^^F4DeLNMM 2b2$*u,2 2 &	2
 2 72 $2 D2 2 2 .2 2 %2 %2 &2  E!2" $#2$   $"&""..vyA!--fjA  $#!
  &%
  ('
  $//F#//F$  ,,V5GHc2 2-H	R rs  c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }|j                  d      }	| j	                  |	d      }
| j                  |
      }| j	                  |	d      }| j                  |      }| j	                  |d      }| j                  |      }||k(  }||k(  }|dz   |z   dz   |z   }| j                  |d	      }| j                  |d
      }| j                  |d      }|j                  i d|d|d|d|d|d|
d|d|dddddd ddddddd| j	                  |d      dk(  ddd||||| j                  d       d d d d | j                  |d!      | j                  |d"      d#d d d$| j                  |d%      | j                  |d&      d$| j                  |d'      | j                  |d(      d$| j                  |d)      | j                  |d*      d$d+| j                  |d,      |d-        |S ).Nr   r   r  r  r  r   settlementAsset:priceFilterlotSizeFilterr  r6   r  r  r  r  r  r  r  rB   r@   FrA   TrC   rD   r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  )v2PublicGetFuturesContractr  r  r  r  r  r  	safe_dictr  r  ro  r  )rp  ry  	contractsr   r  r  r  r6   r  r  r  r  r  r  r  r  r  r   r  r  r  r  s                         rr  r  zascendex.fetch_contract_markets  s)   33F;	L ~~i4q#d)$ C	A!WF!!&(3B))&,?J$$S)E%%eQ/F**62D&&ua0G++G4E''0ABH,,X6Fu_FnGCZ%'#-6F..?K NN6?CM""6+BCCMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 $2 2 %2 %2 $**68<H2  D!2" &#2$ # $ 1 1# 6"&""..}iH!--k:F  $#!
  $//xH#//xH
  $//ZH#//ZH
  $//F#//F$  ,,V5GHc2 2#C	H rs  c                     d| j                         i}| j                  | j                  ||            }| j                  |di       }| j	                  |d      S )a  
        fetches the current integer timestamp in milliseconds from the ascendex server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the ascendex server
        requestTimer   requestReceiveAt)millisecondsv1PublicGetExchangeInfoextendr  r  )rp  ry  requestr  r   s        rr  
fetch_timezascendex.fetch_timeM  s^     4,,.
 //GV0LM ~~h3  '9::rs  c                     | j                  | j                  d      }d}|E| j                  |      }| j                  |di       }| j                  |d      }|| j                  d<   |dd|dgS )a  
        fetch all the accounts associated with a profile
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        r   Nr   r   )r6   r  r  r   )r  r   v1PrivateGetInfor  )rp  ry  r   r  r   s        rr  fetch_accountszascendex.fetch_accountsd  s     ''oF,,V4H" >>(FB7D++D.AL,8DLL) # 	
 	
rs  c                 T   |d d d}| j                  |dg       }t        dt        |            D ]g  }||   }| j                  | j	                  |d            }| j                         }| j	                  |d      |d<   | j	                  |d      |d<   |||<   i | j                  |      S )	Nr   	timestampdatetimer   r   assetavailableBalancefreetotalBalancetotal)r  r  r  r  r  ru  safe_balance)rp  r  r  balancesr  r   r  ru  s           rr  parse_balancezascendex.parse_balance  s    

 >>(FB7q#h-( 	#AqkG**4+;+;GW+MNDllnG"..w8JKGFO#//HGG"F4L	#   ((rs  c                    |d d d}| j                  |dg       }t        dt        |            D ]  }||   }| j                  | j	                  |d            }| j                         }| j	                  |d      |d<   | j	                  |d      |d<   | j	                  |d	      }| j	                  |d
      }	t        j                  ||	      |d<   |||<    | j                  |      S )Nr  r   r   r  r  r  r  r  borrowedinterestdebt)	r  r  r  r  r  ru  r1   
string_addr  )
rp  r  r  r  r  r   r  ru  r  r  s
             rr  parse_margin_balancezascendex.parse_margin_balance  s    

 >>(FB7q#h-( 		#AqkG**4+;+;GW+MNDllnG"..w8JKGFO#//HGG##GZ8D''<H%00x@GFO"F4L		#   ((rs  c                 P   |d d d}| j                  |di       }| j                  |dg       }t        dt        |            D ]R  }||   }| j	                  | j                  |d            }| j                         }| j                  |d      |d<   |||<   T | j                  |      S )Nr  r   collateralsr   r  r   r  )r  r  r  r  r  r  ru  r  )	rp  r  r  r   r  r  r   r  ru  s	            rr  parse_swap_balancezascendex.parse_swap_balance  s    

 ~~h3nnT="=q#k*+ 	#A!!nG**4+;+;GW+MNDllnG#//CGG"F4L	#   ((rs  c                    | j                          | j                          d}d}| j                  dd|      \  }}| j                  d|      \  }}| j	                  |dd      }|dk(  }|s|rdn|}| j                  |d      }| j                  | j                  di       }| j                  ||d      }| j                  | j                  di       }| j                  |d	      }	d
|	i}
|dk(  r|dk7  rt        | j                  dz         |dk(  s|dk(  r||
d<   d}|dk(  s|dk(  r"| j                  | j                  |
|            }nE|dk(  r"| j                  | j                  |
|            }nt        | j                  dz   |z   dz         |dk(  r| j!                  |      S |dk(  r| j#                  |      S | j%                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://ascendex.github.io/ascendex-pro-api/#cash-account-balance
        https://ascendex.github.io/ascendex-pro-api/#margin-account-balance
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#position

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: wallet type, 'spot', 'margin', or 'swap'
        :param str [params.marginMode]: 'cross' or None, for spot margin trading, value of 'isolated' is invalid
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrP   rA   Fcrossr   r   r   r6   r   isolatedrB   z+ does not supported isolated margin tradingr   r@   z/ fetchBalance() is not currently supported for  markets)load_marketsload_accountshandle_market_type_and_paramshandle_margin_mode_and_paramsr  omitr  r   r  accountsr+   r6   "v1PrivateAccountCategoryGetBalancer  'v2PrivateAccountGroupGetFuturesPositionr/   r  r  r  )rp  ry  r  r   isMarginisCrossr   r   ru  r   r  r  s               rr  fetch_balancezascendex.fetch_balance  s    	

!??PTV\]
F!??PVW
F>>&(E:'"*gXJ
68,6FK**>:vN..26''6\
 *$:+?TWW'TTUUv%?h+F*9G&'& jH&<>>t{{7TZ?[\H6!CCDKKPWY_D`aHtww)ZZ]ggjttuuX **8448#,,X66%%h//rs  Nr  r  c                 X   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j	                  |di       }| j                  |d      }	| j                  |||	      }
| j                  |d      |
d<   |
S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  r6   r   tsseqnumnonce)r  r  v1PublicGetDepthr  r  r  parse_order_book)rp  r  r  ry  r  r  r  r   	orderbookr  r  s              rr  fetch_order_bookzascendex.fetch_order_book  s     	V$fTl
 ((Wf)EF0 ~~h3NN44	%%i6	&&y&)D++Ix@wrs  r   r  c                    d }| j                  |d      }| j                  |d      }|dk(  rdnd }| j                  |||      }| j                  |d      }| j                  |dg       }	| j                  |dg       }
| j                  |d      }| j                  i d|d	|d
d d| j                  |d      d| j                  |d      d| j                  |	d      d| j                  |	d      d| j                  |
d      d| j                  |
d      dd d|d|d|dd dd dd dd | j                  |d      d |d|      S )Nr  r  r@   r  closebidaskopenr  r   highlowr   	bidVolumer   	askVolumevwapr  previousClosechanger   averagevolume)
baseVolumequoteVolumer   )r  safe_symbolr  safe_ticker)rp  r   r  r  marketIdr  	delimiterr  r*  r+  r,  r-  s               rr  parse_tickerzascendex.parse_tickerD  s    	##FH5/ FNC	!!(FI>  1nnVUB/nnVUB// !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4##C+!
 ))#q1!
 4##C+!
 ))#q1!
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ **68<)!
* + 	rs  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |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
        :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  r6   r   )r  r  v1PublicGetTickerr  r  r=  )rp  r  ry  r  r  r  r   s          rr  fetch_tickerzascendex.fetch_tickerr  sr     	V$fTl
 ))$++gv*FG" ~~h3  v..rs  symbolsc                    | j                          i }d}|H| j                  |d      }| j                  |      }| j                  |      }dj	                  |      |d<   d}| j                  d||      \  }}d}|dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |dg       }	t        |	t              s| j                  |	g|      S | j                  |	|      S )aV  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://ascendex.github.io/ascendex-pro-api/#ticker
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#ticker

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        Nr   ,r  rz   r@   r   )r  r  r  
market_idsjoinr  r?  r  v2PublicGetFuturesTickerr  
isinstancer  parse_tickers)
rp  rA  ry  r  r  r  	marketIdsr  r  r   s
             rr  fetch_tickerszascendex.fetch_tickers  s    	%%gq1F[[(F0I # 3GH99.&RXYf6>--dkk'6.JKH44T[[&5QRH" ~~h3$%%%tfg66!!$00rs  c           	          | j                  |di       }| j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r"  ohlcv)r  r  r  )rp  ohlcvr  r   s       rr  parse_ohlcvzascendex.parse_ohlcv  s      ~~eVR0dD)T3'T3'T3'T3'T3'
 	
rs  r   sincec                    | j                          | j                  |      }|d   | j                  | j                  ||      d}| j	                  |      }| j                  | j                  di       }	| j                  |	dd      }
| j                  |d      }|J||d<   ||
}nt        ||
      }| j                  |||z  dz  d	      }|t        ||d	z         |d
<   n7||d
<   n1|(|d	z   |d
<   ||
}nt        ||
      }|||z  dz  z
  |d<   n|||d<   | j                  |d      }| j                  | j                  ||            }| j                  |dg       }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :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
        r6   )r  intervalrj   r  r  untilfromr  r   tonr   )r  r  r  r   parse_timeframer  r   r  r  sumr  v1PublicGetBarhistr  r  parse_ohlcvs)rp  r  	timeframerS  r  ry  r  r  durationr   defaultLimitrV  toWithLimitr  r   s                  rr  fetch_ohlcvzascendex.fetch_ohlcv  s    	V$Tl(()YO
 ''	2..|R@(('3?!!&'2#GFO}$E<0((5%(*:T*A1EK  #K ; +!AIGDM}$E<0#ux'7$'>?GFO GCL67+**4;;w+GH* ~~h3  vy%GGrs  tradec                 *   | j                  |d      }| j                  |dd      }| j                  |d      }| j                  |dd      }|rdnd}| j	                  d |      }| j                  ||| j                  |      |d	   d d d d |||d d d
|      S )Nr"  r  pqbmFsellbuyr  )r   r  r   r  r6   r   r  takerOrMakersider  r  r  r  )r  r  r  r  safe_market
safe_tradeiso8601)rp  rc  r  r  priceStringamountStringbuyerIsMakerrk  s           rr  parse_tradezascendex.parse_trade  s     %%eT2	((=''s3~~eT59%v5!!$/"Y/X&  " 
  	rs  c                    | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }	| j                  |	|||      S )a"  
        get the list of most recent trades for a particular symbol

        https://ascendex.github.io/ascendex-pro-api/#market-trades

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r6   rY  r   )r  r  v1PublicGetTradesr  r  r  parse_trades)
rp  r  rS  r  ry  r  r  r  recordsr   s
             rr  fetch_tradeszascendex.fetch_tradesA  s     	V$fTl
  GCL))$++gv*FG ..6264  >>rs  r  c                 :    ddddddd}| j                  |||      S )Nr-  closedcanceledrejected)
PendingNewNewPartiallyFilledFilledCanceledRejectedr  rp  r  statusess      rr  parse_order_statuszascendex.parse_order_statusg  s2     %""
 &&99rs  r   c           	         | j                  | j                  |d            }| j                  |d      }| j                  ||d      }| j                  |dd      }| j	                  |d      }||}| j                  |d      }| j                  |d      }	| j                  |d	      }
| j                  |g d
      }| j                  |d      }| j                  |d      }|t        |      dk  rd }| j                  |d      }|}||dk(  rd}|dk(  rd}| j                  |d      }| j                  |dd      }d }|(| j                  |d      }| j                  |      }||d}| j                  | j                  |d            }d }| j                  |d      }|dk(  rd}d }|dk(  r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(|      S ))Nr  r  r  r  sendingTimelastExecTimer  orderQtyavgPx)cumFilledQtycumQtyfillQtyorderIdr6   r   	orderType	stoplimitr  
stopmarketr  rk  cumFeer  feeAsset)r  r  	stopPriceexecInst
reduceOnlyTPostr   clientOrderIdr   lastTradeTimestampr  r  postOnlyr   r  r  r5  )filled	remainingr  r  r   )r  r  r9  safe_integer_2r  safe_string_nr  safe_string_lowersafe_number_2r  	omit_zero
safe_orderrn  )rp  r   r  r  r;  r  r  r  r  r  r5  r  r6   r  rawTypeLowerr  rk  feeCostr  feeCurrencyIdfeeCurrencyCoder   r  r  r  s                            rr  parse_orderzascendex.parse_orderr  s   R (()9)9%)JK##E84!!(FC8''{MJ	!..unE*I  0!!%4""5'2##E+PQeY/((5$=!A% $--e[A#{*|+%%eV4$$UHe< ,,UJ?M"55mDO+C ~~d&6&6uk&JK
##E:6|#JvH  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 f 
 D 
 4 
  
 * 
 D 
 U 
 L 
 f 
  D! 
" w# 
$ - 
. / 	rs  c                 D   | j                          | j                          | j                  | j                  di       }| j	                  |d      }d|i}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }i }t        dt        |            D ]k  }	||	   }
| j	                  |
d      }| j                  |dd      }| j                  |
d	i       }|
|| j                  |d
      | j                  |d      ddd||<   m |S )a  
        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r   r6   r   r   r   r  Nr  r  r   r   )r   r  r   r   r   r   )r  r  r  r  r  v1PrivateAccountGroupGetSpotFeer  r  r  r  r9  r  )rp  ry  ru  r   r  r  r   r   r  r  r  r;  r  
takerMakers                 rr  fetch_trading_feeszascendex.fetch_trading_fees  s1    	..26''6\
 77GV8TU" ~~h3~~dFB/q#d)$ 	Aq'C''X6H%%hc:FUB7J ))*g>))*g>"!F6N	 rs  r  rk  r  r  c                    | j                  |      }d}d}	| j                  d|      \  }}| j                  d||      \  }	}| j                  | j                  di       }
| j                  |
|	d      }|d}| j                  | j                  di       }| j                  |d      }| j                  |dd      }|||d   | j                         | j                  ||      ||d	}|d
k(  xs |dk(  }|dk(  xs |dk(  }| j                  |d      }| j                  |d|      }| j                  |dd      }| j                  |dd      }|r| j                  ||      |d<   |dk(  rd|d<   |dk(  rd|d<   |rd|d<   |$| j                  ||      |d<   |rd|d<   n|rd|d<   |||d<   |d   r|||d<   n||d<   |rd|d<   |rd|d<   | j                  |ddg      }| j                  ||      S )a&  
 @ignore
        helper function to build request
        :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 you want to trade in units of the 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
        :param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
        :param bool [params.postOnly]: True or False
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
        :returns dict: request to be sent to the exchange
        NcreateOrderRequestr   r   rA   r   r6   r  )r   r   r  timer  r  rk  r  stop_marketr  
stop_limitr  Fr  r   r  
orderPricer   r   Tr  r  r@   categoryr   
ReduceOnlyr  r  )r  r  r  r  r   r  r  r  r  amount_to_precisionis_post_onlyr  price_to_precisionr  r  )rp  r  r  rk  r  r  ry  r  r   r  r   r   ru  r   r  r  isMarketOrderisLimitOrderr  r  r  r   s                         rr  create_order_requestzascendex.create_order_requestM  sa    V$

!??@TV\]
F!??@TV\^de
F6FK**>:vN!&O..26''6**6?DI) /Tl%%'00@

 (*F0ECdl.B&&v}=$$]E6B^^FL%@
))&.+N$($;$;FE$JGL!%%*GM"%%*GM""&GJ##'#:#:6<#PGK '3$'4$$)GDM&>*&5
#*9G&'&2
#&,
#6L.#AB{{7F++rs  c                 V   | j                          | j                          | j                  |      }| j                  ||||||      }d}	|d   r| j	                  |      }	n| j                  |      }	| j                  |	di       }
| j                  |
ddi       }| j                  ||      S )a  
        create a trade order on the exchange

        https://ascendex.github.io/ascendex-pro-api/#place-order
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#new-order

        :param str symbol: unified CCXT market symbol
        :param str type: "limit" or "market"
        :param str side: "buy" or "sell"
        :param float amount: the amount of currency to trade
        :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
        :param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
        :param bool [params.postOnly]: True or False
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
        :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered(perpetual swap markets only)
        :param float [params.takeProfit.triggerPrice]: *swap only* take profit trigger price
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered(perpetual swap markets only)
        :param float [params.stopLoss.triggerPrice]: *swap only* stop loss trigger price
        :returns: `An order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NrB   r   r   r   )	r  r  r  r  %v2PrivateAccountGroupPostFuturesOrder!v1PrivateAccountCategoryPostOrderr  safe_dict_2r  )rp  r  r  rk  r  r  ry  r  r  r  r   r   s               rr  create_orderzascendex.create_order  s    , 	V$++FD$vV&>AA'JH==gFH@ ~~h3  w;v..rs  ordersc           	      N   | j                          | j                          g }d}d}t        dt        |            D ]  }||   }| j	                  |d      }||}n||k7  rt        | j                  dz         | j	                  |d      }	| j	                  |d      }
| j                  |d      }| j                  |d      }| j                  |d	i       }| j                  d
|      }|d   }|"||}n||k7  rt        | j                  dz         | j                  ||	|
|||      }|j                  |        | j                  |      }| j                  | j                  di       }| j	                  ||d   d      }|d}| j                  | j                  di       }| j	                  |d      }i }d}|d   rt        | j                  dz         ||d<   ||d<   ||d<   | j!                  |      }| j                  |di       }| j#                  |dg       }| j%                  ||      S )a  
        create a list of trade orders

        https://ascendex.github.io/ascendex-pro-api/#place-batch-orders
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#place-batch-orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.timeInForce]: "GTC", "IOC", "FOK", or "PO"
        :param bool [params.postOnly]: True or False
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  z; createOrders() requires all orders to have the same symbolr  rk  r  r  ry  rI   zS createOrders() requires all orders to have the same margin mode(isolated or cross)r   r   rA   r6   rB   zG createOrders() is not currently supported for swap markets on ascendexr   r   r  r   r   )r  r  r  r  r  r+   r6   r  r  r  r  r  r  r   r  r/   &v1PrivateAccountCategoryPostOrderBatchr  parse_orders)rp  r  ry  ordersRequestsr  r   r  rawOrderr;  r  rk  r  r  orderParamsmarginResultcurrentMarginModeorderRequestr  r   r   ru  r   r  r  r   r   s                             rr  create_orderszascendex.create_orders  sd    	
q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5D##Hf5D%%h9F$$Xw7E..8R@K==nkZL ,Q ,%!2J!%66(  4I  *I  J  J44XtT6SXZefL!!,/-	0. V$6FK**>6&>6R!&O..26''6&>tww)rrss (4GO$*9G&' .GHBB7KH. ~~h3~~dFB/  v..rs  r6   c                    | j                          | j                          d}|| j                  |      }| j                  d||      \  }}| j	                  | j
                  di       }| j                  ||d      }| j	                  | j                  di       }	| j                  |	d      }
|
||d}d}|dk(  s|d	k(  r"| j                  | j                  ||            }nJ|d
k(  r'||d<   | j                  | j                  ||            }nt        | j                  dz   |z   dz         | j	                  |di       }| j                  ||      S )a  
        fetches information on an order made by the user

        https://ascendex.github.io/ascendex-pro-api/#query-order
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#query-order-by-id

        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nrp   r   r   r   r6   )r   r   r  r@   rA   rB   r   z- fetchOrder() is not currently supported for r  r   )r  r  r  r  r  r   r  r  &v1PrivateAccountCategoryGetOrderStatusr  *v2PrivateAccountGroupGetFuturesOrderStatusr/   r6   r  )rp  r6   r  ry  r  r  queryr   r   ru  r   r  r  r   s                 rr  fetch_orderzascendex.fetch_orderO  sY    	[[(F88vvVe6FK**>4H..26''6) /

 FN 0BB4;;wX]C^_HV^*9G&'FFt{{SZ\aGbcHtww)XX[__bllmmH ~~h3f--rs  c                 ^   | j                          | j                          d}|| j                  |      }|d   }| j                  | j                  di       }| j                  |d      }| j                  d||      \  }}	| j                  | j                  di       }
| j                  |
|d      }||d}d}|d	k(  s|d
k(  r"| j                  | j                  ||	            }nJ|dk(  r'||d<   | j                  | j                  ||	            }nt        | j                  dz   |z   dz         | j                  |dg       }|dk(  r| j                  ||||      S g }t        dt!        |            D ](  }| j#                  ||   |      }|j%                  |       * | j'                  ||||      S )aa  
        fetch all unfilled currently open orders

        https://ascendex.github.io/ascendex-pro-api/#list-open-orders
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#list-open-orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r   r6   rm   r   r   )r   r   r@   rA   rB   r   z2 fetchOpenOrders() is not currently supported for r  r   r   )r  r  r  r  r  r  r  r   $v1PrivateAccountCategoryGetOrderOpenr  (v2PrivateAccountGroupGetFuturesOrderOpenr/   r6   r  r  r  r  r  r  filter_by_symbol_since_limit)rp  r  rS  r  ry  r  ru  r   r  r  r   r   r  r  r   r  r  r   s                     rr  fetch_open_orderszascendex.fetch_open_orders  s    	[[(FH%F..26''6889JFTZ[e6FK**>4H) /
 FN 0@@WV[A\]HV^*9G&'DDT[[QXZ_E`aHtww)]]`ddgqqrrH ~~h3i'$$T65%@@q#d)$ 	!A$$T!Wf5EMM% 	! 00NNrs  c                 T   | j                          | j                          | j                  | j                  di       }| j	                  |d      }i }d}|| j                  |      }|d   |d<   | j                  d||      \  }	}
| j                  | j                  di       }| j	                  |dd      }| j                  |	||dd	      }|||d
<   | j	                  |d      }|||d<   | j                  | j                  di       }| j	                  ||	d      }d}|dk(  r3||d<   ||d<   |||d<   | j                  | j                  ||
            }n|dk(  r.||d<   |||d<   | j                  | j                  ||
            }nV|dk(  r3||d<   ||d<   |||d<   | j                  | j                  ||
            }nt        | j                  dz   |	z   dz         | j                  |dg       }t!        |t"              }|s| j                  |dg       }| j%                  ||||      S )a  
        fetches information on multiple closed orders made by the user

        https://ascendex.github.io/ascendex-pro-api/#list-history-orders-v2
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#list-current-history-orders

        :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
        :param int [params.until]: the latest time in ms to fetch orders for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r   r6   Nr  rQ   r   r   /v2PrivateAccountGroupGetFuturesOrderHistCurrent)r@   rA   rB   	startTimerV  endTimer   r   +v1PrivateAccountCategoryGetOrderHistCurrentr   r   r  ru  pageSizez4 fetchClosedOrders() is not currently supported for r  r   )r  r  r  r  r  r  r  r   get_supported_mappingr  r  r   r  r/   r6   r  rG  r  r  )rp  r  rS  r  ry  ru  r   r  r  r  r  r   defaultMethodr   rV  r   r   r  r   isArrays                       rr  fetch_closed_orderszascendex.fetch_closed_orders)  s    	..26''6

 [[(F &tGH889LfV\]e../BBG(((<WX++D!#E3
 
 #(GK   1!&GI6FK**>4HBB'3GO$*9G&' #( GGT[]bHcdH22!0GI #( 55dkk'56QRHHH'3GO$*9G&' &+
#KKDKKX_afLghHtww)__bffissttx ~~h3T4(>>$3D  vue<<rs  c                 ~   |t        | j                  dz         | j                          | j                          | j	                  |      }| j                  d||      \  }}| j                  | j                  di       }| j                  ||d      }| j                  | j                  di       }	| j                  |	d      }
|
||d   | j                         dd	}| j                  |d
d      }|||d<   n||d<   | j                  |d
dg      }d}|dk(  s|dk(  r"| j                  | j                  ||            }nJ|dk(  r'||d<   | j                  | j                  ||            }nt!        | j                  dz   |z   dz         | j                  |di       }| j#                  |ddi       }| j%                  ||      S )a  
        cancels an open order

        https://ascendex.github.io/ascendex-pro-api/#cancel-order
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#cancel-order

        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumentrG   r   r   r   r6   foobar)r   r   r  r  r6   r  r  r@   rA   rB   r   z. cancelOrder() is not currently supported for r  r   r   r   )r*   r6   r  r  r  r  r  r   r  r  r  r  r  #v1PrivateAccountCategoryDeleteOrderr  'v2PrivateAccountGroupDeleteFuturesOrderr/   r  r  )rp  r6   r  ry  r  r  r  r   r   ru  r   r  r  r  r   r   s                   rr  cancel_orderzascendex.cancel_order  s    >#DGG.Y$YZZV$88PVWe6FK**>4H..26''6) /Tl%%'
 **6?DI !#GI)GDMYYv'>?FFN 0??GUZ@[\HV^*9G&'CCDKKPWY^D_`Htww)YY\``cmmnn@ ~~h3  w;v..rs  c                    | j                          | j                          d}|| j                  |      }| j                  d||      \  }}| j	                  | j
                  di       }| j                  ||d      }| j	                  | j                  di       }| j                  |d      }	|	|| j                         d}
||d   |
d<   d}|d	k(  s|d
k(  r"| j                  | j                  |
|            }nJ|dk(  r'||
d<   | j                  | j                  |
|            }nt        | j                  dz   |z   dz         | j                  d|i      S )a<  
        cancel all open orders

        https://ascendex.github.io/ascendex-pro-api/#cancel-all-orders
        https://ascendex.github.io/ascendex-futures-pro-api-v2/#cancel-all-open-orders

        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list with a single `order structure <https://docs.ccxt.com/#/?id=order-structure>` with the response assigned to the info property
        NrF   r   r   r   r6   )r   r   r  r  r@   rA   rB   r   z2 cancelAllOrders() is not currently supported for r  r   )r  r  r  r  r  r   r  r  r  &v1PrivateAccountCategoryDeleteOrderAllr  *v2PrivateAccountGroupDeleteFuturesOrderAllr/   r6   r  )rp  r  ry  r  r  r  r   r   ru  r   r  r  s               rr  cancel_all_orderszascendex.cancel_all_orders<	  sn    	[[(F889JFTZ[e6FK**>4H..26''6) /%%'

  &tGHFN 0BB4;;wX]C^_HV^*9G&'FFt{{SZ\aGbcHtww)]]`ddgqqrrF H 
  	rs  r  c                     | j                  |d      }| j                  |d      }| j                  ||      }| j                  |       |d n|d   }| j                  |d      }| j                  ||      }|||||dS )NaddresstagIdr  
blockchain)r   r  networkr  tag)r  check_addressnetwork_id_to_code)	rp  depositAddressr  r  r  r  r  r  r  s	            rr  parse_deposit_addresszascendex.parse_deposit_address	  s     "">9=  9~u57# (tx/?$$^\B	)))T:"
 	
rs  r  c                    | j                          | j                  |      }| j                  |dd      }| j                  |      }| j	                  |dg      }|d   |d}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }	t        |	      }
d}|
dkD  rm| j                  |	d      }|Et        |j                               }d	j                  |      }t        | j                  d
z   |z         | j                  ||i       }n| j                  |	di       }| j!                  ||      }| j                  |d|i      S )a  
        fetch the deposit address for a currency associated with self account

        https://ascendex.github.io/ascendex-pro-api/#query-deposit-addresses

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: unified network code for deposit chain
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r  r  r6   )r  r  r   r  Nr   z, za fetchDepositAddress() returned more than one address, a chainName parameter is required, one of r   r   )r  r  r  r  r   v1PrivateGetWalletDepositAddressr  r  r  r  r  r  r  rE  r*   r6   r  )rp  r  ry  r  r  r  r  r  r   	addressesnumAddressesr  addressesByChainName
chainNamesr  r  s                   rr  fetch_deposit_addresszascendex.fetch_deposit_address	  s|    	==&((KH++K8	6K=1d^#
 88Wf9UVD ~~h3NN4B7	9~!#'==K#H  !"6";";"=>
:.'  3V  )V  Y_  )_  `  `nn%99bIG nnY26G++GX>{{6H$
  	rs  c           	      R    ddi}| j                  |||| j                  ||            S )a  
        fetch all deposits made to an account
        :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>`
        txTyper  fetch_transactionsr  rp  r  rS  r  ry  r  s         rr  fetch_depositszascendex.fetch_deposits	  s5     i
 &&tUE4;;wPV;WXXrs  c           	      R    ddi}| j                  |||| j                  ||            S )a  
        fetch all withdrawals made from an account
        :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 withdrawals 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  
withdrawalr  r  s         rr  fetch_withdrawalszascendex.fetch_withdrawals	  s5     l
 &&tUE4;;wPV;WXXrs  c                 2   | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }	| j                  |	|||      S )a$  
        fetch history of deposits and withdrawals
        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr6   r  startTsr  r   )r  r  v1PrivateGetWalletTransactionsr  r  r  parse_transactions)
rp  r  rS  r  ry  r  r  r  r   transactionss
             rr  fetch_deposits_withdrawalsz#ascendex.fetch_deposits_withdrawals
  s     	
 }}T*H'~GG!&GI"'GJ66t{{7F7ST4 ~~h3~~dFB7&&|XueLLrs  c                 6    ddddd}| j                  |||      S )Npendingokr{  )	reviewingr  	confirmedr{  r  r  s      rr  parse_transaction_statusz!ascendex.parse_transaction_status@
  s,    " "	
 &&99rs  transactionc                    | j                  |di       }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	t        j                  ||	      }| j                  ||      }
i d|d	| j                  |d
      d| j                  |d      d| j                  |d      d|
dd d| j                  |      d| j                  | j                  |d            d|d| j                  |      d|dd d|d|dd d|dd d |
| j                  |	      d dddS )NdestAddressr  destTagr  r  r  
commissionr   r6   	requestIdtxidnetworkTransactionIdr  transactionTyper  r  r  r  r   addressFrom	addressTor  tagFromtagToupdated)r  r  rateF)commentr  internal)	r  r  r  r1   
string_subr  ro  r  rn  )rp  r  r  r  r  r  r  
currencyIdrp  feeCostStringr  s              rr  parse_transactionzascendex.parse_transactionI
  s   & nn[-D"";	:{I6%%k6:	%%k7;
''X>((lC)),F&&z8<
K
$"";<
 D$$[2HI
 D$$[2CD	

 
 t
 d''5
 d33D4D4D[RZ4[\
 
 Y/
 w
 4
 
 3
 t
  S!
" t#
$  ))-8
 1
 	
rs  c                    | j                          | j                          | j                  | j                  di       }| j	                  |d      }d|i}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }g }	t        dt        |            D ]%  }
|	j                  | j                  ||
                ' | j                  |      }| j                  |	d|d      S )a*  
        fetch all open positions
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r   r6   r   r   r  r  F)r  r  r  r  r  r  r  r  r  r  r  parse_positionmarket_symbolsfilter_by_array_positions)rp  rA  ry  ru  r   r  r  r   positionr  r  s              rr  fetch_positionszascendex.fetch_positions
  s     	..26''6\
 ??GU[@\]P ~~h3>>$R8q#h-( 	<AMM$--hqk:;	<%%g.--fhOOrs  r&  c                    | j                  |d      }| j                  ||      }| j                  |d      }t        j                  |d      r| j                  |d      }| j                  |d      }|dk(  rdnd}d }|dk(  r| j                  |d	      }| j	                  i d
|dd d|d   d| j                  |      d|dd d| j                  |d      d| j                  |d      dd 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 | j                  |d      d | j                  |d      | j                  |d      d
      S ) Nr  buyOpenOrderNotional0sellOpenOrderNotional
marginTypecrossedr  r  isolatedMarginr   r6   notionalr   liquidationPrice
entryPriceavgOpenPriceunrealizedPnlr   r  r&  r  	markPrice	lastPricerk  r  r  r   r  r  r  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior  r  )	r  rl  r1   	string_eqsafe_positionro  r  r  r  )rp  r&  r  r;  r/  r,  r   r9  s           rr  r#  zascendex.parse_position
  s)   . ##Hh7!!(F3##H.DEXs+''2IJH%%h=
!+y!8Wz

#))(4DEJ!! #
H#
$#
 fX&#
 ))(3	#

 *#
 #
 $**8^D#
 T--hH#
 $#
 ))(J?#
 D,,V^D#
 ))(K@#
 #
 D**8V<#
 d#
  !#
" ##
$ $(!%+/$!'+))(J?!--hH#//:KL7#
  	rs  c                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }i d|d|d| j                  |d      d| j                  |d      d| j	                  d	      d
d d|d| j                  |      dd dd dd dd dd dd d|d|d| j                  |      dd iS )Nr  r  fundingRatenextFundingTimer   r4  
indexPriceinterestRater*  estimatedSettlePricer  r   previousFundingRatenextFundingRatepreviousFundingTimestampnextFundingTimestamppreviousFundingDatetimenextFundingDatetimefundingTimestampfundingDatetimerU  )r  r9  r  r  ro  rn  )rp  r  r  r;  r  currentTimerF  nextFundingRateTimestamps           rr  parse_funding_ratezascendex.parse_funding_rate
  sw    ##Hh7!!(F3''&9**8]C#'#4#4X?P#Q 
H
f
 ))(K@
 $**8\B	

 D--c2
 #D
 
 [1
 "4
 t
 '
 #D
 &t
 "4
 ?
   8!
" t||,DE#
$ %
 	
rs  c                     | j                          | j                  |      }| j                  |      }| j                  |di       }| j	                  |dg       }| j                  ||      S )ab  
        fetch the funding rate for multiple markets
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rates structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexe by market symbols
        r   r  )r  r$  v2PublicGetFuturesPricingDatar  r  parse_funding_rates)rp  rA  ry  r  r   r  s         rr  fetch_funding_rateszascendex.fetch_funding_rates#  si     	%%g.55f=2 ~~h3NN4b9	''	7;;rs  c                    | j                          | j                          | j                  |      }| j                  | j                  di       }| j                  |d      }| j                  ||      }||d   |d}| j                  | j                  ||            }	|dk(  rt        j                  |      }| j                  | j                  |	|      | j                  |      |d      S )Nr   r6   )r   r  r  reduce)r  r  )r  r  r  r  r  r  r  6v2PrivateAccountGroupPostFuturesIsolatedPositionMarginr  r1   
string_absparse_margin_modificationro  )
rp  r  r  r  ry  r  ru  r   r  r  s
             rr  modify_margin_helperzascendex.modify_margin_helperI  s    V$..26''6))&&9)Tl

 NNt{{[bdjOkl 8''/F{{499(FK''/N
  	rs  r   c                 ^    | j                  |d      }|dk(  rdnd}||d   d dd d |d   |d d d
S )	Nr  r*  r	  failedr  r  r  )
r   r  r  r   r  r  r  r  r  r   r  )rp  r   r  	errorCoder  s        rr  rX  z"ascendex.parse_margin_modificationd  sU     $$T62	#s*X&$7O
 	
rs  c                 ,    | j                  || d|      S )aS  
        remove margin from a position
        :param str symbol: unified market symbol
        :param float amount: the amount of margin to remove
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
        rU  rY  rp  r  r  ry  s       rr  reduce_marginzascendex.reduce_margin{  s     ((&(FKKrs  c                 *    | j                  ||d|      S )a6  
        add margin
        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
        addr^  r_  s       rr  
add_marginzascendex.add_margin  s     ((GGrs  r  c                    |t        | j                  dz         |dk  s|dkD  rt        | j                  dz         | j                          | j	                          | j                  |      }|d   st        | j                  dz         | j                  | j                  di       }| j                  |d      }||d   |d	}| j                  | j                  ||            S )
a  
        set the level of leverage for a market

        https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-contract-leverage

        :param float leverage: the rate of leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        z) setLeverage() requires a symbol argumentr   d   z% leverage should be between 1 and 100rB   z+ setLeverage() supports swap contracts onlyr   r6   )r   r  r  )r*   r6   r+   r  r  r  r,   r  r  r  (v2PrivateAccountGroupPostFuturesLeverager  )rp  r  r  ry  r  ru  r   r  s           rr  set_leveragezascendex.set_leverage  s     >#DGG.Y$YZZqLhnTWW'NNOOV$f~DGG&SSTT..26''6)Tl 

 <<T[[RX=YZZrs  r   c                    |t        | j                  dz         |j                         }|dk(  rd}|dk7  r|dk7  rt        | j                  dz         | j	                          | j                          | j                  |      }| j                  | j                  di       }| j                  |d      }||d   |d}|d	   st        | j                  d
z         | j                  | j                  ||            S )a|  
        set margin mode to 'cross' or 'isolated'

        https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-margin-type

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        z+ setMarginMode() requires a symbol argumentr  r-  r  z@ setMarginMode() marginMode argument should be isolated or crossr   r6   )r   r  r,  rB   z- setMarginMode() supports swap contracts only)r*   r6   rw  r+   r  r  r  r  r  r  r,   *v2PrivateAccountGroupPostFuturesMarginTyper  )rp  r   r  ry  r  ru  r   r  s           rr  set_margin_modezascendex.set_margin_mode  s     >#DGG.[$[\\%%'
 "J#
i(?TWW'iijjV$..26''6)Tl$

 f~DGG&UUVV>>t{{7TZ?[\\rs  c                     | j                          | j                  |      }| j                  |dg       }| j                  |      }| j	                  ||d      S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
        r   r  )r  r  r  r$  parse_leverage_tiers)rp  rA  ry  r  r   s        rr  fetch_leverage_tierszascendex.fetch_leverage_tiers  sY     	226:: ~~h3%%g.((wAArs  c                    | j                  |dg       }| j                  |d      }| j                  ||      }g }t        dt	        |            D ]  }||   }| j                  |d      }|j                  | j                  |d      | j                  ||dd      |d   | j                  |d	      | j                  |d
      | j                  |d      | j                  t        j                  d|            |d        |S )zq
        :param dict info: Exchange market response for 1 market
        :param dict market: CCXT market
        marginRequirementsr  r   initialMarginRater   Nr  r  positionNotionalLowerBoundpositionNotionalUpperBoundmaintenanceMarginRater   )tierr  r  r  r  rs  maxLeverager   )r  r  rl  r  r  r  r[  r9  r  ro  r1   
string_div)	rp  r   r  ro  r;  tiersr  rt  rp  s	            rr  parse_market_leverage_tiersz$ascendex.parse_market_leverage_tiers  s   8 "^^D2FK##D(3!!(F3q#012 	A%a(D $ 0 07J KLLA**8VT:N"7O#//6RS#//6RS)-)9)9$@W)X#001C1CCIZ1[\	 		 rs  c                    | j                  |dg       }t        |      }|d d dd d di d}t        d|      D ]  }||   }| j                  |d      }| j                  |d      }	| j	                  ||	      }
d d d| j                  |d      ddd	|d
   |
<   |dk(  se| j                  |d      |d   d<   d|d   d<    |S )Nr~  )r  r   )r   r  r  r   r   r  r  r  F)r  r  r   r   r  r  r   )r  r  r  r  r  r  )rp  r  r  blockChainsblockChainsLengthr  r  r~  r  currencyCoder  s              rr  parse_deposit_withdraw_feez#ascendex.parse_deposit_withdraw_fee$  s   ( nnS,;,"
 " 
 q+, 	9A$QJ(([AI++Hf=L11)\JK#'t<$($4$4Z$O_de/F:{+ !A%,0,<,<Z,Wz"5)38z"<0	9 rs  codesc                     | j                          | j                  |      }| j                  |d      }| j                  ||d      S )ak  
        fetch deposit and withdraw fees

        https://ascendex.github.io/ascendex-pro-api/#list-all-assets

        :param str[]|None codes: list of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r}  )r  r  r  parse_deposit_withdraw_fees)rp  r~  ry  r  r   s        rr  fetch_deposit_withdraw_feesz$ascendex.fetch_deposit_withdraw_feesT  sE     	))&1~~h///e[IIrs  fromAccount	toAccountc                    | j                          | j                          | j                  | j                  di       }| j	                  |d      }| j                  |      }| j                  | j                  di       }	| j	                  |	||      }
| j	                  |	||      }|
dk7  r|dk7  rt        | j                  dz         || j                  ||      |d   |
|d}| j                  | j                  ||            }| j                  | j                  di       }| j                  |dd	      }| j                  ||      }|r||d
<   ||d<   ||d<   ||d<   |S )u  
        transfer currency internally between wallets on the same account
        :param str code: unified currency codeåå
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r   r6   r   r   zX transfer() only supports direct balance transfer between spot and swap, spot and margin)r   r  r  r  r  r   r   Tr  r  r  r  )r  r  r  r  r  r  r   r&   r6   currency_to_precision!v1PrivateAccountGroupPostTransferr  r  parse_transfer)rp  r  r  r  r  ry  ru  r   r  r   fromIdtoIdr  r  transferOptionsr   r   s                    rr  r   zascendex.transferc  ss    	..26''6==&6FK!!.+{K	9EV  +E  !E  F  F)00v>d^!
 99$++gv:VW ..z2F"&..B[]a"b&&x:"&1H]#$-H[!!'HX#'HZ rs  r   c                     | j                  |d      }| j                  d |      }|d d d |d d d | j                  |      d	S )Nr  )	r   r6   r  r   r  r  r  r  r  )r  r  parse_transfer_status)rp  r   r  r  r|  s        rr  r  zascendex.parse_transfer  sX     !!(F3..tX>$008

 
	
rs  c                     |dk(  ryy)Nr*  r	  r[   )rp  r  s     rr  r  zascendex.parse_transfer_status  s    S=rs  c           	         | j                          | j                          d}| j                  |dd      \  }}|r| j                  d||||dd      S | j	                  | j
                  di       }| j                  |d      }d|i}d	}	|| j                  |      }	|	d   |d
<   |||d<   | j                  | j                  ||            }
| j	                  |
di       }| j                  |dg       }| j                  ||	||      S )aE  
        fetch the history of funding payments paid and received on self account

        https://ascendex.github.io/ascendex-futures-pro-api-v2/#funding-payment-history

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        Fr[   paginatepage   r   r6   r   Nr  r  r   )r  r  handle_option_and_params fetch_paginated_call_incrementalr  r  r  r  .v2PrivateAccountGroupGetFuturesFundingPaymentsr  r  parse_incomes)rp  r  rS  r  ry  r  ru  r   r  r  r  r   rowss                rr  fetch_funding_historyzascendex.fetch_funding_history  s*    	88AVXbc&889NPVX]_dflntvxyy..26''6\
 [[(F &tGH"'GJFFt{{SZ\bGcd& ~~h3~~dFB/!!$u==rs  c           
          | j                  |d      }| j                  |d      }|| j                  ||dd      d|| j                  |      d | j	                  |d      dS )Nr  r  -rB   USDTpaymentInUSDT)r   r  r  r  r   r6   r  )r  r  r9  rn  r  )rp  incomer  r;  r  s        rr  parse_incomezascendex.parse_income  sn     ##FH5%%fk:	&&xfE"Y/&&v?
 	
rs  c                 \   | j                          | j                          | j                  | j                  di       }| j	                  |d      }d|i}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  ||d      S )a  
        fetches the set margin mode of the user

        https://ascendex.github.io/ascendex-futures-pro-api-v2/#position

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `margin mode structures <https://docs.ccxt.com/#/?id=margin-mode-structure>`
        r   r6   r   r   r  r  )	r  r  r  r  r  r  r  r  parse_margin_modes)	rp  rA  ry  ru  r   r  r  r   marginModess	            rr  fetch_margin_modeszascendex.fetch_margin_modes  s     	..26''6\
 ??GU[@\]P ~~h3nnT;;&&{GXFFrs  c                     | j                  |d      }| j                  |d      }|dk(  rdnd}|| j                  ||      |dS )Nr  r,  r-  r  r  )r   r  r   )r  r9  )rp  r   r  r;  r,  rA   s         rr  parse_margin_modezascendex.parse_margin_mode*  sT    ##J9%%j,?
'94:&&x8 
 	
rs  c                 \   | j                          | j                          | j                  | j                  di       }| j	                  |d      }d|i}| j                  | j                  ||            }| j                  |di       }| j                  |dg       }| j                  ||d      S )a  
        fetch the set leverage for all contract markets

        https://ascendex.github.io/ascendex-futures-pro-api-v2/#position

        :param str[] [symbols]: a list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
        r   r6   r   r   r  r  )	r  r  r  r  r  r  r  r  parse_leverages)	rp  rA  ry  ru  r   r  r  r   	leveragess	            rr  fetch_leverageszascendex.fetch_leverages4  s     	..26''6\
 ??GU[@\]P ~~h3NN4b9	##IwAArs  c                     | j                  |d      }| j                  |d      }| j                  |d      }|dk(  rdnd}|| j                  ||      |||dS )Nr  r  r,  r-  r  r  )r   r  r   longLeverageshortLeverage)r  r  r9  )rp  r  r  r;  leverageValuer,  r   s          rr  parse_leveragezascendex.parse_leverageq  sl    ##Hh7))(J?%%h=
!+y!8Wz
&&x8$)*
 	
rs  r   GETc                 B   |d   }|d   }| j                  |d      }	d}
|	dk(  }|s|	dk(  r'|
| j                  d|      z  }
| j                  |d      }| j                  ||      }|
d	z  }
|d
k(  r|	dk(  rd|z   dz   |z   }n|dz   |z   }n|
|dz   z  }
|r|
| j                  d|      z  }
| j                  |d      }|
|z  }
|dk(  r|dk(  s|dk(  rd}|dk(  r|dk(  rd}|j                  d      dk\  r|j	                  d      }|d   }| j                  || j                  |            }|dk(  r|r|
d| j                  |      z   z  }
n| j                          t        | j                               }|dz   |z   }| j                  | j                  |      | j                  | j                        t        j                  d      }| j                  ||d}|dk(  r|r.|
d| j                  |      z   z  }
nd|d<   | j!                  |      }| j"                  d   d    |
z   }
|
|||d!S )"Nr   r       r   r   z/{account-group}r   z	/api/pro/r   r   zdata/r  z{account-category}/r   r   r   r   r   r   r  subuserr   ?+base64)z
x-auth-keyzx-auth-timestampzx-auth-signaturer  zapplication/jsonzContent-Typer   r   )r   r   bodyheaders)r  implode_paramsr  r  r  extract_params	urlencodecheck_required_credentialsstrr  hmacencodesecrethashlibsha256apiKeyjsonr   )rp  pathr   r   ry  r  r  r   accessr  r   r   r  r  r  payloadr  s                    rr  signzascendex.sign~  s^   a&QQ'#44t~54&&'96BBCYYv7F%%dF3{d?v~!G+c1G;!C-'17S= C4&&'<fEEC6#56wtO'^";L\A\GtO'Z"7G<<	"a'MM#&EAhG64#6#6t#<=XsT^^F333++-D--/0I#o/G99T[[14;;t{{3KW^^]efD"kk$-$(G
 3!777C*<'yy(iiv&,fdwOOrs  httpCodereasonr   r   r  r  c
                 j   |y | j                  |d      }
| j                  |d      }|
d uxr |
dk7  }|s|}| j                  dz   |z   }| j                  | j                  d   |
|       | j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )Nr  messager*   r^  r_  )r  r6   throw_exactly_matched_exceptionr!  throw_broadly_matched_exceptionr&   )rp  r  r  r   r   r  r  r  requestHeadersrequestBodyr  r  errorfeedbacks                 rr  handle_errorszascendex.handle_errors  s     &1""8Y7T!4W(ww}t+H001I4QYZ001I7T\]001I7T\]))rs  )N)i__name__
__module____qualname__r   rn  r{  r   r  r%   r   r  r  r  r   r  r   r  r   r  r  r  r   r  r   r(  dictr   r=  r@  r   r   rJ  r  rR  rb  r!   rr  rw  r   r  r   r  r"   r  r   r   floatr   r  r  r   r  r  r  r  r  r  r	   r
   r  r  r#   r  r   r  r  r!  r   r'  r#  r   rO  r    rS  r   rY  rX  r`  rc  rg  rj  r   rm  r   rx  r}  r  r$   r   r  r  r  r  r   r  r   r  r   r  r   r  r  intr  __classcell__)rq  s   @rr  r3   r3      s=   L# L\ "$ 1 ') [Z [z $& 	?$v, 	? )+ EtF| EN -/ m4< m^ !# ;s ;. %' $
4= $
L) ) )&)  $& Y0( Y0v :>b *s *3 *Y *X,4 , ,6 ,\ 02 /3 /f /@ 04B -1W -17 -1^
 
4 
4 26DW[df BH# BHc BHQT BHkoptku BHH   v    D 6:UW $?3 $?s $?# $?\`af\g $?L	: 	:i iv i iV )+ .{ .` os{} F,3 F,i F,y F,Z_ F,hk F,P gksu `/3 `/i `/y `/RW `/`c `/D @B V/D$6 V/p 26b g.c g.3 g.R /3TXac oO oO3 oOc oOhlmrhs oOb 154VZce c=# c=S c=PS c=jnotju c=J 37r l/s l/C l/\ /32 H HT
h 
R` 
: 79 G# G^ GR *.Dt\^ Y3 Yc Y Ycghsct Y -1tRV_a Yc Y YC Yfjkvfw Y 6:[_hj 6Ms 6M# 6MUX 6Most  pA 6Mp:s :5
T 5
X 5
Q\ 5
n 26b <Pw <PT(^ <P|=t =V =~$
6 $
[ $
L 6:" $<7 $< $<L FH 3 L^ 6
d 
F 
N` 
. @B LC L LFX L =? H He HCU H 9=R [S [# [: >B" ]# ]s ]@ 7;2 'BG 'B- 'BR- -$|J\ -^. .` <@ J J [] 'S '% 'c 'c 'an 'R
t 
x 
= 
$C C 
 37TX\eg 3>C 3>s 3>RU 3>j
6 
* 59 ;G' ;G ;Gz
D 
* 
 26b ;Bw ;BY ;Bz
t 
V 
x 
 &eBSW 2Phc 3 S # X\ dg rs  r3   )8ccxt.base.exchanger   ccxt.abstract.ascendexr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   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/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3   r  rs  rr  <module>r     s}    ( .  t  t  t  t  t  t  t  t  t  * 0 - - . ' & . ) ) 4 %k6x k6rs  