
    ei{                    p   d dl mZ d dlmZ d dl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)m0Z0 d dl)m1Z1 d dl)m2Z2 d dl)m3Z3 d dl4m5Z5 d dl6m7Z7  G d dee          Z8d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    Y/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/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                   K   |                      |           d{V }|                     |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
        Nr   r   	assetCode
blockChainnativeScale	chainNamewithdrawFee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  s      //77777777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                    K   |                      |          }|                     |          }t          j        ||g  d{V \  }}|                     ||          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
        N)fetch_spot_marketsfetch_contract_marketsasynciogatherarray_concat)ry  r  spotPromisecontractPromisespotMarketscontractMarketss         r{  fetch_marketszascendex.fetch_marketsV  sl       --f5555f==-4^k?=[-\'\'\'\'\'\'\$_  o>>>r|  c                 b  K   |                      |          }|                     |          }t          j        ||g  d {V \  }}|                     |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  r  r  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_marketsa  sB     226::* 226::<  '~/MNNNNNNN$~~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                   K   |                      |           d {V }|                     |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     99&AAAAAAAA	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                    K   d|                                  i}|                     |                     ||                     d{V }|                     |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
        requestTimeNr   requestReceiveAt)millisecondsv1PublicGetExchangeInfoextendr  r  )ry  r  requestr  r   s        r{  
fetch_timezascendex.fetch_timeW  s       4,,..
 55dkk'66R6RSSSSSSSS ~~h33  '9:::r|  c                    K   |                      | j        d          }d}|R|                     |           d{V }|                     |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_accountsn  s       ''oFF!226::::::::H" >>(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  K   |                                   d{V  |                                  d{V  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    r0|                     |                     |
|                     d{V }nS|dk    r0|                     |                     |
|                     d{V }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  s      !!!!!!!!!  """""""""

!??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&<&<!DDT[[QXZ`EaEabbbbbbbbHH6!!!II$++V]_eJfJfggggggggHHtw)ZZ]ggjttuuuX **84448##,,X666%%h///r|  Nr  r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |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
        Nr  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
 ..t{{7F/K/KLLLLLLLL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  r5  r6  r7  r8  s               r{  parse_tickerzascendex.parse_tickerN  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                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |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>`
        Nr  r6   r   )r!  r  v1PublicGetTickerr  r  rH  )ry  r  r  r  r  r  r   s          r{  fetch_tickerzascendex.fetch_ticker|  s       !!!!!!!!!V$$fTl
 //GV0L0LMMMMMMMM" ~~h33  v...r|  symbolsc                   K   |                                   d{V  i }d}|X|                     |d          }|                     |          }|                     |          }d                    |          |d<   d}|                     d||          \  }}d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    |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#  rJ  r  v2PublicGetFuturesTickerr  
isinstancer  parse_tickers)
ry  rL  r  r  r  r  	marketIdsr  r  r   s
             r{  fetch_tickerszascendex.fetch_tickers  sx      !!!!!!!!!%%gq11F[[((F00I # 3 3GH99.&RXYYf6>>!33DKK4P4PQQQQQQQQHH!::4;;wPV;W;WXXXXXXXXH" ~~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                 n  K   |                                   d{V  |                     |          }|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{V }|                     |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
        Nr6   )r  intervalrr   r  r  until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   defaultLimitrb  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++00Wf1M1MNNNNNNNN* ~~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  rn  r  r
  priceStringamountStringbuyerIsMakerrv  s           r{  parse_tradezascendex.parse_trade)  s     %%eT22	((==''s33~~eT599%0vv5!!$//"Y//X&  " 
  
   	r|  c                 p  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |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>`
        Nr  r6   re  r   )r!  r  v1PublicGetTradesr  r  r  parse_trades)
ry  r  r_  r  r  r  r  r  recordsr   s
             r{  fetch_tradeszascendex.fetch_tradesK  s       !!!!!!!!!V$$fTl
  GCL//GV0L0LMMMMMMMM ..626644  >>>r|  r  c                 B    ddddddd}|                      |||          S )Nr8  closedcanceledrejected)
PendingNewNewPartiallyFilledFilledCanceledRejectedr  ry  r  statusess      r{  parse_order_statuszascendex.parse_order_statusq  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  rv  cumFeer  feeAsset)r  r  	stopPriceexecInst
reduceonlyTr   r   clientOrderIdr
  r  lastTradeTimestampr  r  postOnly
reduceOnlyr  r  r  r@  )filled	remainingr  r  r   )r  r  rD  safe_integer_nr  r  safe_string_nr  safe_string_lowersafe_number_2r  	omit_zero
safe_orderry  )ry  r   r  r  rF  r  r
  r  r&  r  r@  r  r6   r  rawTypeLowerr  rv  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                   K   |                                   d{V  |                                  d{V  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                     d{V }|                     |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
        Nr   r6   r   r   r   r  r  r  r   r   )r   r  r   r   r   r   )r!  r"  r  r&  r  v1PrivateAccountGroupGetSpotFeer  r  r  r  rD  r  )ry  r  r~  r   r  r  r   r   r  r  r  rF  r  
takerMakers                 r{  fetch_trading_feeszascendex.fetch_trading_fees)  s      !!!!!!!!!  """""""""..266''66\
 ==dkk'SY>Z>Z[[[[[[[[" ~~h33~~dFB//q#d))$$ 	 	Aq'C''X66H%%hc::FUB77J ))*g>>))*g>>"! F6NN r|  r  rv  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  rv  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  rv  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_requestY  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                   K   |                                   d{V  |                                  d{V  |                     |          }|                     ||||||          }d}	|d         r|                     |           d{V }	n|                     |           d{V }	|                     |	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  rv  r  r&  r  r  r  r  r   r   s               r{  create_orderzascendex.create_order  s#     , !!!!!!!!!  """""""""V$$++FD$vVV&> 	M!GGPPPPPPPPHH!CCGLLLLLLLLH@ ~~h33  w;;v...r|  ordersc           	      (  K   |                                   d{V  |                                  d{V  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{V }|                     |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  rv  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  rawOrderrF  r  rv  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&> 
	Rtw)rrsss (4GO$*9G&' .GH!HHQQQQQQQQH. ~~h33~~dFB//  v...r|  r6   c                 0  K   |                                   d{V  |                                  d{V  d}||                     |          }|                     d||          \  }}|                     | j        di           }|                     ||d          }|                     | j        di           }	|                     |	d          }
|
||d}d}|dk    s|d	k    r0|                     | 	                    ||                     d{V }nX|d
k    r5||d<   | 
                    | 	                    ||                     d{V }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_order[  s      !!!!!!!!!  """""""""[[((F88vvVVe6FKK**>4HH..266''66) /
 

 FNN 0 0!HHU\^cIdIdeeeeeeeeHHV^^*9G&'!LLT[[Y`bgMhMhiiiiiiiiHHtw)XX[__bllmmmH ~~h33f---r|  c                 $  K   |                                   d{V  |                                  d{V  d}||                     |          }|d         }|                     | j        di           }|                     |d          }|                     d||          \  }}	|                     | j        di           }
|                     |
|d          }||d}d}|d	k    s|d
k    r0|                     | 	                    ||	                     d{V }nX|dk    r5||d<   | 
                    | 	                    ||	                     d{V }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  sg      !!!!!!!!!  """""""""[[((FH%F..266''66889JFTZ[[e6FKK**>4HH) /
 
 FNN 0 0!FFt{{SZ\aGbGbccccccccHHV^^*9G&'!JJ4;;W^`eKfKfggggggggHH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                 .  K   |                                   d{V  |                                  d{V  |                     | 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    rA||d<   ||d<   |||d<   | 	                    | 
                    ||
                     d{V }n|dk    r<||d<   |||d<   |                     | 
                    ||
                     d{V }nd|dk    rA||d<   ||d<   |||d<   |                     | 
                    ||
                     d{V }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>`
        Nr   r6   r  rU   r   r   /v2PrivateAccountGroupGetFuturesOrderHistCurrent)r@   rA   rB   	startTimerb  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  rR  r  r  )ry  r  r_  r  r  r~  r   r  r  r  r  r   defaultMethodr   rb  r   r   r  r   s                      r{  fetch_closed_orderszascendex.fetch_closed_orders5  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&' #( !MMdkkZachNiNijjjjjjjjHH222!0GI #( !;;DKKQV<W<WXXXXXXXXHHHHH'3GO$*9G&' &+
#!QQRVR]R]^eglRmRmnnnnnnnnHHtw)__bffisstttx ~~h33$%% 	4>>$33D  vue<<<r|  c                 6  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     |          }|                     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    r0|                     |                     ||                     d{V }nX|dk    r5||d<   |                     |                     ||                     d{V }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  sn      >#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!EEdkkRY[`FaFabbbbbbbbHHV^^*9G&'!II$++V]_dJeJeffffffffHHtw)YY\``cmmnnn@ ~~h33  w;;v...r|  c                 D  K   |                                   d{V  |                                  d{V  d}||                     |          }|                     d||          \  }}|                     | j        di           }|                     ||d          }|                     | j        di           }|                     |d          }	|	||                                 d}
||d         |
d<   d}|d	k    s|d
k    r0| 	                    | 
                    |
|                     d{V }nX|dk    r5||
d<   |                     | 
                    |
|                     d{V }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_ordersG	  s      !!!!!!!!!  """""""""[[((F889JFTZ[[e6FKK**>4HH..266''66) /%%''
 

  &tGHFNN 0 0!HHU\^cIdIdeeeeeeeeHHV^^*9G&'!LLT[[Y`bgMhMhiiiiiiiiHH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                 r  K   |                                   d{V  |                     |          }|                     |dd          }|                     |          }|                     |dg          }|d         |d}|                     |                     ||                     d{V }|                     |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>`
        Nr  r  r6   )r  r  r   r  r   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  rP  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^#
 
 >>t{{7TZ?[?[\\\\\\\\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           	      r   K   ddi}|                      ||||                     ||                     d{V 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  Nfetch_transactionsr  ry  r  r_  r  r  r  s         r{  fetch_depositszascendex.fetch_deposits	  sQ       i
 ,,T5%WV\A]A]^^^^^^^^^r|  c           	      r   K   ddi}|                      ||||                     ||                     d{V 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  
withdrawalNr  r  s         r{  fetch_withdrawalszascendex.fetch_withdrawals
  sQ       l
 ,,T5%WV\A]A]^^^^^^^^^r|  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|                     |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<<T[[RX=Y=YZZZZZZZZ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_statusK
  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  ry  )ry  r  r  r  r  r  r
  
currencyIdr{  feeCostStringr  s              r{  parse_transactionzascendex.parse_transactionT
  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                   K   |                                   d{V  |                                  d{V  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                     d{V }|                     |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>`
        Nr   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  rL  r  r~  r   r  r  r   positionr  r  s              r{  fetch_positionszascendex.fetch_positions
  sd      !!!!!!!!!  """""""""..266''66\
 EEdkkRY[aFbFbccccccccP ~~h33>>$R88q#h--(( 	< 	<AMM$--hqk::;;;;%%g..--fhOOOr|  r2  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  r2  r  	markPrice	lastPricerv  r  r
  r  r  r
  r  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatior
  r  )	r  rw  r1   	string_eqsafe_positionrx  r  r  r  )ry  r2  r  rF  r;  r8  r  rE  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interestRater6  estimatedSettlePricer
  r  previousFundingRatenextFundingRatepreviousFundingTimestampnextFundingTimestamppreviousFundingDatetimenextFundingDatetimefundingTimestampfundingDatetimera  )r  rD  r  r  rx  ry  )ry  r  r  rF  r  currentTimerR  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                 "  K   |                                   d{V  |                     |          }|                     |           d{V }|                     |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
        Nr   r  )r!  r0  v2PublicGetFuturesPricingDatar  r  parse_funding_rates)ry  rL  r  r  r   r  s         r{  fetch_funding_rateszascendex.fetch_funding_rates.  s       !!!!!!!!!%%g..;;FCCCCCCCC2 ~~h33NN4b99	''	7;;;r|  c                 R  K   |                                   d {V  |                                  d {V  |                     |          }|                     | j        di           }|                     |d          }|                     ||          }||d         |d}|                     |                     ||                     d {V }	|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_helperT  sX     !!!!!!!!!  """""""""V$$..266''66))&&99)Tl
 

 TTUYU`U`ahjpUqUqrrrrrrrr 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  r6  r  failedr  r  r  )
r   r  r  r  r  r  r  r  r
  r  r  )ry  r   r  	errorCoder  s        r{  rd  z"ascendex.parse_margin_modificationo  sb     $$T622	#s**X&$7O
 
 	
r|  c                 D   K   |                      || d|           d{V 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>`
        ra  Nre  ry  r  r  r  s       r{  reduce_marginzascendex.reduce_margin  s6       ..vw&QQQQQQQQQr|  c                 B   K   |                      ||d|           d{V 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>`
        addNrj  rk  s       r{  
add_marginzascendex.add_margin  s4       ..vvufMMMMMMMMMr|  r  c                 (  K   |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  d{V  |                                  d{V  |                     |          }|d         st          | j        dz             |                     | j        di           }| 	                    |d	          }||d	         |d
}| 
                    |                     ||                     d{V 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  sB      >#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 
 

 BB4;;wX^C_C_`````````r|  r  c                 `  K   |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  d{V  |                                  d{V  |                     |          }|                     | j        di           }| 	                    |d          }||d         |d	}|d
         st          | j        dz             |                     |                     ||                     d{V 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  r9  r  z@ setMarginMode() marginMode argument should be isolated or crossr   r6   )r   r  r8  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  sh      >#DG.[$[\\\%%''
  "J##
i(?(?TW'iijjj!!!!!!!!!  """""""""V$$..266''66)Tl$
 

 f~ 	WDG&UUVVVDDT[[QXZ`EaEabbbbbbbbbr|  c                    K   |                                   d{V  |                     |           d{V }|                     |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
        Nr   r  )r!  r  r  r0  parse_leverage_tiers)ry  rL  r  r  r   s        r{  fetch_leverage_tierszascendex.fetch_leverage_tiers  s       !!!!!!!!!88@@@@@@@@: ~~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  rw  r  r  r  rg  rD  r  rx  r1   
string_div)	ry  r   r  r{  rF  tiersr  r  r|  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                    K   |                                   d{V  |                     |           d{V }|                     |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>`
        Nr   r  )r!  r  r  parse_deposit_withdraw_fees)ry  r  r  r  r   s        r{  fetch_deposit_withdraw_feesz$ascendex.fetch_deposit_withdraw_fees_  s|       !!!!!!!!!//77777777~~h////e[IIIr|  fromAccount	toAccountc                 :  K   |                                   d{V  |                                  d{V  |                     | j        di           }|                     |d          }|                     |          }|                     | j        di           }	|                     |	||          }
|                     |	||          }|
dk    r|dk    rt          | j        dz             || 	                    ||          |d         |
|d}| 
                    |                     ||                     d{V }|                     | 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>`
        Nr   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.transfern  s      !!!!!!!!!  """""""""..266''66==&&6FKK!!.+{KK	9EEV  +E  !E  F  F  F)00v>>d^!
 
 ??GU[@\@\]]]]]]]] ..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 )Nr6  r  rg   )ry  r  s     r{  r  zascendex.parse_transfer_status  s    S==4xr|  c           	        K   |                                   d{V  |                                  d{V  d}|                     |dd          \  }}|r!|                     d||||dd           d{V S |                     | j        di           }|                     |d          }d	|i}d}	| |                     |          }	|	d         |d
<   |||d<   |                     | 	                    ||                     d{V }
|                     |
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>`
        NFra   paginatepage   r   r6   r   r  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  s      !!!!!!!!!  """""""""88AVXbcc& 	@>>?TV\^cejlrtz|~..266''66\
 [[((F &tGH"'GJLLT[[Y`bhMiMijjjjjjjj& ~~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  rD  ry  r  )ry  incomer  rF  r
  s        r{  parse_incomezascendex.parse_income  s     ##FH55%%fk::	&&xfEE"Y//&&v??
 
 	
r|  c                   K   |                                   d{V  |                                  d{V  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                     d{V }|                     |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>`
        Nr   r6   r   r   r  r  )	r!  r"  r  r&  r  r(  r  r  parse_margin_modes)	ry  rL  r  r~  r   r  r  r   marginModess	            r{  fetch_margin_modeszascendex.fetch_margin_modes  s      !!!!!!!!!  """""""""..266''66\
 EEdkkRY[aFbFbccccccccP ~~h33nnT;;;&&{GXFFFr|  c                     |                      |d          }|                      |d          }|dk    rdnd}||                     ||          |dS )Nr  r8  r9  r  r  )r   r  r  )r  rD  )ry  r  r  rF  r8  rA   s         r{  parse_margin_modezascendex.parse_margin_mode5  sg    ##J99%%j,??
'944:&&x88 
 
 	
r|  c                   K   |                                   d{V  |                                  d{V  |                     | j        di           }|                     |d          }d|i}|                     |                     ||                     d{V }|                     |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>`
        Nr   r6   r   r   r  r  )	r!  r"  r  r&  r  r(  r  r  parse_leverages)	ry  rL  r  r~  r   r  r  r   	leveragess	            r{  fetch_leverageszascendex.fetch_leverages?  s      !!!!!!!!!  """""""""..266''66\
 EEdkkRY[aFbFbccccccccP ~~h33NN4b99	##IwAAAr|  c                 R  K   |                                   d{V  i }d}|                     |                     ||                     d{V }|                     |          }|                     |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  r0  r  r  parse_open_interests)ry  rL  r  r  r  r   r  s          r{  fetch_open_interestszascendex.fetch_open_interests|  s       !!!!!!!!!;;DKKQW<X<XYYYYYYYY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  rB  rC  openInterestAmountopenInterestValuer
  r  )r  r  r  safe_open_interestrD  ry  )ry  r  r  rF  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  r8  r9  r  r  )r   r  r  longLeverageshortLeverage)r  r  rD  )ry  r  r  rF  leverageValuer8  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  messager6   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   r3  dictr   rH  rK  r   r   rU  r  r]  rm  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   r3  r/  r   r[  r    r_  r   re  rd  rl  ro  intrs  rv  r   ry  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 *, 	? 	?V 	? 	? 	? 	? /1 E ET&\ E E E EN 35 m mf m m m m^ ') ; ;S ; ; ; ;. +- $
 $
g $
 $
 $
 $
L) ) ) ) ) ) ) )&) ) )  *, Y0 Y0 Y0 Y0 Y0 Y0v @DB * *S * *S\ * * * *X, ,4 , ,6 , , , ,\ 68 / / /F / / / /@ 6:" -1 -17 -1 -1 -1 -1 -1^
 
 
4 
 
 
 
4 ?CQUdhqs BH BH BH BH3 BH^a BHx|  ~B  yC BH BH BH BHH     v          D <@d[] $? $? $?S $? $?bfglbm $? $? $? $?L	: 	: 	: 	: 	:k k kv k k k k kZ /1 . .[ . . . .` os{} F, F,3 F,i F,y F,Z_ F,hk F, F, F, F,P mqy{ `/ `/ `/I `/Y `/X] `/fi `/ `/ `/ `/D FH V/ V/$|*< V/ V/ V/ V/p 8<B g. g.C g. g. g. g. g.R 59tZ^gi oO oOc oO oOTW oOnrsxny oO oO oO oOb 7;\`ik b= b= b=3 b=VY b=ptuzp{ b= b= b= b=H 9=R l/ l/S l/# l/ l/ l/ l/\ 59 H Hc H H H HT
 
h 
R` 
 
 
 
: =? G G G> G G G GR 04$UYbd _ _ _C _s _imnyiz _ _ _ _ 37TX\eg _ _C _s _RU _lpq|l} _ _ _ _ <@daenp 6M 6MS 6M 6M[^ 6Muy  {F  vG 6M 6M 6M 6Mp:s : : : :5
 5
T 5
X 5
Q\ 5
 5
 5
 5
n 8<B <P <PW <P4PX> <P <P <P <P|= =t =V = = = =~$
 $
6 $
[ $
 $
 $
 $
L <@ $< $< $<| $< $< $< $<L LN   Rd    6
 
d 
F 
N` 
 
 
 
. FH R R# Ru RL^ R R R R CE N Ns NE NI[ N N N N ?C2 a a3 a a a a a: DHPR c c cS c c c c@ =A 'B 'B' 'BP] 'B 'B 'B 'BR- - -$|J\ - - - -^. . . . . .` BFb J Jw J J J J ac ' '3 ' 'C 'TW 'gt ' ' ' 'R
 
t 
x 
= 
 
 
 
$C C    
 9=4^bkm 3> 3># 3>S 3>X[ 3> 3> 3> 3>j
 
6 
 
 
 
* ;?r ;G ;G ;Gk ;G ;G ;G ;Gz
 
D 
* 
 
 
 
 8<B ;B ;BW ;B9 ;B ;B ;B ;Bz =A (= (=' (= (= (= (=T F    :
 
t 
V 
x 
 
 
 
 &eBSW 2P 2P 2P 2Phc 3 S # X\ dg        r|  r3   )9 ccxt.async_support.base.exchanger   ccxt.abstract.ascendexr   r  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   6 5 5 5 5 5 . . . . . .   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|  