
    ei2x                    h   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          Z7dS )    )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dhd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dhd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"dhd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'dhd"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d0Z6di fd-ede&fd1Z7di fde&fd2Z8dhd3e9de:fd4Z;i fd5ede:fd6Z<dddi fd5e&dededee=         fd7Z>dddi fd5e&dededee=         fd8Z?dddi fd5e&dededee=         fd9Z@d e&fd:ZAdhd;ed3e9de=fd<ZBdi fdedeeC         fd=ZDdhd>ede	fd?ZEdhde	deFfd@ZGdi fdedeHfdAZIi fdedeJfdBZKdhdCede	deJfdDZLi fded'e.deJfdEZMi fded'e.deJfdFZNdi fdGeOde&fdHZPdi fdIede&fdJZQdi fdedeRfdKZSdhde	deeT         fdLZUdhd3e9fdMZVdi fdNefdOZWi fd5ed'e.dPedQedeXf
dRZYdhdSed3e9deXfdTZZd e&de&fdUZ[dddi fde&dedefdVZ\dhde	fdWZ]di fdede^fdXZ_dhdIede`fdYZadi fdedebfdZZcdi fdefd[Zddhde	fd\ZedhdGede	deffd]Zgd^d_i ddfd`ZhdaeOdbedceddedeedfefdgZi xZjS )iascendexreturnc                 	   |                      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i dSddTddUd
dVddWd
dXd
dYd.dZd
d[d
d\d
d]d
d^dd_dd`ddaddbddcd
dddidedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxidwdyidxdzgd{d|d}d~dddi ddddddddddddddddddddddddddddddddddddiidddddddddddddddddddddddddddddd	dddddddddddddddidddiiddiddddddddddddddddddd
ddddddddddddd|                     d          |                     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
ddddd
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          d t          dt          dt          dt          dt          dt          dt          dt          dt          d	t          d
t          dt          dt          dt          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fetchAllGreeksfetchBalancefetchBorrowRatefetchBorrowRateHistoryfetchBorrowRatesfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistory
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterests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-grouprU   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   fetchMyTradesry   rv   r{   rU   rr   default  i )r  r  daysBackdaysBackCanceled	untilDaysr  r  r  )extendsrU   r  )lastmarkindex)r  price)r"  rH   rU   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)rj  BONDBTCBEARBTCBULLBYNPLN)deep_extendsuperr3   describeparse_numberr0   r+   r'   r,   r-   r.   r&   r(   r)   )self	__class__s    K/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/ascendex.pyrw  zascendex.describe   sb   h 5 5 > > @ @ TC
*TC
JTC
 $TC
 TC
 TC
 4TC
  WWW $W 	W
 %W %W TW "4W tW tW W &tW (W 'W (W  "4!W"  #W W$ !%%W& 'W( "5)W* )%+W, #E-W. $T/W0 '1W2 (3W4 "45W6 &t7W8 (9W: 1%;W<  =W> +D?W@ *:AWB +DCWD &tEW W WF #JGWH *5IWJ $TKWL uMWN "5OWP *5QWR +ESWT  UWV !$WWX %dYWZ ":[W\ #D]W^ +J_W` aWb !%cWd +EeWf dgW W Wh $ZiWj +EkWl %dmWn "4oWp uqWr #EsWt duWv !$wWx uyWz  {W| $U}W~ !$W@ %eAWB )%CWD )%EWF tGWH IW W WJ TKWL tMWN "5OWP #DQWR &uSWT 'UWV $ZWWX  YWZ !%[W\ )%]W^ "5_W` #DaWb cWd 4eWf tgWh  iWj "5kW Wl DmW WTC
D  ETC
` taTC
b i2 C .a ST $  cTC
F    $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 DN &'012345.//0   	 " ,a$! +A 
 /04578>?<=6789$ $ EF7845<==>127867<=AB% % 237856' '-) )%  % 1 1Mx xGTC
x $!%"&!..w77!..w77 yTC
J YKTC
L $*!%9&  &"%&# # .t .%#/"$$""$(%,"    MTC
N	 #&*(,,0,1).+06:#'#'"&#(	( ( #($)$)27+0/4#()$ $. r% &*&+#($)&**/# # ',!%#($)&**/( ( $()-#[0 0d  )&+!%$*,-%+#($)*/	* 	*   ) 5(,(-).1 1
 &+7 7
$ ',!%$(,0%)#($)*/	* 	*# #4 "#3  $	  ## {a aO	TC
R ?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 BSTC
X  !!!! !YTC
 T T T	    c                     |                      |d| j        d                   }|                                }|                     |          S )Naccount)
safe_valuer   lower
capitalize)ry  paramsr~  lowercaseAccounts       r{  get_accountzascendex.get_account  s?    //&)T\)5LMM"==??/000r|  c                    |                      |          }|                     |dg           }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |dg           }	|                     |                     |                     |d                              }
i }t          dt          |	                    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 )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_coderx  parse_precisionnetwork_code_to_idsafe_number	safe_boolsafe_currency_structure)ry  r  responser   resulticurrencyr6   r  chainsr  r   jnetworkEtnry	networkIdnetworkCodes                   r{  fetch_currencieszascendex.fetch_currencies  sr    ))&114 ~~h33q#d))$$ 8	 8	AAwH!!(K88B**2..D^^HlB??F))$*>*>t?O?OPXZg?h?h*i*ijjIH1c&kk**  %ay ,,\;GG	"55i@@++L-HH" $|_ M M#~~lNKK!* $(#'# #
 $(#3#3L/#R#R#'% %
 $(#3#3L/#R#R#'$ $ ) )%%,  77 ((;?? &  $# 
  $//:LMM#! !	 	 %-9 9  F4LL0 r|  c                     |                      |          }|                     |          }||g\  }}|                     ||          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)ry  r  spotPromisecontractPromisespotMarketscontractMarketss         r{  fetch_marketszascendex.fetch_marketsU  sO     --f5555f==(3_'E$_  o>>>r|  c                 :   |                      |          }|                     |          }||g\  }}|                     |dg           }|                     |d          }|                     |dg           }|                     |d          }	|                     ||	          }
t          |
                                          }g }t          dt          |                    D ]7}||         }|	                    d          dk    r%|
|         }| 
                    |d          }| 
                    |d          }d}|dk    s|d	k    r|d
k    rd}|                     |d          }|                     |d          }|                     |d          }d }|                     |dd          }|                    d          }| 
                    |d          }| 
                    |d          }|                     |          }|                     |          }|                     |d          }|                     |dd          }|                    i d|d|dz   |z   d|d|d|d|dd dd ddddd|ddddd dd!|d"dd#d d ||d d d d d |                     |d$          |                     |d          d%d d d&||d&||d&|                     |d'          |                     |d(          d&d)|                     |d*          |d+           9|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_byru  listkeysr  r  findr  r  safe_string_2splitr  r  appendsafe_integer)ry  r  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                                  r{  r  zascendex.fetch_spot_markets`  s%   226::* 226::< *;7$~~h;;}}\8<<>>$33 $h A A##L2GHH8==??##q#c((## H	 H	AQBwww1$$b\F%%fh77F%%fh77FF8##3D)D)DFVdLdLd%%fh77F%%fh77F''
;;H H++FL(KKJ$$S))E%%eQ//F&&ua00G**622D++G44E""6+BCCC!^^F4DeL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A!--fjAA   $#! !
  &% 
  (' 
  $//FF#//FF  $  ,,V5GHHc2 2 2 2 2 2 2f r|  c                    |                      |          }|                     |dg           }g }t          dt          |                    D ]s}||         }|                     |d          }|                     |d          }|                    d          }	|                     |	d          }
|                     |
          }|                     |	d          }|                     |          }|                     |d          }|                     |          }||k    }||k    }|dz   |z   dz   |z   }|                     |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k    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-           u|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  rx  r  )ry  r  	contractsr   r  r  r  r6   r  r  r  r  r  r  r  r  r(  r)  r  r  r  r  s                         r{  r  zascendex.fetch_contract_markets  s   33F;;	L ~~i44q#d))$$ C	 C	A!WF!!&(33B))&,??J$$S))E%%eQ//F**622D&&ua00G++G44E''0ABBH,,X66Fu_FnGCZ%'#-6F..??K NN6?CCM""6+BC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 6"&""..}iHH!--k:FF   $#! !
  $//xHH#//xHH 
  $//ZHH#//ZHH 
  $//FF#//FF  $  ,,V5GHHc2 2 2 2 2 2 2f r|  c                     d|                                  i}|                     |                     ||                    }|                     |di           }|                     |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  )ry  r  requestr  r   s        r{  
fetch_timezascendex.fetch_timeV  sm     4,,..
 //GV0L0LMM ~~h33  '9:::r|  c                     |                      | j        d          }d}|L|                     |          }|                     |di           }|                      |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  )ry  r  r   r  r   s        r{  fetch_accountszascendex.fetch_accountsm  s     ''oFF,,V44H" >>(FB77D++D.AAL,8DL) # 	 
 	
r|  c                    |d d d}|                      |dg           }t          dt          |                    D ]~}||         }|                     |                     |d                    }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )	Nr   	timestampdatetimer   r   assetavailableBalancefreetotalBalancetotal)r  r  r  r  r  r~  safe_balance)ry  r  r  balancesr  r   r  r~  s           r{  parse_balancezascendex.parse_balance  s    
 

 >>(FB77q#h--(( 	# 	#AqkG**4+;+;GW+M+MNNDllnnG"..w8JKKGFO#//HHGG"F4LL  (((r|  c                 &   |d d d}|                      |dg           }t          dt          |                    D ]}||         }|                     |                     |d                    }|                                 }|                     |d          |d<   |                     |d          |d<   |                     |d	          }|                     |d
          }	t          j        ||	          |d<   |||<   |                     |          S )Nr  r   r   r
  r  r  r  r  borrowedinterestdebt)	r  r  r  r  r  r~  r1   
string_addr  )
ry  r  r  r  r  r   r  r~  r  r  s
             r{  parse_margin_balancezascendex.parse_margin_balance  s   
 

 >>(FB77q#h--(( 		# 		#AqkG**4+;+;GW+M+MNNDllnnG"..w8JKKGFO#//HHGG##GZ88D''<<H%0x@@GFO"F4LL  (((r|  c                    |d d d}|                      |di           }|                     |dg           }t          dt          |                    D ]e}||         }|                     |                     |d                    }|                                 }|                     |d          |d<   |||<   f|                     |          S )Nr  r   collateralsr   r
  r   r  )r  r  r  r  r  r  r~  r  )	ry  r  r  r   r  r  r   r  r~  s	            r{  parse_swap_balancezascendex.parse_swap_balance  s    
 

 ~~h33nnT="==q#k**++ 	# 	#A!!nG**4+;+;GW+M+MNNDllnnG#//CCGG"F4LL  (((r|  c                    |                                   |                                  d}d}|                     dd|          \  }}|                     d|          \  }}|                     |dd          }|dk    }|s|rdn|}|                     |d          }|                     | j        di           }|                     ||d          }|                     | j	        di           }|                     |d	          }	d
|	i}
|dk    r|dk    rt          | j        dz             |dk    s|dk    r||
d<   d}|dk    s|dk    r*|                     |                     |
|                    }nM|dk    r*|                     |                     |
|                    }nt          | j        dz   |z   dz             |dk    r|                     |          S |dk    r|                     |          S |                     |          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>`
        NrQ   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  )ry  r  r  r  isMarginisCrossr   r   r~  r   r  r  s               r{  fetch_balancezascendex.fetch_balance  sI    	

!??PTV\]]
F!??PVWW
F>>&(E::'"*FgFXXJ
68,,6FKK**>:vNN..266''66\
 *$$:+?+?TW'TTUUUv%%?h+F+F*9G&'&  jH&<&<>>t{{7TZ?[?[\\HH6!!CCDKKPWY_D`D`aaHHtw)ZZ]ggjttuuuX **84448##,,X666%%h///r|  Nr  r  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |di           }|                     |d          }	|                     |||	          }
|                     |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)ry  r  r  r  r  r  r  r   	orderbookr  r  s              r{  fetch_order_bookzascendex.fetch_order_book!  s     	V$$fTl
 ((Wf)E)EFF0 ~~h33NN444	%%i66	&&y&)DD++Ix@@wr|  r   r  c                 
   d }|                      |d          }|                      |d          }|dk    rdnd }|                     |||          }|                      |d          }|                     |dg           }	|                     |dg           }
|                      |d          }|                     i d|d	|d
d d|                      |d          d|                      |d          d|                      |	d          d|                      |	d          d|                      |
d          d|                      |
d          dd d|d|d|dd dd dd dd |                      |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)ry  r   r  r  marketIdr  	delimiterr  r3  r4  r5  r6  s               r{  parse_tickerzascendex.parse_tickerM  s#    	##FH55// FNNCC	!!(FI>>  11nnVUB//nnVUB//// !
f!
!
 !
 D$$VV44	!

 4##FE22!
 4##C++!
 ))#q11!
 4##C++!
 ))#q11!
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ **68<<)!
 !
 !
* +  	r|  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          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  rF  )ry  r  r  r  r  r  r   s          r{  fetch_tickerzascendex.fetch_ticker{  s     	V$$fTl
 ))$++gv*F*FGG" ~~h33  v...r|  symbolsc                    |                                   i }d}|X|                     |d          }|                     |          }|                     |          }d                    |          |d<   d}|                     d||          \  }}d}|dk    r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |dg           }	t          |	t                    s|                     |	g|          S |                     |	|          S )aT  
        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  r   r@   r   )r  r  r  
market_idsjoinr!  rH  r   v2PublicGetFuturesTickerr  
isinstancer  parse_tickers)
ry  rJ  r  r  r  r  	marketIdsr  r  r   s
             r{  fetch_tickerszascendex.fetch_tickers  s=    	%%gq11F[[((F00I # 3 3GH99.&RXYYf6>>--dkk'6.J.JKKHH44T[[&5Q5QRRH" ~~h33$%% 	7%%tfg666!!$000r|  c           	      0   |                      |di           }|                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r+  ohlcv)r  r  r  )ry  ohlcvr  r   s       r{  parse_ohlcvzascendex.parse_ohlcv  s      ~~eVR00dD))T3''T3''T3''T3''T3''
 	
r|  r   	timeframesincec                 R   |                                   |                     |          }|d         |                     | j        ||          d}|                     |          }|                     | j        di           }	|                     |	dd          }
|                     |d          }|V||d<   ||
}nt          ||
          }| 	                    |||z  d	z  d
          }|t          ||d
z             |d<   n;||d<   n5|,|d
z   |d<   ||
}nt          ||
          }|||z  d	z  z
  |d<   n|||d<   | 
                    |d          }|                     |                     ||                    }|                     |dg           }|                     |||||          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  intervalrr   r  r  untilNfromr  r   tonr   )r  r  r  r   parse_timeframer  r   r  r  sumr#  v1PublicGetBarhistr   r  parse_ohlcvs)ry  r  r\  r]  r  r  r  r  durationr   defaultLimitr`  toWithLimitr  r   s                  r{  fetch_ohlcvzascendex.fetch_ohlcv  s    	V$$Tl(()YOO
 
 ''	22..|R@@(('3??!!&'22#GFO}$E<00((5%(*:T*A1EEK  #K ; ; +!AIGDM}$E<00#ux'7$'>?GFOO GCL67++**4;;w+G+GHH* ~~h33  vy%GGGr|  tradec                 h   |                      |d          }|                     |dd          }|                     |d          }|                     |dd          }|rdnd}|                     d |          }|                     |||                     |          |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)ry  rl  r  r  priceStringamountStringbuyerIsMakerrt  s           r{  parse_tradezascendex.parse_trade(  s     %%eT22	((==''s33~~eT599%0vv5!!$//"Y//X&  " 
  
   	r|  c                 T   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          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   Nrc  r   )r  r  v1PublicGetTradesr   r  r  parse_trades)
ry  r  r]  r  r  r  r  r  recordsr   s
             r{  fetch_tradeszascendex.fetch_tradesJ  s     	V$$fTl
  GCL))$++gv*F*FGG ..626644  >>>r|  r  c                 B    ddddddd}|                      |||          S )Nr6  closedcanceledrejected)
PendingNewNewPartiallyFilledFilledCanceledRejectedr  ry  r  statusess      r{  parse_order_statuszascendex.parse_order_statusp  s:     %""
 
 &&999r|  r   c           	         |                      |                     |d                    }|                     |d          }|                     ||d          }|                     |g d          }|                     |d          }||}|                     |d          }|                     |d          }	|                     |dd	          }
|                     |g d
          }|                     |d          }|                     |d          }|t          |          dk     rd }|                     |d          }|}||dk    rd}|dk    rd}|                     |d          }| 	                    |dd          }d }|0|                     |d          }| 
                    |          }||d}|                     |                     |d                    }d }|                     |d          }|dk    rd}d }|dk    rd}|                     i d|d|d|d|d |                     |          d!|d|d"|d#d d$|d%|d|d|d&|d'|	d(d d)|
|d ||d d*|          S )+Nr  r  r  )r  sendingTimetimelastExecTimer&  orderQtyavgPxavgFilledPx)cumFilledQtycumQtyfillQtyorderIdr6   r   	orderType	stoplimitr  
stopmarketr  rt  cumFeer  feeAsset)r  r  	stopPriceexecInst
reduceonlyTr   r   clientOrderIdr  r	  lastTradeTimestampr  r  postOnly
reduceOnlyr  r  r  r>  )filled	remainingr  r  r   )r  r  rB  safe_integer_nr  r  safe_string_nr  safe_string_lowersafe_number_2r  	omit_zero
safe_orderrw  )ry  r   r  r  rD  r  r  r  r&  r  r>  r  r6   r  rawTypeLowerr  rt  feeCostr  feeCurrencyIdfeeCurrencyCoder  r  r  r  s                            r{  parse_orderzascendex.parse_order{  s^   V (()9)9%)J)JKK##E844!!(FC88''/S/S/STT	!..unEE*I  00!!%44$$UG]CC##E+P+P+PQQeY//((55$=!!A%% $--e[AA#{**|++%%eV44$$UHe<< ,,UJ??M"55mDDO+ C ~~d&6&6uk&J&JKK
))%<<|##JvH  
E 
" 
 ] 
 	 

 Y// 
 !"4 
 f 
 D 
 4 
  
 * 
 D 
 U 
 L 
 f 
  D! 
" w# 
$ - 
  
  
. /  	r|  c                    |                                   |                                  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                    }|                     |di           }|                     |dg           }i }t          dt          |                    D ]}	||	         }
|                     |
d          }| 
                    |dd          }|                     |
d	i           }|
||                     |d
          |                     |d          ddd||<   |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  rB  r  )ry  r  r~  r   r  r  r   r   r  r  r  rD  r  
takerMakers                 r{  fetch_trading_feeszascendex.fetch_trading_fees(  sh    	..266''66\
 77GV8T8TUU" ~~h33~~dFB//q#d))$$ 	 	Aq'C''X66H%%hc::FUB77J ))*g>>))*g>>"! F6NN r|  r  rt  r  r&  c                 `   |                      |          }d}d}	|                     d|          \  }}|                     d||          \  }	}|                     | j        di           }
|                     |
|	d          }|d}|                     | j        di           }|                     |d          }|                     |dd          }|||d         |                                 | 	                    ||          ||d	}|d
k    p|dk    }|dk    p|dk    }|                     |d          }| 
                    |d|          }|                     |dd          }|                     |dd          }|r|                     ||          |d<   |dk    rd|d<   |dk    rd|d<   |rd|d<   |(|                     ||          |d<   |rd|d<   n|rd|d<   |||d<   |d         r|||d<   n||d<   |rd|d<   |rd|d<   |                     |ddg          }|                     ||          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  r  r  r  rt  r  stop_marketr  
stop_limitr  Fr  r  r  
orderPricer  r  Tr  r  r@   categoryr   
ReduceOnlyr  Post)r  r"  r!  r  r   r  r$  r  r  amount_to_precisionis_post_onlyr  price_to_precisionr#  r   )ry  r  r  rt  r  r&  r  r  r  r  r   r   r~  r   r  r  isMarketOrderisLimitOrderr  r  r  r  s                         r{  create_order_requestzascendex.create_order_requestX  s    V$$

!??@TV\]]
F!??@TV\^dee
F6FKK**>:vNN!&O..266''66**6?DII) /Tl%%''00@@

 

 (*F0ECdl.B&&v}==$$]E6BB^^FL%@@
))&.+NN 	K$($;$;FE$J$JGL!%%*GM"%%*GM" 	'"&GJ##'#:#:6<#P#PGK  5'3$$ 5'4$$)GDM&> 	-*&5
#*9G&' 3&2
# -&,
#6L.#ABB{{7F+++r|  c                    |                                   |                                  |                     |          }|                     ||||||          }d}	|d         r|                     |          }	n|                     |          }	|                     |	di           }
|                     |
ddi           }|                     ||          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  )ry  r  r  rt  r  r&  r  r  r  r  r   r   s               r{  create_orderzascendex.create_order  s    , 	V$$++FD$vVV&> 	GAA'JJHH==gFFH@ ~~h33  w;;v...r|  ordersc           	          |                                   |                                  g }d}d}t          dt          |                    D ]#}||         }|                     |d          }||}n||k    rt          | j        dz             |                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d	i           }| 	                    d
|          }|d         }|"||}n||k    rt          | j        dz             | 
                    ||	|
|||          }|                    |           %|                     |          }|                     | j        di           }|                     ||d         d          }|d}|                     | j        di           }|                     |d          }i }d}|d         rt          | j        dz             ||d<   ||d<   ||d<   |                     |          }|                     |di           }|                     |dg           }|                     ||          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  rt  r  r&  r  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)ry  r  r  ordersRequestsr  r  r  rawOrderrD  r  rt  r  r&  orderParamsmarginResultcurrentMarginModeorderRequestr  r   r   r~  r   r  r  r   r   s                             r{  create_orderszascendex.create_orders  s    	
q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55D##Hf55D%%h99F$$Xw77E..8R@@K==nkZZL ,Q ,%!2JJ!%666(  4I  *I  J  J  J44XtT6SXZeffL!!,////V$$6FKK**>6&>6RR!&O..266''66&> 
	Ltw)rrsss (4GO$*9G&' .GHBB7KKH. ~~h33~~dFB//  v...r|  r6   c                    |                                   |                                  d}||                     |          }|                     d||          \  }}|                     | j        di           }|                     ||d          }|                     | j        di           }	|                     |	d          }
|
||d}d}|dk    s|d	k    r*|                     | 	                    ||                    }nR|d
k    r/||d<   | 
                    | 	                    ||                    }nt          | j        dz   |z   dz             |                     |di           }|                     ||          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>`
        Nry   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  )ry  r6   r  r  r  r  queryr   r   r~  r   r  r  r   s                 r{  fetch_orderzascendex.fetch_orderZ  s    	[[((F88vvVVe6FKK**>4HH..266''66) /
 

 FNN 0 0BB4;;wX]C^C^__HHV^^*9G&'FFt{{SZ\aGbGbccHHtw)XX[__bllmmmH ~~h33f---r|  c                    |                                   |                                  d}||                     |          }|d         }|                     | j        di           }|                     |d          }|                     d||          \  }}	|                     | j        di           }
|                     |
|d          }||d}d}|d	k    s|d
k    r*|                     | 	                    ||	                    }nR|dk    r/||d<   | 
                    | 	                    ||	                    }nt          | j        dz   |z   dz             |                     |dg           }|dk    r|                     ||||          S g }t          dt!          |                    D ]3}|                     ||         |          }|                    |           4|                     ||||          S )a_  
        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   rv   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)ry  r  r]  r  r  r  r~  r   r  r  r   r   r  r  r   r  r  r   s                     r{  fetch_open_orderszascendex.fetch_open_orders  s    	[[((FH%F..266''66889JFTZ[[e6FKK**>4HH) /
 
 FNN 0 0@@WV[A\A\]]HHV^^*9G&'DDT[[QXZ_E`E`aaHHtw)]]`ddgqqrrrH ~~h33i''$$T65%@@@q#d))$$ 	! 	!A$$T!Wf55EMM%    00NNNr|  c                    |                                   |                                  |                     | j        di           }|                     |d          }i }d}| |                     |          }|d         |d<   |                     d||          \  }	}
|                     | j        di           }|                     |dd          }|                     |	||dd	          }|||d
<   |                     |d          }|||d<   |                     | j        di           }|                     ||	d          }d}|dk    r;||d<   ||d<   |||d<   | 	                    | 
                    ||
                    }n|dk    r6||d<   |||d<   |                     | 
                    ||
                    }n^|dk    r;||d<   ||d<   |||d<   |                     | 
                    ||
                    }nt          | j        dz   |	z   dz             |                     |dg           }t!          |t"                    s|                     |dg           }|                     ||||          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  rU   r   r   /v2PrivateAccountGroupGetFuturesOrderHistCurrent)r@   rA   rB   	startTimer`  endTimer   r   +v1PrivateAccountCategoryGetOrderHistCurrentr   r   r  r~  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  rP  r  r  )ry  r  r]  r  r  r~  r   r  r  r  r  r   defaultMethodr   r`  r   r   r  r   s                      r{  fetch_closed_orderszascendex.fetch_closed_orders4  s    	..266''66

 [[((F &tGH889LfV\]]e../BBGG(((<WXX++D!#E3
 3
  
 #(GK   11!&GI6FKK**>4HHBBB'3GO$*9G&' #( GGT[]bHcHcddHH222!0GI #( 55dkk'56Q6QRRHHHHH'3GO$*9G&' &+
#KKDKKX_afLgLghhHHtw)__bffisstttx ~~h33$%% 	4>>$33D  vue<<<r|  c                    |t          | j        dz             |                                  |                                  |                     |          }|                     d||          \  }}|                     | j        di           }|                     ||d          }|                     | j	        di           }	|                     |	d          }
|
||d         | 
                                dd	}|                     |d
d          }|||d<   n||d<   |                     |d
dg          }d}|dk    s|dk    r*|                     |                     ||                    }nR|dk    r/||d<   |                     |                     ||                    }nt!          | j        dz   |z   dz             |                     |di           }|                     |ddi           }|                     ||          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  )ry  r6   r  r  r  r  r  r   r   r~  r   r  r  r  r   r   s                   r{  cancel_orderzascendex.cancel_order  s!    >#DG.Y$YZZZV$$88PVWWe6FKK**>4HH..266''66) /Tl%%''
 
 **6?DII !#GI)GDMYYv'>??FFNN 0 0??GUZ@[@[\\HHV^^*9G&'CCDKKPWY^D_D_``HHtw)YY\``cmmnnn@ ~~h33  w;;v...r|  c                    |                                   |                                  d}||                     |          }|                     d||          \  }}|                     | j        di           }|                     ||d          }|                     | j        di           }|                     |d          }	|	||                                 d}
||d         |
d<   d}|d	k    s|d
k    r*| 	                    | 
                    |
|                    }nR|dk    r/||
d<   |                     | 
                    |
|                    }nt          | j        dz   |z   dz             |                     d|i          g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  )ry  r  r  r  r  r  r   r   r~  r   r  r  s               r{  cancel_all_orderszascendex.cancel_all_ordersF	  s    	[[((F889JFTZ[[e6FKK**>4HH..266''66) /%%''
 

  &tGHFNN 0 0BB4;;wX]C^C^__HHV^^*9G&'FFt{{SZ\aGbGbccHHtw)]]`ddgqqrrrF H!
    	r|  r  c                 0   |                      |d          }|                      |d          }|                      ||          }|                     |           |d n|d         }|                      |d          }|                     ||          }|||||dS )NaddresstagIdr  
blockchain)r   r  networkr  tag)r  check_addressnetwork_id_to_code)	ry  depositAddressr  r  r  r  r  r  r  s	            r{  parse_deposit_addresszascendex.parse_deposit_address	  s     "">9==  99~u557### (ttx/?$$^\BB	)))T::"
 
 	
r|  r  c                 V   |                                   |                     |          }|                     |dd          }|                     |          }|                     |dg          }|d         |d}|                     |                     ||                    }|                     |di           }|                     |dg           }	t          |	          }
d}|
dk    r| 
                    |	d          }|Pt          |                                          }d	                    |          }t          | j        d
z   |z             |                     ||i           }n|                     |	di           }|                     ||          }|                     |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  rN  r*   r6   r  )ry  r  r  r  r  r  r  r  r   	addressesnumAddressesr  addressesByChainName
chainNamesr  r  s                   r{  fetch_deposit_addresszascendex.fetch_deposit_address	  s    	==&&((KHH++K88	6K=11d^#
 
 88Wf9U9UVVD ~~h33NN4B77	9~~!#'==K#H#H  !"6";";"="=>>
:..'  3V  )V  Y_  )_  `  `  `nn%99bIIGG nnY266G++GX>>{{6H$
   	r|  c           	      b    ddi}|                      ||||                     ||                    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   ry  r  r]  r  r  r  s         r{  fetch_depositszascendex.fetch_deposits	  s;     i
 &&tUE4;;wPV;W;WXXXr|  c           	      b    ddi}|                      ||||                     ||                    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         r{  fetch_withdrawalszascendex.fetch_withdrawals
  s;     l
 &&tUE4;;wPV;W;WXXXr|  c                 p   |                                   i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          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)
ry  r  r]  r  r  r  r  r  r   transactionss
             r{  fetch_deposits_withdrawalsz#ascendex.fetch_deposits_withdrawals
  s     	
 }}T**H'~GG!&GI"'GJ66t{{7F7S7STT4 ~~h33~~dFB77&&|XueLLLr|  c                 >    ddddd}|                      |||          S )Npendingokr  )	reviewingr  	confirmedr  r  r  s      r{  parse_transaction_statusz!ascendex.parse_transaction_statusJ
  s4    " "	
 
 &&999r|  transactionc                 D   |                      |di           }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	t          j        ||	          }|                     ||          }
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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  rx  r  rw  )ry  r  r  r  r  r  r  
currencyIdry  feeCostStringr  s              r{  parse_transactionzascendex.parse_transactionS
  s5   & nn[-DD"";	::{I66%%k6::	%%k7;;
''X>>((lCC),FF&&z8<<
K
$"";<<
 D$$[2HII
 D$$[2CDD	

 
 t
 d''55
 d33D4D4D[RZ4[4[\\
 
 Y//
 w
 4
 
 3
 t
  S!
" t#
$  ))-88 
 1
 
 
 	
r|  c                 f   |                                   |                                  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                    }|                     |di           }|                     |dg           }g }	t          dt          |                    D ]0}
|	
                    |                     ||
                              1|                     |          }|                     |	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)ry  rJ  r  r~  r   r  r  r   positionr  r  s              r{  fetch_positionszascendex.fetch_positions
  s)    	..266''66\
 ??GU[@\@\]]P ~~h33>>$R88q#h--(( 	< 	<AMM$--hqk::;;;;%%g..--fhOOOr|  r0  c                    |                      |d          }|                     ||          }|                      |d          }t          j        |d          r|                      |d          }|                      |d          }|dk    rdnd}d }|dk    r|                      |d	          }|                     i d
|dd d|d         d|                     |          d|dd d|                     |d          d|                     |d          dd d|                     |d          d|                     |d          d|                     |d          dd d|                     |d          dd dd dd d d d |d d |                     |d          d |                     |d          |                     |d          d
          S ) Nr  buyOpenOrderNotional0sellOpenOrderNotional
marginTypecrossedr  r  isolatedMarginr   r6   notionalr  liquidationPrice
entryPriceavgOpenPriceunrealizedPnlr   r  r0  r  	markPrice	lastPricert  r  r  r	  r  r
  r  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior
  r  )	r  ru  r1   	string_eqsafe_positionrx  r  r  r  )ry  r0  r  rD  r9  r6  r  rC  s           r{  r-  zascendex.parse_position
  sv   . ##Hh77!!(F33##H.DEEXs++ 	K''2IJJH%%h==
!+y!8!8WWz

##))(4DEEJ!! #
H#
$#
 fX&#
 ))(33	#

 *#
 #
 $**8^DD#
 T--hHH#
 $#
 ))(J??#
 D,,V^DD#
 ))(K@@#
 #
 D**8V<<#
 d#
  !#
" ##
$ $(!%+/$!'+))(J??!--hHH#//:KLL7#
 #
 #
   	r|  c                    |                      |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 iS )Nr  r  fundingRatenextFundingTimer   r>  
indexPriceinterestRater4  estimatedSettlePricer  r	  previousFundingRatenextFundingRatepreviousFundingTimestampnextFundingTimestamppreviousFundingDatetimenextFundingDatetimefundingTimestampfundingDatetimer_  )r  rB  r  r  rx  rw  )ry  r  r  rD  r  currentTimerP  nextFundingRateTimestamps           r{  parse_funding_ratezascendex.parse_funding_rate  s    ##Hh77!!(F33''&99**8]CC#'#4#4X?P#Q#Q 
H
f
 ))(K@@
 $**8\BB	

 D--c22
 #D
 
 [11
 "4
 t
 '
 #D
 &t
 "4
 ?
   8!
" t||,DEE#
$ %
 
 	
r|  c                    |                                   |                     |          }|                     |          }|                     |di           }|                     |dg           }|                     ||          S )a`  
        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)ry  rJ  r  r  r   r  s         r{  fetch_funding_rateszascendex.fetch_funding_rates-  s~     	%%g..55f==2 ~~h33NN4b99	''	7;;;r|  c                 *   |                                   |                                  |                     |          }|                     | j        di           }|                     |d          }|                     ||          }||d         |d}|                     |                     ||                    }	|dk    rt          j
        |          }|                     |                     |	|          |                     |          |d          S )Nr   r6   )r   r  r  reduce)r  r  )r  r   r  r  r$  r  r  6v2PrivateAccountGroupPostFuturesIsolatedPositionMarginr   r1   
string_absparse_margin_modificationrx  )
ry  r  r  r  r  r  r~  r   r  r  s
             r{  modify_margin_helperzascendex.modify_margin_helperS  s   V$$..266''66))&&99)Tl
 

 NNt{{[bdjOkOkll 8'//F{{499(FKK''//N
 N
   	r|  r   c                 t    |                      |d          }|dk    rdnd}||d         d dd d |d         |d d d
S )	Nr  r4  r  failedr  r  r  )
r   r  r  r  r  r  r  r  r  r	  r  )ry  r   r  	errorCoder  s        r{  rb  z"ascendex.parse_margin_modificationn  sb     $$T622	#s**X&$7O
 
 	
r|  c                 4    |                      || d|          S )aJ  
        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=margin-structure>`
        r_  rc  ry  r  r  r  s       r{  reduce_marginzascendex.reduce_margin  s      ((&(FKKKr|  c                 2    |                      ||d|          S )a0  
        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=margin-structure>`
        addrh  ri  s       r{  
add_marginzascendex.add_margin  s     ((GGGr|  r  c                     |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  |                                  |                     |          }|d         st          | j        dz             |                     | j        di           }| 	                    |d	          }||d	         |d
}| 
                    |                     ||                    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
        Nz) 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   )ry  r  r  r  r  r~  r   r  s           r{  set_leveragezascendex.set_leverage  s    >#DG.Y$YZZZqLLhnnTW'NNOOOV$$f~ 	UDG&SSTTT..266''66)Tl 
 

 <<T[[RX=Y=YZZZr|  r  c                 8   |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  |                                  |                     |          }|                     | j        di           }| 	                    |d          }||d         |d	}|d
         st          | j        dz             |                     |                     ||                    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
        Nz+ setMarginMode() requires a symbol argumentr  r7  r  z@ setMarginMode() marginMode argument should be isolated or crossr   r6   )r   r  r6  rB   z- setMarginMode() supports swap contracts only)r*   r6   r  r+   r  r   r  r  r$  r  r,   *v2PrivateAccountGroupPostFuturesMarginTyper   )ry  r  r  r  r  r~  r   r  s           r{  set_margin_modezascendex.set_margin_mode  s-    >#DG.[$[\\\%%''
  "J##
i(?(?TW'iijjjV$$..266''66)Tl$
 

 f~ 	WDG&UUVVV>>t{{7TZ?[?[\\\r|  c                     |                                   |                     |          }|                     |dg           }|                     |          }|                     ||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)ry  rJ  r  r  r   s        r{  fetch_leverage_tierszascendex.fetch_leverage_tiers  sk     	226::: ~~h33%%g..((wAAAr|  c                 l   |                      |dg           }|                     |d          }|                     ||          }g }t          dt	          |                    D ]}||         }|                     |d          }|                    |                     |d          |                     ||dd          |d         |                     |d	          |                     |d
          |                     |d          | 	                    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  r}  maxLeverager   )r  r  ru  r  r  r  re  rB  r  rx  r1   
string_div)	ry  r   r  ry  rD  tiersr  r~  rz  s	            r{  parse_market_leverage_tiersz$ascendex.parse_market_leverage_tiers  sD   8 "^^D2FKK##D(33!!(F33q#01122 	 	A%a(D $ 0 07J K KLLA**8VT:NN"7O#//6RSS#//6RSS)-)9)9$@W)X)X#001CCIZ1[1[\\	 	 	 	 	 	 r|  c                    |                      |dg           }t          |          }|d d dd d di d}t          d|          D ]}||         }|                     |d          }|                     |d          }	|                     ||	          }
d d d|                     |d          ddd	|d
         |
<   |dk    r*|                     |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  )ry  r  r  blockChainsblockChainsLengthr  r  r  r  currencyCoder  s              r{  parse_deposit_withdraw_feez#ascendex.parse_deposit_withdraw_fee.  s?   ( nnS,;;,," 
 "  
 
 q+,, 	9 	9A$QJ(([AAI++Hf==L11)\JJK#'t<<$($4$4Z$O$O_dee/ /F:{+ !A%%,0,<,<Z,W,Wz"5)38z"<0r|  codesc                     |                                   |                     |          }|                     |d          }|                     ||d          S )ai  
        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)ry  r  r  r  r   s        r{  fetch_deposit_withdraw_feesz$ascendex.fetch_deposit_withdraw_fees^  sT     	))&11~~h////e[IIIr|  fromAccount	toAccountc                    |                                   |                                  |                     | j        di           }|                     |d          }|                     |          }|                     | j        di           }	|                     |	||          }
|                     |	||          }|
dk    r|dk    rt          | j        dz             || 	                    ||          |d         |
|d}| 
                    |                     ||                    }|                     | j        di           }|                     |dd	          }|                     ||          }|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)ry  r  r  r  r  r  r~  r   r  r   fromIdtoIdr  r  transferOptionsr   r   s                    r{  r   zascendex.transferm  s    	..266''66==&&6FKK!!.+{KK	9EEV  +E  !E  F  F  F)00v>>d^!
 
 99$++gv:V:VWW ..z2FF"&..B[]a"b"b&&x::" 	(&1H]#$-H[!!'HX#'HZ r|  r   c                     |                      |d          }|                     d |          }|d d d |d d d |                     |          d	S )Nr  )	r   r6   r  r	  r  r  r  r  r  )r  r  parse_transfer_status)ry  r   r  r  r  s        r{  r  zascendex.parse_transfer  sf     !!(F33..tX>>$0088

 

 
	
r|  c                     |dk    rdS dS )Nr4  r  re   )ry  r  s     r{  r  zascendex.parse_transfer_status  s    S==4xr|  c           	      d   |                                   |                                  d}|                     |dd          \  }}|r|                     d||||dd          S |                     | j        di           }|                     |d          }d|i}d	}	| |                     |          }	|	d         |d
<   |||d<   |                     | 	                    ||                    }
|                     |
di           }| 
                    |dg           }|                     ||	||          S )aC  
        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>`
        Fra   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)ry  r  r]  r  r  r  r~  r   r  r  r  r   rowss                r{  fetch_funding_historyzascendex.fetch_funding_history  sX    	88AVXbcc& 	z889NPVX]_dflntvxyyy..266''66\
 [[((F &tGH"'GJFFt{{SZ\bGcGcdd& ~~h33~~dFB//!!$u===r|  c           
          |                      |d          }|                     |d          }||                     ||dd          d||                     |          d |                     |d          dS )Nr  r  -rB   USDTpaymentInUSDT)r   r  r  r  r	  r6   r  )r  r  rB  rw  r  )ry  incomer  rD  r  s        r{  parse_incomezascendex.parse_income  s     ##FH55%%fk::	&&xfEE"Y//&&v??
 
 	
r|  c                    |                                   |                                  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     ||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)	ry  rJ  r  r~  r   r  r  r   marginModess	            r{  fetch_margin_modeszascendex.fetch_margin_modes  s     	..266''66\
 ??GU[@\@\]]P ~~h33nnT;;;&&{GXFFFr|  c                     |                      |d          }|                      |d          }|dk    rdnd}||                     ||          |dS )Nr  r6  r7  r  r  )r   r  r  )r  rB  )ry  r  r  rD  r6  rA   s         r{  parse_margin_modezascendex.parse_margin_mode4  sg    ##J99%%j,??
'944:&&x88 
 
 	
r|  c                    |                                   |                                  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                    }|                     |di           }|                     |dg           }|                     ||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)	ry  rJ  r  r~  r   r  r  r   	leveragess	            r{  fetch_leverageszascendex.fetch_leverages>  s     	..266''66\
 ??GU[@\@\]]P ~~h33NN4b99	##IwAAAr|  c                 6   |                                   i }d}|                     |                     ||                    }|                     |          }|                     |di           }|                     |dg           }|                     ||          S )a  
        Retrieves the open interest for a list of symbols

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

        :param str[] [symbols]: a list of unified CCXT market symbols
        :param dict [params]: exchange specific parameters
        :returns dict[]: a list of `open interest structures <https://docs.ccxt.com/?id=open-interest-structure>`
        Nr   r  )r  r[  r   r.  r  r  parse_open_interests)ry  rJ  r  r  r  r   r  s          r{  fetch_open_interestszascendex.fetch_open_interests{  s     	55dkk'66R6RSS0 %%g..~~h33NN4b99	((G<<<r|  c                    |                      |d          }|                     |d          }|                     |d          }|                     ||                     ||d d          |d |d ||                     |          d|          S )Nr  r  openInterestrB   )r   r  r@  rA  openInterestAmountopenInterestValuer  r	  )r  r  r  safe_open_interestrB  rw  )ry  r  r  rD  r  r  s         r{  parse_open_interestzascendex.parse_open_interest  s     ##Hh77%%h77	''.AA&&&&xvFF&".!%"Y//	(
 	(
 	 	 		r|  c                     |                      |d          }|                     |d          }|                      |d          }|dk    rdnd}||                     ||          |||dS )Nr  r  r6  r7  r  r  )r   r  r  longLeverageshortLeverage)r  r  rB  )ry  r  r  rD  leverageValuer6  r  s          r{  parse_leveragezascendex.parse_leverage  s    ##Hh77))(J??%%h==
!+y!8!8WWz
&&x88$)*
 
 	
r|  r   GETc                    |d         }|d         }|                      |d          }	d}
|	dk    }|s|	dk    r/|
|                     d|          z  }
|                     |d          }|                     ||          }|
d	z  }
|d
k    r|	dk    rd|z   dz   |z   }n|dz   |z   }n|
|dz   z  }
|r|
|                     d|          z  }
|                     |d          }|
|z  }
|dk    r|dk    s|dk    rd}|dk    r|dk    rd}|                    d          dk    r|                    d          }|d         }|                     ||                     |                    }|dk    r|r|
d|                     |          z   z  }
n|                                  t          | 	                                          }|dz   |z   }| 
                    |                     |          |                     | j                  t          j        d          }| j        ||d}|dk    r|r|
d|                     |          z   z  }
nd|d<   |                     |          }| 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   )ry  pathr   r   r  r  r  r   accessr  r   r   r  r  r  payloadr  s                    r{  signzascendex.sign  s   a&QQ''#44 	8t~554&&'96BBBCYYv77F%%dF33{d??v~~!G+c1G;!C-'17S= C 	F4&&'<fEEEC6#566wtOO'^";";L\A\A\GtOO'Z"7"7G<<	""a''MM#&&EAhG64#6#6t#<#<==X 4sT^^F3333++---D--//00I#o/G99T[[114;;t{3K3KW^]effD"k$-$( G
  83!7!777C*<'yy((iv&,fdwOOOr|  httpCodereasonr   r   r  r  c
                    |d S |                      |d          }
|                      |d          }|
d uo|
dk    }|s|| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nr  messager4   rg  rh  )r  r6   throw_exactly_matched_exceptionr*  throw_broadly_matched_exceptionr&   )ry  r  r  r   r   r  r  r  requestHeadersrequestBodyr  r  errorfeedbacks                 r{  handle_errorszascendex.handle_errors  s    4 &11""8Y77T!4 	*W(w}t+H001I4QYZZZ001I7T\]]]001I7T\]]])))tr|  )N)k__name__
__module____qualname__r   rw  r  r   r  r%   r   r  r  r  r   r  r   r  r   r  r  r  r)  r  r   r1  dictr   rF  rI  r   r   rS  r  r[  rk  r!   r{  r  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   r1  r-  r   rY  r    r]  r   rc  rb  rj  rm  intrq  rt  r   rw  r   r  r  r  r$   r   r  r  r  r  r   r  r   r  r   r  r  r  r   r  r  r  __classcell__)rz  s   @r{  r3   r3      s       U# U U U U U Un "$ 1 1 1 1 ') [ [Z [ [ [ [z $& 	? 	?$v, 	? 	? 	? 	? )+ E EtF| E E E EN -/ m m4< m m m m^ !# ; ;s ; ; ; ;. %' $
 $
4= $
 $
 $
 $
L) ) ) ) ) ) ) )&) ) )  $& Y0 Y0( Y0 Y0 Y0 Y0v :>b * *s *3 *Y * * * *X, ,4 , ,6 , , , ,\ 02 / /3 /f / / / /@ 04B -1 -1W -17 -1 -1 -1 -1^
 
 
4 
 
 
 
4 9=4^bkm BH BH# BH# BHS BHX[ BHrvw{r| BH BH BH BHH     v          D 6:UW $? $?3 $?s $?# $?\`af\g $? $? $? $?L	: 	: 	: 	: 	:k k kv k k k k kZ )+ . .{ . . . .` os{} F, F,3 F,i F,y F,Z_ F,hk F, F, F, F,P gksu `/ `/3 `/i `/y `/RW `/`c `/ `/ `/ `/D @B V/ V/D$6 V/ V/ V/ V/p 26b g. g.c g.3 g. g. g. g.R /3TXac oO oO oO3 oOc oOhlmrhs oO oO oO oOb 154VZce b= b=# b=S b=PS b=jnotju b= b= b= b=H 37r l/ l/s l/C l/ l/ l/ l/\ /32 H H H H H HT
 
h 
R` 
 
 
 
: 79 G G# G^ G G G GR *.Dt\^ Y Y3 Yc Y Ycghsct Y Y Y Y -1tRV_a Y Yc Y YC Yfjkvfw Y Y Y Y 6:[_hj 6M 6Ms 6M# 6MUX 6Most  pA 6M 6M 6M 6Mp:s : : : :5
 5
T 5
X 5
Q\ 5
 5
 5
 5
n 26b <P <Pw <PT(^ <P <P <P <P|= =t =V = = = =~$
 $
6 $
[ $
 $
 $
 $
L 6:" $< $<7 $< $< $< $< $<L FH  3 L^    6
 
d 
F 
N` 
 
 
 
. @B L LC L LFX L L L L =? H H He HCU H H H H 9=R [ [S [# [ [ [ [: >B" ] ]# ]s ] ] ] ]@ 7;2 'B 'BG 'B- 'B 'B 'B 'BR- - -$|J\ - - - -^. . . . . .` <@ J J J J J J [] ' 'S '% 'c 'c 'an ' ' ' 'R
 
t 
x 
= 
 
 
 
$C C    
 37TX\eg 3> 3>C 3>s 3>RU 3> 3> 3> 3>j
 
6 
 
 
 
* 59 ;G ;G' ;G ;G ;G ;G ;Gz
 
D 
* 
 
 
 
 26b ;B ;Bw ;BY ;B ;B ;B ;Bz 7;2 (= (=G (= (= (= (=T F    :
 
t 
V 
x 
 
 
 
 &eBSW 2P 2P 2P 2Phc 3 S # X\ dg        r|  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  r|  r{  <module>r     s   ( ' ' ' ' ' . . . . . .  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t  t       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %|7 |7 |7 |7 |7x |7 |7 |7 |7 |7r|  