
    E#il                    `   S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%  S SK&J'r'  S SK(J)r)  S SK(J*r*  S SK(J+r+  S S	K(J,r,  S S
K(J-r-  S SK(J.r.  S SK(J/r/  S SK(J0r0  S SK(J1r1  S SK(J2r2  S SK3J4r4  S SK5J6r6   " S S\\5      r7g)    )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                     ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S\4S jjr0 4S\	\
   4S jjr0 4S\	\
   4S jjr0 4S\	\
   4S jjr0 4S\4S	 jjr0 4S\	\   4S
 jjrS\4S jrS rS r0 4S\4S jjrS0 4S\S\S\4S jjrShS\S\
S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjr ShS\
S\!4S jjr"SSS0 4S\S\S\S\S\	\!   4
S jjr#ShS\S\
S\$4S jjr%SS0 4S\S\S\S\	\$   4S  jjr&S!\'4S" jr(ShS#\S\
S\)4S$ jjr*0 4S\+4S% jjr,S0 4S\S&\-S'\.S(\/S)\04
S* jjr1S0 4S\S&\-S'\.S(\/S)\04
S+ jjr20 4S,\	\3   4S- jjr4S0 4S.\S\'4S/ jjr5SSS0 4S\'S\S\S\	\)   4S0 jjr6SSS0 4S\'S\S\S\	\)   4S1 jjr7S0 4S.\S\'4S2 jjr8S0 4S\'4S3 jjr9ShS4\:S\;4S5 jjr<0 4S6\S\;4S7 jjr=SSS0 4S6\'S\S\S\	\>   4S8 jjr?SSS0 4S6\'S\S\S\	\>   4S9 jjr@SSS0 4S6\'S\S\S\	\>   4S: jjrAS!\'4S; jrBShS<\S4\:S\>4S= jjrCS0 4S\S\	\D   4S> jjrEShS?\S\
4S@ jjrFShS\
S\G4SA jjrHS0 4S\S\I4SB jjrJ0 4S\S\K4SC jjrLShSD\S\
S\K4SE jjrM0 4S\S(\/S\K4SF jjrN0 4S\S(\/S\K4SG jjrOS0 4SH\PS\'4SI jjrQS0 4SJ\S\'4SK jjrRS0 4S\S\S4SL jjrTShS\
S\	\U   4SM jjrVShS4\:4SN jjrWS0 4SO\4SP jjrX0 4S6\S(\/SQ\SR\S\Y4
SS jjrZShST\S4\:S\Y4SU jjr[S!\'S\'4SV jr\SSS0 4S\'S\S\4SW jjr]ShS\
4SX jjr^S0 4S\S\_4SY jjr`ShSJ\S\a4SZ jjrbS0 4S\S\c4S[ jjrdShSH\S\
S\e4S\ jjrfS]S^0 SS4S_ jrgS`\PSa\Sb\Sc\Sd\Se\4Sf jrhSgriU =rj$ )iascendex   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_S0 SS _SS_SS_SS_SS
_SS
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS
_S S_S!S_S"S_S#S_S$S
_S%S
_S&S_S'S_S(S)_S*S_S+S_S,S)_S-S
_S.S_S/S
_S0S
_E0 S1S)_S2S_S3S_S4S)_S5S_S6S)_S7S_S8S
_S9S
_S:S_S;S
_S<S
_S=S_S>S
_S?S
_S@S_SAS_E0 SBS
_SCS
_SDS
_SES_SFS
_SGS
_SHS
_SIS_SJS_SKS_SLS_SMS
_SNS_SOS
_SPS
_SQS)_SRS
_ES
S
S
SSSSSS
SSS.
E_STSUSVSWSXSYSZS[S\S]S^S_S`Sa._SbSc_SdSeSfSg0SfSh0SgSi/SjSkSlSm.Sn._SoSp0 SqSr_SsSr_StSr_SuSr_SvSr_SwSr_SxSr_SySr_SzSr_S{Sr_S|Sr_S}Sr_S~Sr_SSr_SSr_SSr_SSr_SSr0E0SrSrSrSrSrS.SrSrSrSrSrS.SrSrS.SrSrSrS.S.SrSrSrSrSrSrSrSrSrS.	SrSrSrS.S.S.S.SpSrSrSrSrSrSrS.0SpSSr00SSr0SrSrSrSrSrSrSrS.SrSrSrSrSrSrSrSrSrSrS.
SrSrSrS.S.S.S.S._SSSpSSU R	                  S5      U R	                  S5      S.0_S[
        _SSS SS0SSSSS.SS0SSSSSSSSSSSSSSS.S._SSSSS S
S
S
S SSSS
S.S
S
S
S
S
S
S
S.SS0S S
S
S
SS
S.S
S S
S
SS
S.S S SS0S.	SS
SSSrSS
S
S
S.S.SSSS
S
S.S
S.0S
SS S S S
S
S
S.S.SS0S S.S S S.S._S0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _E0 S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _S[        _E[        [        [        [        [        [        [        [        [        S.	E0 S._SGS GSGSGSGSGSGS._5      $ (  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fetchClosedOrdersfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMySettlementHistory
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionModefetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfer)
fetchTransfersfetchVolatilityHistoryfetchWithdrawalfetchWithdrawalsreduceMarginsandboxsetLeveragesetMarginModesetPositionModetransfer
timeframes151530601202403607201d1w1m)r   5m15m30m1h2h4h6h12hr   r   1Mversionv2urlszOhttps://github.com/user-attachments/assets/55bab6b9-d4ca-42a8-a0e6-fac81ae557f1restzhttps://ascendex.comz%https://api-test.ascendex-sandbox.comzKhttps://ascendex.github.io/ascendex-pro-api/#ascendex-pro-api-documentationz8https://ascendex.com/en/feerate/transactionfee-traderatez7https://ascendex.com/en-us/register?inviteCode=EL6BXBQMg      ?)urldiscount)logoapitestwwwdocfeesreferralr   getassets   productstickerzbarhist/infobarhistdepthtradeszcash/assetszcash/productszmargin/assetszmargin/productsfutures/collateralzfutures/contractszfutures/ref-pxzfutures/market-datazfutures/funding-ratesrisk-limit-infozexchange-info)infozwallet/transactionszwallet/deposit/addresszdata/balance/snapshotzdata/balance/history)balancez
order/openzorder/statuszorder/hist/currentrisk)orderorder/batch)r   z	order/allr   )r   postdelete)	cash/balancemargin/balancezmargin/riskzfutures/collateral-balancefutures/positionzfutures/riskfutures/funding-payments
order/histspot/fee)r   futures/transfer/depositfutures/transfer/withdraw)r   r   )r   accountCategoryaccountGroup)publicprivate)r   zfutures/contractr   zfutures/pricing-datazfutures/tickerr   r   zaccount/info)r   r   zfutures/free-marginzfutures/order/hist/currentr   futures/order/openzfutures/order/status)
z futures/isolated-position-marginzfutures/margin-typezfutures/leverager   r   futures/orderfutures/order/batchr   zsubuser/subuser-transferzsubuser/subuser-transfer-hist)r   r   zfutures/order/all)datar   r   )v1r   r   tradingz0.002)feeSide	tierBased
percentagetakermakerprecisionModeoptionscashmethodv2PrivateDataGetOrderHistfutures)rA   rC   rB   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-grouprS   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   rI   rJ   fetchMyTradesrr   ro   rt   rS   rl   default  i )r   r  daysBackdaysBackCanceled	untilDaysr  r  r  )extendsrS   r  )lastmarkindex)r  price)r  rI   rS   r  forDerivatives)linearinverse)r  rA   r   rC   rD   
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)rc  BONDBTCBEARBTCBULLBYNPLN)deep_extendsuperr3   describeparse_numberr0   r+   r'   r,   r-   r.   r&   r(   r)   )self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/ascendex.pyrp  ascendex.describe   s:   h > @ LC
*LC
JLC
 $LC
 LC
 LC
 4LC
  OOO $O 	O
 %O %O TO "4O tO tO O &tO (O 'O (O  "4!O"  #O$ !%%O& 'O( $T)O* "4+O, &t-O. (/O0 1%1O2  3O4 +D5O6 *:7O8 +D9O: &t;O< #J=O> *5?O@ $TAOB uCOD "5EOF  GOH !$IOJ %dKOL ":MON #DOOP +JQOR SOT !%UOV +EWOX dYOZ $U[O\ +E]O^ "4_O` uaOb #EcOd deOf !$gOh uiOj  kOl $UmOn !$oOp %eqOr )%sOt )%uOv twOx yOz T{O| t}O~ "5O@ #DAOB &uCOD 'EOF $ZGOH  IOJ #(*/#($( $#!%#( ]OLC
t uLC
P tQLC
R i2 C .a ST $SLC
v    $a &  %a  +A	 
 &q  $Q  %a  *1  ,Q  ,Q  .q  1!  0  -a  21   4Q! " .q# $ ,Q% 0 %&34675645  ,-./0167()$ *+/0%
 *+-./0',( 1223/0>?4501<=./,-
$ -.<==>%)5, /DN &'012345.//0 	 " ,a$! +A 
 /04578>?<=6789$ EF7845<==>127867<=AB% 237856'-)% 1MxwLC
h $!%"&!..w7!..w7iLC
z Y{LC
| $*!%9&  &"%&# .t .%#/"$$""$(%," }LC
~ #&*(,,0,1).+06:#'#'"&#(	( #($)$)27+0/4#()$. r% &*&+#($)&**/# ',!%#($)&**/( $()-#[0d  )&+!%$*,-%+#($)*/	*  ) 5(,(-).1
 &+7
$ ',!%$(,0%)#($)*/	*#4 "#3  $	 ##{aLC
B ?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CLC
H  !!!!ILC
 L L	    c                     U R                  USU R                  S   5      nUR                  5       nU R                  U5      $ )Naccount)
safe_valuer   lower
capitalize)rr  paramsrx  lowercaseAccounts       rt  get_accountascendex.get_account  s9    //&)T\\)5LM"==?/00rv  c                 P   U R                  U5      nU R                  US/ 5      n0 n[        S[        U5      5       GHe  nX5   nU R	                  US5      nU R                  U5      nU R                  US/ 5      n	U R                  U R                  U R	                  US5      5      5      n
0 n[        S[        U	5      5       H  nX   nU R	                  US5      nU R                  U5      nU R                  US5      SU R                  US	5      U R                  US
5      U
SSS.U R                  US5      SS.U R                  US5      SS.S.S.X'   M     U R                  UUUSSU R	                  US5      SSSSU
SSS.U R                  US5      SS.S.US.5      XH'   GMh     U$ )z
fetches all available currencies on an exchange
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r   r   	assetCode
blockChainnativeScale	chainNamewithdrawFeeNallowWithdrawallowDepositminr  minWithdrawalminDepositAmt)amountwithdrawdeposit)feeactiver  r  	precisionlimits	assetNameminWithdrawalAmt)r  r  )r7   coder   typerB   r8   r  r  r  r  r  r  r   )v2PublicGetAssets	safe_listrangelensafe_stringsafe_currency_coderq  parse_precisionnetwork_code_to_idsafe_number	safe_boolsafe_currency_structure)rr  r|  responser   resulticurrencyr7   r  chainsr  r   jnetworkEtnry	networkIdnetworkCodes                   rt  fetch_currenciesascendex.fetch_currencies  s    ))&14 ~~h3q#d)$AwH!!(K8B**2.D^^HlB?F))$*>*>t?O?OPXZg?h*ijIH1c&k*%y ,,\;G	"55i@++L-H" $|_ M#~~lNK!* $(#'#
 $(#3#3L/#R#'%
 $(#3#3L/#R#'$)%	 +4  77 ((;? &  $#
  $//:LM#!	 %-9 FLC %r rv  c                 r    U R                  U5      nU R                  U5      nX#/u  pEU R                  XE5      $ )z
retrieves data on all markets for ascendex
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
)fetch_spot_marketsfetch_contract_marketsarray_concat)rr  r|  spotPromisecontractPromisespotMarketscontractMarketss         rt  fetch_marketsascendex.fetch_marketsM  s@     --f555f=(3'E$  >>rv  c                 6   U R                  U5      nU R                  U5      nX#/u  pEU R                  US/ 5      nU R                  US5      nU R                  US/ 5      nU R                  US5      n	U R	                  Xy5      n
[        U
R                  5       5      n/ n[        S[        U5      5       GH  nX   nUR                  S5      S:  a  M  X   nU R                  US5      nU R                  US5      nSnUS:X  d  US	:X  a  US
:w  a  SnU R                  US5      nU R                  US5      nU R                  US5      nS nU R                  USS5      nUR                  S5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  US5      nU R                  USS5      nUR!                  0 SU_SUS-   U-   _SU_SU_SU_SU_SS _SS _SS_SS_SU_SS_SS_S S_S!U_S"S_S#S _S UUS S S S S U R                  US$5      U R                  US5      S%.S S S&.UUS&.UUS&.U R                  US'5      U R                  US(5      S&.S).U R#                  US*5      US+.E5        GM     U$ ),Nr   symbolr   z-PERPstatusdomainFNormalInternalTradingLeveragedETFTminQtymaxQtytickSize
underlying/r   commissionReserveRatemarginTradabler7   basebaseIdquotequoteIdsettlesettleIdr  rA   rB   rC   rD   rE   r  contractr!  lotSizer  r  r  minNotionalmaxNotionalr	  r  r  costtradingStartTimer"  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr   )v1PublicGetProductsv1PublicGetCashProductsr  index_byrn  listkeysr  r  findr  r  safe_string_2splitr  r  appendsafe_integer)rr  r|  productsPromisecashPromiser   r   productsDataproductsByIdcashDatacashAndPerpetualsByIddataByIdidsr  r  r7   marketr  r  r  r  r  minPricemaxPricer  partsr  r  r  r  r  r  s                                  rt  r  ascendex.fetch_spot_marketsX  sx   226:* 226:< *7~~h;}}\8<>>$3 $h A##LH8==?#q#c(#ABwww1$\F%%fh7F%%fh7FF8#3D)DFVdLd%%fh7F%%fh7F''
;H H++FL(KJ$$S)E%%eQ/F&&ua0G**62D++G4E""6+BCC!^^F4DeLNMM 2b2$*u,2 2 &	2
 2 72 $2 D2 2 2 .2 2 %2 %2 &2  E!2" $#2$   $"&""..vyA!--fjA  $#!
  &%
  ('
  $//F#//F$  ,,V5GHc2 2- $R rv  c                    U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH  nX5   nU R	                  US5      nU R	                  US5      nUR                  S5      n	U R	                  U	S5      n
U R                  U
5      nU R	                  U	S5      nU R                  U5      nU R	                  US5      nU R                  U5      nX:H  nX:H  nUS-   U-   S-   U-   nU R                  US	5      nU R                  US
5      nU R                  US5      nUR                  0 SU_SU_SU_SU_SU_SU
_SU_SU_SS_SS_SS _SS_SS_SS_SU R	                  US5      S:H  _SS_SU_UUUU R                  S 5      S S S S U R                  US!5      U R                  US"5      S#.S S S$.U R                  US%5      U R                  US&5      S$.U R                  US'5      U R                  US(5      S$.U R                  US)5      U R                  US*5      S$.S+.U R                  US,5      US-.E5        GM     U$ ).Nr   r   r  r  r  r   settlementAsset:priceFilterlotSizeFilterr  r7   r  r  r  r  r  r  r  rC   rA   FrB   TrD   rE   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  rq  r  )rr  r|  	contractsr   r  r  r  r7   r  r  r  r  r  r  r  r  r!  r"  r  r  r  r  s                         rt  r  ascendex.fetch_contract_markets  s   33F;	L ~~i4q#d)$AWF!!&(3B))&,?J$$S)E%%eQ/F**62D&&ua0G++G4E''0ABH,,X6F_FnGCZ%'#-6F..?K NN6?CM""6+BCCMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 $2 2 %2 %2 $**68<H2  D!2" &#2$ # $ 1 1# 6"&""..}iH!--k:F  $#!
  $//xH#//xH
  $//ZH#//ZH
  $//F#//F$  ,,V5GHc2 2# %H rv  c                     SU R                  5       0nU R                  U R                  X!5      5      nU R                  US0 5      nU R	                  US5      $ )z
fetches the current integer timestamp in milliseconds from the ascendex server
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the ascendex server
requestTimer   requestReceiveAt)millisecondsv1PublicGetExchangeInfoextendr  r  )rr  r|  requestr  r   s        rt  
fetch_timeascendex.fetch_timeN  s\     4,,.
 //G0LM ~~h3  '9::rv  c                     U R                  U R                  S5      nSnUcD  U R                  U5      nU R                  US0 5      nU R                  US5      nX R                  S'   USSUS./$ )z
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   )r7   r  r  r   )r  r   v1PrivateGetInfor  )rr  r|  r   r  r   s        rt  fetch_accountsascendex.fetch_accountse  s     ''oF,,V4H" >>(FB7D++D.AL,8LL) # 	
 	
rv  c                 T   US S S.nU R                  US/ 5      n[        S[        U5      5       Hf  nX4   nU R                  U R	                  US5      5      nU R                  5       nU R	                  US5      US'   U R	                  US5      US'   XrU'   Mh     U R                  U5      $ )	Nr   	timestampdatetimer   r   assetavailableBalancefreetotalBalancetotal)r  r  r  r  r  rx  safe_balance)rr  r  r  balancesr  r   r  rx  s           rt  parse_balanceascendex.parse_balance  s    

 >>(FB7q#h-(AkG**4+;+;GW+MNDllnG"..w8JKGFO#//HGG"4L )   ((rv  c                    US S S.nU R                  US/ 5      n[        S[        U5      5       H  nX4   nU R                  U R	                  US5      5      nU R                  5       nU R	                  US5      US'   U R	                  US5      US'   U R	                  US	5      nU R	                  US
5      n	[        R                  " X5      US'   XrU'   M     U R                  U5      $ )Nr  r   r   r  r  r  r  r  borrowedinterestdebt)	r  r  r  r  r  rx  r1   
string_addr  )
rr  r  r  r  r  r   r  rx  r  r  s
             rt  parse_margin_balanceascendex.parse_margin_balance  s    

 >>(FB7q#h-(AkG**4+;+;GW+MNDllnG"..w8JKGFO#//HGG##GZ8D''<H%00@GFO"4L )   ((rv  c                 P   US S S.nU R                  US0 5      nU R                  US/ 5      n[        S[        U5      5       HQ  nXE   nU R	                  U R                  US5      5      nU R                  5       nU R                  US5      US'   XU'   MS     U R                  U5      $ )Nr  r   collateralsr   r  r   r  )r  r  r  r  r  r  rx  r  )	rr  r  r  r   r  r  r   r  rx  s	            rt  parse_swap_balanceascendex.parse_swap_balance  s    

 ~~h3nnT="=q#k*+A!nG**4+;+;GW+MNDllnG#//CGG"4L ,   ((rv  c                    U R                  5         U R                  5         SnSnU R                  SSU5      u  p!U R                  SU5      u  p1U R	                  USS5      nUS:H  nU(       d  U(       a  SOUnU R                  US5      nU R                  U R                  S0 5      nU R                  XbS5      nU R                  U R                  S0 5      nU R                  US	5      n	S
U	0n
US:X  a  US:w  a  [        U R                  S-   5      eUS:X  d  US:X  a  XzS'   SnUS:X  d  US:X  a!  U R                  U R                  X5      5      nOEUS:X  a!  U R                  U R                  X5      5      nO[        U R                  S-   U-   S-   5      eUS:X  a  U R!                  U5      $ US:X  a  U R#                  U5      $ U R%                  U5      $ )av  
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>`
NrR   rB   Fcrossr   r   r   r7   r   isolatedrC   z+ does not supported isolated margin tradingr   rA   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+   r7   "v1PrivateAccountCategoryGetBalancer  'v2PrivateAccountGroupGetFuturesPositionr/   r  r  r  )rr  r|  r  r   isMarginisCrossr   r   rx  r   r   r  s               rt  fetch_balanceascendex.fetch_balance  s    	

!??PTV\]
!??PVW
>>&(E:'"*gXJ
68,6FK**>vN..26''6\
 *$:+?TWW'TTUUv%?h+F*9&'& jH&<>>t{{7?[\H6!CCDKKPWD`aHtww)ZZ]ggjttuuX **8448#,,X66%%h//rv  Nr  r  c                 T   U R                  5         U R                  U5      nSUS   0nU R                  U R                  XS5      5      nU R	                  US0 5      nU R	                  US0 5      nU R                  US5      n	U R                  XU	5      n
U R                  US5      U
S'   U
$ )a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
r  r7   r   tsseqnumnonce)r#  r  v1PublicGetDepthr  r  r  parse_order_book)rr  r  r  r|  r  r   r  r   	orderbookr	  r  s              rt  fetch_order_bookascendex.fetch_order_book  s     	V$fTl
 ((W)EF0 ~~h3NN44	%%i6	&&y)D++Ix@wrv  r   r  c                    S nU R                  US5      nU R                  US5      nUS:X  a  SOS nU R                  XBU5      nU R                  US5      nU R                  US/ 5      n	U R                  US/ 5      n
U R                  US5      nU R                  0 SU_S	U_S
S _SU R                  US5      _SU R                  US5      _SU R                  U	S5      _SU R                  U	S5      _SU R                  U
S5      _SU R                  U
S5      _SS _SU_SU_SU_SS _SS _SS _SS _U R                  US5      S US.EU5      $ )Nr  r  rA   r  closebidaskopenr	  r
  highlowr   	bidVolumer   	askVolumevwapr  previousClosechanger   averagevolume)
baseVolumequoteVolumer   )r  safe_symbolr  safe_ticker)rr  r   r  r	  marketIdr  	delimiterr  r9  r:  r;  r<  s               rt  parse_tickerascendex.parse_tickerE  s    	##FH5/ FNC	!!(I>  1nnVUB/nnVUB// !
f!
!
 !
 D$$VV4	!

 4##FE2!
 4##C+!
 ))#q1!
 4##C+!
 ))#q1!
 D!
 D!
 U!
 E!
 T!
 d!
  $!!
" t#!
$ **68<)!
* + 	rv  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )ah  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
r  r7   r   )r#  r  v1PublicGetTickerr  r  rL  )rr  r  r|  r  r   r  r   s          rt  fetch_tickerascendex.fetch_tickers  sn     	V$fTl
 ))$++g*FG" ~~h3  ..rv  symbolsc                    U R                  5         0 nSnUbH  U R                  US5      nU R                  U5      nU R                  U5      nSR	                  U5      US'   SnU R                  SXB5      u  prSnUS:X  a!  U R                  U R                  X25      5      nO U R                  U R                  X25      5      nU R                  US/ 5      n	[        U	[        5      (       d  U R                  U	/U5      $ U R                  X5      $ )a  
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|   rA   r   )r#  r  r  
market_idsjoinr%  rO  r  v2PublicGetFuturesTickerr  
isinstancer  parse_tickers)
rr  rR  r|  r   r  r  	marketIdsr  r  r   s
             rt  fetch_tickersascendex.fetch_tickers  s     	%%gq1F[[(F0I # 3GH99.&Y6>--dkk'.JKH44T[[5QRH" ~~h3$%%%%tfg66!!$00rv  c           	          U R                  US0 5      nU R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r0  ohlcv)r  r  r  )rr  ohlcvr  r   s       rt  parse_ohlcvascendex.parse_ohlcv  s      ~~eVR0dD)T3'T3'T3'T3'T3'
 	
rv  r   	timeframesincec                    U R                  5         U R                  U5      nUS   U R                  U R                  X"5      S.nU R	                  U5      nU R                  U R                  S0 5      n	U R                  U	SS5      n
U R                  US5      nUbG  X7S'   Uc  U
nO[        XJ5      nU R                  X4U-  S-  S	5      nUb  [        XS	-   5      US
'   O6XS
'   O1Ub'  US	-   US
'   Uc  U
nO[        XJ5      nXU-  S-  -
  US'   OUb  XGS'   U R                  US5      nU R                  U R                  Xu5      5      nU R                  US/ 5      nU R                  XX#U5      $ )aZ  
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
r7   )r  intervalrl   r  r  untilfromr  r   tonr   )r#  r  r  r   parse_timeframer  r   r  r  sumr'  v1PublicGetBarhistr  r  parse_ohlcvs)rr  r  rf  rg  r  r|  r  r   durationr   defaultLimitrj  toWithLimitr  r   s                  rt  fetch_ohlcvascendex.fetch_ohlcv  s    	V$Tl(()O
 ''	2..|R@(('3?!!&'2#FO}$E0((5(*:T*A1EK  #K ; +!AIGDM}$E0#x'7$'>?GFO CL67+**4;;w+GH* ~~h3  yGGrv  tradec                 4   U R                  US5      nU R                  USS5      nU R                  US5      nU R                  USS5      nU(       a  SOSnU R	                  S U5      nU R                  UUU R                  U5      US	   S S S S UUUS S S
.U5      $ )Nr0  r  pqbmFsellbuyr  )r   r	  r
  r  r7   r   r  takerOrMakersider  r  r  r  )r  r  r  r  safe_market
safe_tradeiso8601)rr  rw  r  r	  priceStringamountStringbuyerIsMakerr  s           rt  parse_tradeascendex.parse_trade   s     %%eT2	((=''s3~~eT59%v5!!$/"Y/X&  " 
  	rv  c                    U R                  5         U R                  U5      nSUS   0nUb  X6S'   U R                  U R                  Xd5      5      nU R	                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $ )a  
get the list of most recent trades for a particular symbol

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

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r  r7   rm  r   )r#  r  v1PublicGetTradesr  r  r  parse_trades)
rr  r  rg  r  r|  r  r   r  recordsr   s
             rt  fetch_tradesascendex.fetch_tradesB  s     	V$fTl
  CL))$++g*FG ..6264  >>rv  r  c                 8    SSSSSSS.nU R                  X!U5      $ )Nr<  closedcanceledrejected)
PendingNewNewPartiallyFilledFilledCanceledRejectedr  rr  r  statusess      rt  parse_order_statusascendex.parse_order_statush  s0     %""
 &99rv  r   c           	          U R                  U R                  US5      5      nU R                  US5      nU R                  XBS5      nU R                  U/ SQ5      nU R	                  US5      nUc  UnU R                  US5      nU R                  US5      n	U R                  USS	5      n
U R                  U/ S
Q5      nU R                  US5      nU R                  US5      nUb  [        U5      S:  a  S nU R                  US5      nUnUb  US:X  a  SnUS:X  a  SnU R                  US5      nU R                  USS5      nS nUb(  U R                  US5      nU R                  U5      nUUS.nU R                  U R                  US5      5      nS nU R                  US5      nUS:X  a  SnS nUS:X  a  SnU R                  0 SU_SU_SU_SU_S U R                  U5      _S!U_SU_S"U_S#S _S$U_S%U_SU_SU_S&U_S'U	_S(S _S)U
_US UUS S*.EU5      $ )+Nr  r  r  )r	  sendingTimetimelastExecTimer  orderQtyavgPxavgFilledPx)cumFilledQtycumQtyfillQtyorderIdr7   r   	orderType	stoplimitr  
stopmarketr  r  cumFeer  feeAsset)r  r  	stopPriceexecInst
reduceonlyTr   r   clientOrderIdr	  r
  lastTradeTimestampr  r  postOnly
reduceOnlyr   r  r  rD  )filled	remainingr  r  r   )r  r  rH  safe_integer_nr  r  safe_string_nr  safe_string_lowersafe_number_2r  	omit_zero
safe_orderr  )rr  r   r  r  rJ  r  r	  r  r  r  rD  r  r7   r  rawTypeLowerr  r  feeCostr  feeCurrencyIdfeeCurrencyCoder   r  r  r  s                            rt  parse_orderascendex.parse_orders  s   V (()9)9%)JK##E84!!(C8''/ST	!..unE*I  0!!%4$$UG]C##E+PQeY/((5$=!A% $--e[A#{*|+%%eV4$$UHe< ,,UJ?M"55mDO+C ~~d&6&6uk&JK
))%<|#JvH  
E 
" 
 ] 
 	 

 Y/ 
 !"4 
 f 
 D 
 4 
  
 * 
 D 
 U 
 L 
 f 
  D! 
" w# 
$ - 
. / 	rv  c                 B   U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      nSU0nU R                  U R                  XA5      5      nU R                  US0 5      nU R                  US/ 5      n0 n[        S[        U5      5       Hj  n	Xy   n
U R	                  U
S5      nU R                  USS5      nU R                  U
S	0 5      nU
UU R                  US
5      U R                  US5      SSS.X'   Ml     U$ )z
fetch the trading fees for multiple markets
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
r   r7   r   r   r   r  Nr  r  r   r   )r   r  r   r   r   r   )r#  r$  r  r(  r  v1PrivateAccountGroupGetSpotFeer  r  r  r  rH  r  )rr  r|  rx  r   r   r  r   r   r  r  r  rJ  r  
takerMakers                 rt  fetch_trading_feesascendex.fetch_trading_fees   s&    	..26''6\
 77G8TU" ~~h3~~dFB/q#d)$A'C''X6H%%hc:FUB7J ))*g>))*g>"!FN % rv  r  r  r  r  c                 &   U R                  U5      nSnSn	U R                  SU5      u  pU R                  SXv5      u  pU R                  U R                  S0 5      n
U R                  XS5      nUb  SnU R                  U R                  S0 5      nU R                  US5      nU R                  USS5      nUUUS   U R                  5       U R                  X5      UUS	.nUS
:H  =(       d    US:H  nUS:H  =(       d    US:H  nU R                  US5      nU R                  USU5      nU R                  USS5      nU R                  USS5      nU(       a  U R                  X5      US'   US:X  a  SUS'   US:X  a  SUS'   U(       a  SUS'   Ub.  U R                  UU5      US'   U(       a  SUS'   OU(       a  SUS'   Ub  XS'   US   (       a  Ub  XS'   OXS'   U(       a  SUS'   U(       a  SUS'   U R                  USS/5      nU R                  X5      $ )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   rB   r   r7   r  )r   r   r  r  r  r  r  r  stop_marketr  
stop_limitr  Fr  r   r  
orderPricer   r   Tr  r  rA   categoryr   
ReduceOnlyr  Post)r  r&  r%  r  r   r  r(  r  r  amount_to_precisionis_post_onlyr  price_to_precisionr'  r  )rr  r  r  r  r  r  r|  r  r   r  r   r   rx  r   r  r   isMarketOrderisLimitOrderr  r  r  r   s                         rt  create_order_requestascendex.create_order_requestP  sM    V$

!??@TV\]
!??@TV\e
6FK**>vN!&O..26''6**6?DI) /Tl%%'00@

 (*F0ECdl.B&&v}=$$]E6B^^FL%@
))&.+N$($;$;F$JGL!%%*GM"%%*GM""&GJ##'#:#:6<#PGK '3$'4$$)DM&>*&5
#*9&'&2
#&,
#6L.#AB{{7++rv  c                 X   U R                  5         U R                  5         U R                  U5      nU R                  XX4XV5      nSn	US   (       a  U R	                  U5      n	OU R                  U5      n	U R                  U	S0 5      n
U R                  U
SS0 5      nU R                  X5      $ )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>`
NrC   r   r   r   )	r#  r$  r  r  %v2PrivateAccountGroupPostFuturesOrder!v1PrivateAccountCategoryPostOrderr  safe_dict_2r  )rr  r  r  r  r  r  r|  r  r   r  r   r   s               rt  create_orderascendex.create_order  s    , 	V$++F$V&>AA'JH==gFH@ ~~h3  w;..rv  ordersc           	      \   U R                  5         U R                  5         / nSnSn[        S[        U5      5       H  nX   nU R	                  US5      nUc  UnOXH:w  a  [        U R                  S-   5      eU R	                  US5      n	U R	                  US5      n
U R                  US5      nU R                  US5      nU R                  US	0 5      nU R                  S
U5      nUS   nUb#  Uc  UnOX_:w  a  [        U R                  S-   5      eU R                  XXX5      nUR                  U5        M     U R                  U5      nU R                  U R                  S0 5      nU R	                  UUS   S5      nUb  SnU R                  U R                  S0 5      nU R	                  US5      n0 nSnUS   (       a  [        U R                  S-   5      eUUS'   UUS'   UUS'   U R!                  U5      nU R                  US0 5      nU R#                  US/ 5      nU R%                  UU5      $ )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  r  r  r  r|  rJ   zS createOrders() requires all orders to have the same margin mode(isolated or cross)r   r   rB   r7   rC   zG createOrders() is not currently supported for swap markets on ascendexr   r   r  r   r   )r#  r$  r  r  r  r+   r7   r  r  r&  r  r  r  r   r(  r/   &v1PrivateAccountCategoryPostOrderBatchr  parse_orders)rr  r  r|  ordersRequestsr  r   r  rawOrderrJ  r  r  r  r  orderParamsmarginResultcurrentMarginModeorderRequestr  r   r   rx  r   r   r  r   r   s                             rt  create_ordersascendex.create_orders  sQ    	
q#f+&AyH''(;H~!%$TWW/l%lmm##Hf5D##Hf5D%%h9F$$Xw7E..8R@K==nkZL ,Q ,%!2J!6(  4I  *I  J  J44XTSXfL!!,/- '. V$6FK**>6&>6R!&O..26''6&>tww)rrss (4GO$*9G&' .GHBB7KH. ~~h3~~dFB/  v..rv  r7   c                    U R                  5         U R                  5         SnUb  U R                  U5      nU R                  SXC5      u  pVU R	                  U R
                  S0 5      nU R                  XuS5      nU R	                  U R                  S0 5      n	U R                  U	S5      n
U
UUS.nSnUS:X  d  US	:X  a!  U R                  U R                  X5      5      nOIUS
:X  a%  XS'   U R                  U R                  X5      5      nO[        U R                  S-   U-   S-   5      eU R	                  US0 5      nU R                  X5      $ )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>`
Nrr   r   r   r   r7   )r   r   r  rA   rB   rC   r   z- fetchOrder() is not currently supported for r"  r   )r#  r$  r  r%  r  r   r  r(  &v1PrivateAccountCategoryGetOrderStatusr  *v2PrivateAccountGroupGetFuturesOrderStatusr/   r7   r  )rr  r7   r  r|  r  r  queryr   r   rx  r   r   r  r   s                 rt  fetch_orderascendex.fetch_orderR  sI    	[[(F88vV6FK**>H..26''6) /

 FN 0BB4;;wC^_HV^*9&'FFt{{SZGbcHtww)XX[__bllmmH ~~h3--rv  c                 X   U R                  5         U R                  5         SnUb  U R                  U5      nUS   nU R                  U R                  S0 5      nU R                  US5      nU R                  SXT5      u  pU R                  U R                  S0 5      n
U R                  XS5      nUUS.nSnUS	:X  d  US
:X  a!  U R                  U R                  X5      5      nOIUS:X  a%  XS'   U R                  U R                  X5      5      nO[        U R                  S-   U-   S-   5      eU R                  US/ 5      nUS:X  a  U R                  XX#5      $ / n[        S[!        U5      5       H)  nU R#                  UU   U5      nUR%                  U5        M+     U R'                  XX#5      $ )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   r7   ro   r   r   )r   r   rA   rB   rC   r   z2 fetchOpenOrders() is not currently supported for r"  r   r   )r#  r$  r  r  r(  r  r%  r   $v1PrivateAccountCategoryGetOrderOpenr  (v2PrivateAccountGroupGetFuturesOrderOpenr/   r7   r  r  r  r  r  r  filter_by_symbol_since_limit)rr  r  rg  r  r|  r  rx  r   r  r  r   r   r   r  r   r  r  r   s                     rt  fetch_open_ordersascendex.fetch_open_orders  s    	[[(FH%F..26''6889JF[6FK**>H) /
 FN 0@@WA\]HV^*9&'DDT[[QXE`aHtww)]]`ddgqqrrH ~~h3i'$$T5@@q#d)$A$$T!Wf5EMM%  % 00NNrv  c                 P   U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      n0 nSnUb  U R                  U5      nUS   US'   U R                  SX5      u  pU R                  U R                  S0 5      nU R	                  USS5      nU R                  U	UUSS	.5      nUb  X'S
'   U R	                  US5      nUb  XS'   U R                  U R                  S0 5      nU R	                  XS5      nSnUS:X  a1  XgS'   UUS'   Ub  X7S'   U R                  U R                  Xz5      5      nOUS:X  a-  UUS'   Ub  X7S'   U R                  U R                  Xz5      5      nOUUS:X  a1  XgS'   UUS'   Ub  X7S'   U R                  U R                  Xz5      5      nO[        U R                  S-   U	-   S-   5      eU R                  US/ 5      n[!        U["        5      (       d  U R                  US/ 5      nU R%                  UXU5      $ )a  
fetches information on multiple closed orders made by the user

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

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch orders for
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r   r7   Nr  rS   r   r   /v2PrivateAccountGroupGetFuturesOrderHistCurrent)rA   rB   rC   	startTimerj  endTimer   r   +v1PrivateAccountCategoryGetOrderHistCurrentr   r   r  rx  pageSizez4 fetchClosedOrders() is not currently supported for r"  r   )r#  r$  r  r(  r  r  r%  r   get_supported_mappingr  r  r   r  r/   r7   r  rX  r  r  )rr  r  rg  r  r|  rx  r   r   r  r  r  r   defaultMethodr   rj  r   r   r  r   s                      rt  fetch_closed_ordersascendex.fetch_closed_orders,  s_    	..26''6

 [[(F &tGH889Lf]../BBG(((<WX++D!#E3
 
 #(K   1!&I6FK**>HBB'3O$*9G&' #( GGT[HcdH22!0GI #( 55dkk'6QRHHH'3O$*9G&' &+
#KKDKKX_LghHtww)__bffissttx ~~h3$%%>>$3D  ve<<rv  c                 v   Uc  [        U R                  S-   5      eU R                  5         U R                  5         U R	                  U5      nU R                  SXC5      u  pVU R                  U R                  S0 5      nU R                  XuS5      nU R                  U R                  S0 5      n	U R                  U	S5      n
U
UUS   U R                  5       SS	.nU R                  US
S5      nUc  XS'   OXS'   U R                  US
S/5      nSnUS:X  d  US:X  a!  U R                  U R                  X5      5      nOIUS:X  a%  XS'   U R                  U R                  X5      5      nO[!        U R                  S-   U-   S-   5      eU R                  US0 5      nU R#                  USS0 5      nU R%                  X5      $ )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 argumentrH   r   r   r   r7   foobar)r   r   r  r  r7   r  r  rA   rB   rC   r   z. cancelOrder() is not currently supported for r"  r   r   r   )r*   r7   r#  r$  r  r%  r  r   r  r(  r  r  r'  #v1PrivateAccountCategoryDeleteOrderr  'v2PrivateAccountGroupDeleteFuturesOrderr/   r  r  )rr  r7   r  r|  r  r  r  r   r   rx  r   r   r  r  r   r   s                   rt  cancel_orderascendex.cancel_order  s    >#DGG.Y$YZZV$88W6FK**>H..26''6) /Tl%%'
 **6?DI !#I)DMYYv'>?FFN 0??G@[\HV^*9&'CCDKKPWD_`Htww)YY\``cmmnn@ ~~h3  w;..rv  c                    U R                  5         U R                  5         SnUb  U R                  U5      nU R                  SX25      u  pEU R	                  U R
                  S0 5      nU R                  XdS5      nU R	                  U R                  S0 5      nU R                  US5      n	U	UU R                  5       S.n
Ub  US   U
S'   SnUS	:X  d  US
:X  a!  U R                  U R                  X5      5      nOIUS:X  a%  XzS'   U R                  U R                  X5      5      nO[        U R                  S-   U-   S-   5      eU R                  SU05      /$ )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
NrG   r   r   r   r7   )r   r   r  r  rA   rB   rC   r   z2 cancelAllOrders() is not currently supported for r"  r   )r#  r$  r  r%  r  r   r  r(  r  &v1PrivateAccountCategoryDeleteOrderAllr  *v2PrivateAccountGroupDeleteFuturesOrderAllr/   r7   r  )rr  r  r|  r  r  r  r   r   rx  r   r   r  s               rt  cancel_all_ordersascendex.cancel_all_orders>	  sd    	[[(F889JF[6FK**>H..26''6) /%%'

  &tGHFN 0BB4;;wC^_HV^*9&'FFt{{SZGbcHtww)]]`ddgqqrrF H!
   	rv  r  c                     U R                  US5      nU R                  US5      nU R                  X5      nU R                  U5        Uc  S OUS   nU R                  US5      nU R                  Xv5      nUUUUUS.$ )NaddresstagIdr  
blockchain)r   r  networkr
  tag)r  check_addressnetwork_id_to_code)	rr  depositAddressr  r
  r  r  r  r  r  s	            rt  parse_deposit_addressascendex.parse_deposit_address	  s     "">9=  9~57# (tx/?$$^\B	))):"
 	
rv  r  c                    U R                  5         U R                  U5      nU R                  USS5      nU R                  U5      nU R	                  US/5      nUS   US.nU R                  U R                  Xb5      5      nU R                  US0 5      nU R                  US/ 5      n	[        U	5      n
SnU
S:  am  U R                  U	S5      nUcE  [        UR                  5       5      nS	R                  U5      n[        U R                  S
-   U-   5      eU R                  X0 5      nOU R                  U	S0 5      nU R!                  X5      nU R                  USU05      $ )a  
fetch the deposit address for a currency associated with self account

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: unified network code for deposit chain
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r  r  r7   )r  r  r   r
  Nr   z, za fetchDepositAddress() returned more than one address, a chainName parameter is required, one of r   r   )r#  r  r  r  r'   v1PrivateGetWalletDepositAddressr  r  r  r  r  r  r  rV  r*   r7   r  )rr  r  r|  r  r  r  r   r  r   	addressesnumAddressesr
  addressesByChainName
chainNamesr  r  s                   rt  fetch_deposit_addressascendex.fetch_deposit_address	  sv    	==&((KH++K8	6K=1d^#
 88W9UVD ~~h3NN4B7	9~!#'==K#H  !"6";";"=>
:.'  3V  )V  Y_  )_  `  `nn%9bIG nnY26G++G>{{6H$
  	rv  c           	      L    SS0nU R                  XX0R                  XT5      5      $ )a  
fetch all deposits made to an account
:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
txTyper  fetch_transactionsr  rr  r  rg  r  r|  r   s         rt  fetch_depositsascendex.fetch_deposits	  s.     i
 &&tE;;w;WXXrv  c           	      L    SS0nU R                  XX0R                  XT5      5      $ )a  
fetch all withdrawals made from an account
:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
r  
withdrawalr  r   s         rt  fetch_withdrawalsascendex.fetch_withdrawals	  s.     l
 &&tE;;w;WXXrv  c                 .   U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  X5S'   U R                  U R                  XT5      5      nU R	                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $ )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>`
Nr7   r  startTsr  r   )r#  r  v1PrivateGetWalletTransactionsr  r  r  parse_transactions)
rr  r  rg  r  r|  r   r  r  r   transactionss
             rt  fetch_deposits_withdrawals#ascendex.fetch_deposits_withdrawals

  s     	
 }}T*H'~GG!&I"'J66t{{77ST4 ~~h3~~dFB7&&|uLLrv  c                 4    SSSSS.nU R                  X!U5      $ )Npendingokr  )	reviewingr/  	confirmedr  r  r  s      rt  parse_transaction_status!ascendex.parse_transaction_statusB
  s*    " "	
 &99rv  transactionc                    U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	[        R                  " X5      nU R                  Xr5      n
0 SU_S	U R                  US
5      _SU R                  US5      _SU R                  US5      _SU
_SS _SU R                  U5      _SU R                  U R                  US5      5      _SU_SU R                  U5      _SU_SS _SU_SU_SS _SU_SS _S U
U R                  U	5      S S.SS.E$ )NdestAddressr
  destTagr  r  r  
commissionr   r7   	requestIdtxidnetworkTransactionIdr  transactionTyper  r  r  r	  r
  addressFrom	addressTor  tagFromtagToupdated)r  r  rateF)commentr  internal)	r  r  r  r1   
string_subr  rq  r3  r  )rr  r5  r  r7  r
  r  r	  
currencyIdr  feeCostStringr  s              rt  parse_transactionascendex.parse_transactionK
  s   & nn[-D"";	:{I6%%k6:	%%k7;
''X>((lC)),F&&z<
K
$"";<
 D$$[2HI
 D$$[2CD	

 
 t
 d''5
 d33D4D4D[RZ4[\
 
 Y/
 w
 4
 
 3
 t
  S!
" t#
$  ))-8
 1
 	
rv  c                    U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      nSU0nU R                  U R                  XR5      5      nU R                  US0 5      nU R                  US/ 5      n/ n	[        S[        U5      5       H%  n
U	R                  U R                  X   5      5        M'     U R                  U5      nU R                  U	SUS5      $ )a  
fetch all open positions
:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
r   r7   r   r   r  r  F)r#  r$  r  r(  r  r*  r  r  r  r  r  parse_positionmarket_symbolsfilter_by_array_positions)rr  rR  r|  rx  r   r   r  r   positionr  r  s              rt  fetch_positionsascendex.fetch_positions
  s     	..26''6\
 ??G@\]P ~~h3>>$R8q#h-(AMM$--hk:; )%%g.--fhOOrv  rO  c                    U R                  US5      nU R                  X25      nU R                  US5      n[        R                  " US5      (       a  U R                  US5      nU R                  US5      nUS:X  a  SOSnS nUS:X  a  U R                  US	5      nU R	                  0 S
U_SS _SUS   _SU R                  U5      _SU_SS _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SS _SS _SS _S S S US S U R                  US5      S U R                  US5      U R                  US5      S.
E5      $ ) Nr  buyOpenOrderNotional0sellOpenOrderNotional
marginTypecrossedr   r!  isolatedMarginr   r7   notionalr   liquidationPrice
entryPriceavgOpenPriceunrealizedPnlr   r  rO  r  	markPrice	lastPricer  r  r	  r
  r	  r  r  )
lastUpdateTimestampmaintenanceMarginmaintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager	  marginRatior  r  )	r  r  r1   	string_eqsafe_positionrq  r  r  r  )rr  rO  r  rJ  rY  rV  r   rc  s           rt  rL  ascendex.parse_position
  s*   . ##Hh7!!(3##H.DEXs++''2IJH%%h=
!+y!8Wz

#))(4DEJ!! #
H#
$#
 fX&#
 ))(3	#

 *#
 #
 $**8^D#
 T--hH#
 $#
 ))(J?#
 D,,V^D#
 ))(K@#
 #
 D**8V<#
 d#
  !#
" ##
$ $(!%+/$!'+))(J?!--hH#//:KL7#
  	rv  c                    U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      n0 SU_SU_SU R                  US5      _SU R                  US5      _SU R	                  S	5      _S
S _SU_SU R                  U5      _SS _SS _SS _SS _SS _SS _SU_SU_SU R                  U5      _SS 0E$ )Nr  r  fundingRatenextFundingTimer   r^  
indexPriceinterestRaterT  estimatedSettlePricer	  r
  previousFundingRatenextFundingRatepreviousFundingTimestampnextFundingTimestamppreviousFundingDatetimenextFundingDatetimefundingTimestampfundingDatetimeri  )r  rH  r  r  rq  r  )rr  r  r  rJ  r  currentTimerq  nextFundingRateTimestamps           rt  parse_funding_rateascendex.parse_funding_rate
  su    ##Hh7!!(3''&9**8]C#'#4#4X?P#Q 
H
f
 ))(K@
 $**8\B	

 D--c2
 #D
 
 [1
 "4
 t
 '
 #D
 &t
 "4
 ?
   8!
" t||,DE#
$ %
 	
rv  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US0 5      nU R	                  US/ 5      nU R                  XQ5      $ )a:  
fetch the funding rate for multiple markets
:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `funding rates structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexe by market symbols
r   r  )r#  rM  v2PublicGetFuturesPricingDatar  r  parse_funding_rates)rr  rR  r|  r  r   r  s         rt  fetch_funding_ratesascendex.fetch_funding_rates%  sg     	%%g.55f=2 ~~h3NN4b9	''	;;rv  c                    U R                  5         U R                  5         U R                  U5      nU R                  U R                  S0 5      nU R                  US5      nU R                  X5      nUUS   US.nU R                  U R                  X5      5      n	US:X  a  [        R                  " U5      nU R                  U R                  X5      U R                  U5      US.5      $ )Nr   r7   )r   r  r  reduce)r  r  )r#  r$  r  r  r(  r  r  6v2PrivateAccountGroupPostFuturesIsolatedPositionMarginr  r1   
string_absparse_margin_modificationrq  )
rr  r  r  r  r|  r  rx  r   r   r  s
             rt  modify_margin_helperascendex.modify_margin_helperK  s    V$..26''6))&9)Tl

 NNt{{[bOkl 8''/F{{499(K''/N
  	rv  r   c                 `    U R                  US5      nUS:X  a  SOSnUUS   S SS S US   US S S.
$ )	Nr  rT  r0  failedr  r!  r  )
r   r  r  r   r  r  r  r  r	  r
  r  )rr  r   r  	errorCoder  s        rt  r  "ascendex.parse_margin_modificationf  sU     $$T62	#s*X&$7O
 	
rv  c                 *    U R                  X* SU5      $ )a#  
remove margin from a position
:param str symbol: unified market symbol
:param float amount: the amount of margin to remove
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=reduce-margin-structure>`
r  r  rr  r  r  r|  s       rt  reduce_marginascendex.reduce_margin}  s     (((FKKrv  c                 (    U R                  XSU5      $ )a  
add margin
:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
addr  r  s       rt  
add_marginascendex.add_margin  s     ((GGrv  r	  c                    Uc  [        U R                  S-   5      eUS:  d  US:  a  [        U R                  S-   5      eU R                  5         U R	                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eU R                  U R                  S0 5      nU R                  US5      nUUS   US	.nU R                  U R                  Xs5      5      $ )
aG  
set the level of leverage for a market

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

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
z) setLeverage() requires a symbol argumentr   d   z% leverage should be between 1 and 100rC   z+ setLeverage() supports swap contracts onlyr   r7   )r   r  r	  )r*   r7   r+   r#  r$  r  r,   r  r(  r  (v2PrivateAccountGroupPostFuturesLeverager  )rr  r	  r  r|  r  rx  r   r   s           rt  set_leverageascendex.set_leverage  s     >#DGG.Y$YZZqLhnTWW'NNOOV$f~DGG&SSTT..26''6)Tl 

 <<T[[=YZZrv  r   c                    Uc  [        U R                  S-   5      eUR                  5       nUS:X  a  SnUS:w  a  US:w  a  [        U R                  S-   5      eU R	                  5         U R                  5         U R                  U5      nU R                  U R                  S0 5      nU R                  US5      nUUS   US.nUS	   (       d  [        U R                  S
-   5      eU R                  U R                  Xs5      5      $ )aD  
set margin mode to 'cross' or 'isolated'

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

:param str marginMode: 'cross' or 'isolated'
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
z+ setMarginMode() requires a symbol argumentr   rW  r!  z@ setMarginMode() marginMode argument should be isolated or crossr   r7   )r   r  rV  rC   z- setMarginMode() supports swap contracts only)r*   r7   rz  r+   r#  r$  r  r  r(  r  r,   *v2PrivateAccountGroupPostFuturesMarginTyper  )rr  r   r  r|  r  rx  r   r   s           rt  set_margin_modeascendex.set_margin_mode  s     >#DGG.[$[\\%%'
 "J#
i(?TWW'iijjV$..26''6)Tl$

 f~DGG&UUVV>>t{{7?[\\rv  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  U5      nU R	                  XAS5      $ )a|  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
r   r  )r#  r  r  rM  parse_leverage_tiers)rr  rR  r|  r  r   s        rt  fetch_leverage_tiersascendex.fetch_leverage_tiers  sW     	226:: ~~h3%%g.((AArv  c                    U R                  US/ 5      nU R                  US5      nU R                  XB5      n/ n[        S[	        U5      5       H  nX6   nU R                  US5      nUR                  U R                  US5      U R                  XBSS5      US   U R                  US	5      U R                  US
5      U R                  US5      U R                  [        R                  " SU5      5      US.5        M     U$ )zY
: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  r  r  r  r  ro  rH  r  rq  r1   
string_div)	rr  r   r  r  rJ  tiersr  r  r  s	            rt  parse_market_leverage_tiers$ascendex.parse_market_leverage_tiers  s   8 "^^D2FK##D(3!!(3q#012A%(D $ 0 07J KLLA**8T:N"7O#//6RS#//6RS)-)9)9$@W)X#001C1CCIZ1[\	 	 3 rv  c                    U R                  US/ 5      n[        U5      nUS S S.S S S.0 S.n[        SU5       H  nX6   nU R                  US5      nU R                  US5      n	U R	                  X5      n
S S S.U R                  US5      SS.S	.US
   U
'   US:X  d  Me  U R                  US5      US   S'   SUS   S'   M     U$ )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  )rr  r  r  blockChainsblockChainsLengthr  r  r  r  currencyCoder  s              rt  parse_deposit_withdraw_fee#ascendex.parse_deposit_withdraw_fee&  s   ( nnS,;,"
 " 
 q+,A$J(([AI++Hf=L11)JK#'t<$($4$4Z$O_de/F:{+ !A%,0,<,<Z,Wz"5)38z"<0 - rv  codesc                     U R                  5         U R                  U5      nU R                  US5      nU R                  XAS5      $ )a;  
fetch deposit and withdraw fees

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

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
r   r  )r#  r  r  parse_deposit_withdraw_fees)rr  r  r|  r  r   s        rt  fetch_deposit_withdraw_fees$ascendex.fetch_deposit_withdraw_feesV  sC     	))&1~~h///[IIrv  fromAccount	toAccountc                    U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      nU R                  U5      nU R                  U R                  S0 5      n	U R	                  XU5      n
U R	                  XU5      nU
S:w  a  US:w  a  [        U R                  S-   5      eUU R                  X5      US   U
US.nU R                  U R                  X5      5      nU R                  U R                  S0 5      nU R                  USS	5      nU R                  X5      nU(       a  UUS
'   UUS'   UUS'   UUS'   U$ )u  
transfer currency internally between wallets on the same account
:param str code: unified currency codeåå
:param float amount: amount to transfer
:param str fromAccount: account to transfer from
:param str toAccount: account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r   r7   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&   r7   currency_to_precision!v1PrivateAccountGroupPostTransferr  r  parse_transfer)rr  r  r  r  r  r|  rx  r   r  r   fromIdtoIdr   r  transferOptionsr   r   s                    rt  r   ascendex.transfere  si    	..26''6==&6FK!!.{K9EV  +E  !E  F  F)00>d^!
 99$++g:VW ..z2F"&..B[]a"b&&x:"&1H]#$-H[!!'HX#'HZ rv  r   c                     U R                  US5      nU R                  S U5      nUS S S US S S U R                  U5      S.	$ )Nr  )	r   r7   r	  r
  r  r  r  r  r  )r  r  parse_transfer_status)rr  r   r  r  r  s        rt  r  ascendex.parse_transfer  sX     !!(F3..tX>$008

 
	
rv  c                     US:X  a  gg)NrT  r0  r   )rr  r  s     rt  r  ascendex.parse_transfer_status  s    S=rv  c           	         U R                  5         U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX4SS5      $ U R	                  U R
                  S0 5      nU R                  US5      nSU0nS	n	Ub  U R                  U5      n	U	S   US
'   Ub  X8S'   U R                  U R                  X5      5      n
U R	                  U
S0 5      nU R                  US/ 5      nU R                  XX#5      $ )a  
fetch the history of funding payments paid and received on self account

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

:param str [symbol]: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
Fr]   paginatepager4   r   r7   r   Nr  r  r   )r#  r$  handle_option_and_params fetch_paginated_call_incrementalr  r(  r  r  .v2PrivateAccountGroupGetFuturesFundingPaymentsr  r  parse_incomes)rr  r  rg  r  r|  r  rx  r   r   r  r  r   rowss                rt  fetch_funding_historyascendex.fetch_funding_history  s    	88AVXbc889NPV_dntvxyy..26''6\
 [[(F &tGH"'JFFt{{SZGcd& ~~h3~~dFB/!!$==rv  c           
          U R                  US5      nU R                  US5      nUU R                  X2SS5      SUU R                  U5      S U R	                  US5      S.$ )Nr  r	  -rC   USDTpaymentInUSDT)r   r  r  r	  r
  r7   r  )r  r  rH  r  r  )rr  incomer  rJ  r	  s        rt  parse_incomeascendex.parse_income  sl     ##FH5%%fk:	&&xfE"Y/&&v?
 	
rv  c                 X   U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      nSU0nU R                  U R                  XR5      5      nU R                  US0 5      nU R                  US/ 5      nU R                  XS5      $ )aX  
fetches the set margin mode of the user

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

:param str[] [symbols]: a list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `margin mode structures <https://docs.ccxt.com/#/?id=margin-mode-structure>`
r   r7   r   r   r  r  )	r#  r$  r  r(  r  r*  r  r  parse_margin_modes)	rr  rR  r|  rx  r   r   r  r   marginModess	            rt  fetch_margin_modesascendex.fetch_margin_modes  s     	..26''6\
 ??G@\]P ~~h3nnT;;&&{XFFrv  c                     U R                  US5      nU R                  US5      nUS:X  a  SOSnUU R                  X25      US.$ )Nr  rV  rW  r   r!  )r   r  r   )r  rH  )rr  r   r  rJ  rV  rB   s         rt  parse_margin_modeascendex.parse_margin_mode,  sR    ##J9%%j,?
'94:&&x8 
 	
rv  c                 X   U R                  5         U R                  5         U R                  U R                  S0 5      nU R	                  US5      nSU0nU R                  U R                  XR5      5      nU R                  US0 5      nU R                  US/ 5      nU R                  XS5      $ )aZ  
fetch the set leverage for all contract markets

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

:param str[] [symbols]: a list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `leverage structures <https://docs.ccxt.com/#/?id=leverage-structure>`
r   r7   r   r   r  r  )	r#  r$  r  r(  r  r*  r  r  parse_leverages)	rr  rR  r|  rx  r   r   r  r   	leveragess	            rt  fetch_leveragesascendex.fetch_leverages6  s     	..26''6\
 ??G@\]P ~~h3NN4b9	##IAArv  c                     U R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  SOSnUU R                  X25      UUUS.$ )Nr  r	  rV  rW  r   r!  )r   r  r   longLeverageshortLeverage)r  r  rH  )rr  r	  r  rJ  leverageValuerV  r   s          rt  parse_leverageascendex.parse_leverages  sj    ##Hh7))(J?%%h=
!+y!8Wz
&&x8$)*
 	
rv  r   GETc                 p   US   nUS   nU R                  US5      n	Sn
U	S:H  nU(       d  U	S:X  a&  XR                  SU5      -  n
U R                  US5      nU R                  X5      nU
S	-  n
US
:X  a  U	S:X  a  SU-   S-   U-   nOUS-   U-   nOXS-   -  n
U(       a  XR                  SU5      -  n
U R                  US5      nX-  n
US:X  a  US:X  d  US:X  a  SnUS:X  a  US:X  a  SnUR                  S5      S:  a  UR	                  S5      nUS   nU R                  X@R                  U5      5      nUS:X  a  U(       a  U
SU R                  U5      -   -  n
OU R                  5         [        U R                  5       5      nUS-   U-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      nU R                  UUS.nUS:X  a  U(       a  U
SU R                  U5      -   -  n
OSUS'   U R!                  U5      nU R"                  S   S    U
-   n
XXeS!.$ )"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   )rr  pathr   r   r|  r  r  r   accessr  r   r   r   r  r	  payloadr  s                    rt  signascendex.sign  sP   a&QQ'#44t~5&&'96BBCYYv7F%%d3{d?v~!G+c1G;!C-'1S= C&&'<fEEC6#56tO'^";L\A\GtO'Z"7G<<	"a'MM#&EAhG6#6#6t#<=XsT^^F333++-D--/0I#o/G99T[[14;;t{{3KW^^]efD"kk$-$(G
 3!777C*<'yy(iiv&,dOOrv  httpCodereasonr   r   r  r  c
                 |   Uc  g U R                  US5      n
U R                  US5      nU
S L=(       a    U
S:g  nU(       d  Ubz  U R                  S-   U-   nU R                  U R                  S   X5        U R                  U R                  S   X5        U R	                  U R                  S   X5        [        U5      eg )Nr  messagerT   r`  ra  )r  r7   throw_exactly_matched_exceptionr#  throw_broadly_matched_exceptionr&   )rr  r  r	  r   r   r  r  r  requestHeadersrequestBodyr  r  errorfeedbacks                 rt  handle_errorsascendex.handle_errors  s     &1""8Y7T!4W(ww}t+H001I4Z001I7]001I7]))rv  r  )N)k__name__
__module____qualname____firstlineno__r   rp  r~  r   r  r%   r   r  r  r  r   r  r   r  r   r  r  r  r-  r  r   r6  dictr   rL  rP  r   r   r[  r  rd  ru  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,  r3  rI  r   rP  rL  r   rz  r    r  r   r  r  r  r  intr  r  r   r  r   r  r  r  r$   r   r  r  r  r  r   r  r   r  r   r  r   r  r  r  __static_attributes____classcell__)rs  s   @rt  r3   r3      sK   M# M^ "$ 1 ') [Z [z $& 	?$v, 	? )+ EtF| EN -/ m4< m^ !# ;s ;. %' $
4= $
L) ) )&)  $& Y0( Y0v :>b *s *3 *Y *X,4 , ,6 ,\ 02 /3 /f /@ 04B -1W -17 -1^
 
4 
4 9=4^bkm BH# BH# BHS BHX[ BHrvw{r| BHH   v    D 6:UW $?3 $?s $?# $?\`af\g $?L	: 	:k kv k kZ )+ .{ .` os{} F,3 F,i F,y F,Z_ F,hk F,P gksu `/3 `/i `/y `/RW `/`c `/D @B V/D$6 V/p 26b g.c g.3 g.R /3TXac oO oO3 oOc oOhlmrhs oOb 154VZce b=# b=S b=PS b=jnotju b=H 37r l/s l/C l/\ /32 H HT
h 
R` 
: 79 G# G^ GR *.Dt\^ Y3 Yc Y Ycghsct Y -1tRV_a Yc Y YC Yfjkvfw Y 6:[_hj 6Ms 6M# 6MUX 6Most  pA 6Mp:s :5
T 5
X 5
Q\ 5
n 26b <Pw <PT(^ <P|=t =V =~$
6 $
[ $
L 6:" $<7 $< $<L FH 3 L^ 6
d 
F 
N` 
. @B LC L LFX L =? H He HCU H 9=R [S [# [: >B" ]# ]s ]@ 7;2 'BG 'B- 'BR- -$|J\ -^. .` <@ J J [] 'S '% 'c 'c 'an 'R
t 
x 
= 
$C C 
 37TX\eg 3>C 3>s 3>RU 3>j
6 
* 59 ;G' ;G ;Gz
D 
* 
 26b ;Bw ;BY ;Bz
t 
V 
x 
 &eBSW 2Phc 3 S # X\ dg  rv  r3   )8ccxt.base.exchanger   ccxt.abstract.ascendexr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   typingr%   ccxt.base.errorsr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3   r  rv  rt  <module>r%     s}    ( .  t  t  t  t  t  t  t  t  t  * 0 - - . ' & . ) ) 4 %m6x m6rv  