
    ei                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl%m'Z' d dl%m(Z( d d	l%m)Z) d d
l%m*Z* d dl%m+Z+ d dl%m,Z, d dl%m-Z- d dl%m.Z. d dl%m/Z/ d dl%m0Z0 d dl%m1Z1 d dl%m2Z2 d dl%m3Z3 d dl%m4Z4 d dl%m5Z5 d dl%m6Z6 d dl%m7Z7 d dl%m8Z8 d dl%m9Z9 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?mAZA d d!lBmCZC  G d" d#ee          ZDdS )$    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyIntLedgerEntryLeverage	Leverages
MarginModeMarginModesMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountNotEnabled)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)OperationRejected)NoChange)MarketClosed)InsufficientFunds)InvalidOrder)OrderNotFound)OrderImmediatelyFillable)OrderNotFillable)DuplicateOrderId)NotSupported)ExchangeClosedByUser)OperationFailed)NetworkError)RateLimitExceeded)InvalidNonce)RequestTimeout)BadResponse)TRUNCATE)	TICK_SIZE)Precisec                   R    e Zd Zdef fdZdqdededefdZdqdededefdZ	i fde
fdZi fdee         fd	Zi fdefd
ZdqdedefdZdddi fdedededee         fdZdqd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ddi fdededefdZdi fdededefdZdddi fdededefdZdqd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!dqd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&di fdede%fd Z'de(fd!Z)i fde(fd"Z*di fd#edefd$Z+di fdefd%Z,di fd&edefd'Z-dqd(edede.fd)Z/i fdede.fd*Z0d+efd,Z1defd-Z2dqd.edede3fd/Z4di fd0edefd1Z5di fd0edefd2Z6dddi fdedededee3         fd3Z7dddi fdedededee3         fd4Z8di fdede9d5e:d6e;d7e<f
d8Z=i fd9ee>         fd:Z?di fdede9d5e:d6e;d7e<f
d;Z@di fdefd<ZAdi fd0edefd=ZBdi fd>ee         defd?ZCdi fd@eDdefdAZEdi fdedeFfdBZGdqd@ededeHfdCZIdi fdedeJfdDZKdqd#edeLfdEZMddddi fdedede<de<deeN         f
dFZOdqdGededeNfdHZPi fdefdIZQi fded6e;deNfdJZRi fded6e;deNfdKZSdqdefdLZTdddi fdededefdMZUdqdNedOeVdeWfdPZXdQ ZYdddi fdRedededeeW         fdSZZdqdefdTZ[di fdefdUZ\di fdedee]         fdVZ^drdXZ_dqdefdYZ`di fdefdZZadWi fd[Zbd\ Zcd] Zddefd^Zedi fdRed6e;d_ed`edeff
daZgi fdRed6e;dbedcedehf
ddZide Zjdf Zkdgdhi ddfdiZldjeDdkedledmednedoefdpZm xZnS )sasterreturnc                 `   |                      t          t          |                                           i ddddddgd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d-di d.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>di d?dd@ddAddBd dCddDddEddFddGddHdIdJdIdKddLdIdMddNddOddPdi dQddRddSddTddUddVddWddXddYddZdId[dd\dd]dId^dd_dd`ddadi dbddcddddIdeddfddgddhddiddjdIdkddlddmddnddoddpddqdIdrdi dsdIdtdduddvddwddxddyddzdd{dd|dd}dd~dddddddddddi ddddddddddddddddddddddddddddddddddi ddddIddIddddddddddddddddddddddddddddddddddddddg dig dg ddgg dddg dig dg ddgg ddddddddddddddddddddÜdt          ddddƜdddd|                     dɦ          |                     dʦ          d˜idddddddddddҜdddd֜ddddڜ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*          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          dt.          dt0          i dt0          dt          dt2          dt4          dt6          dt0          dt          dt"          dt          dt          dt*          dt*          dt*          dt*          dt*          dt*          d t*          i 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          d/t          d0t.          d1t*          i d2t*          d3t          d4t          d5t          d6t          d7t          d8t          d9t          d:t          d;t8          d<t          d=t          d>t:          d?t4          d@t4          dAt4          dBt0          i dCt0          dDt:          dEt4          dFt4          dGt&          dHt          dIt          dJt*          dKt:          dLt*          dMt*          dNt4          dOt          dPt          dQt          dRt          dSt4          i dTt4          dUt          dVt*          dWt*          dXt:          dYt          dZt*          d[t4          d\t4          d]t          d^t          d_t          d`t          dat          dbt          dct          ddt"          i det          dft          dgt          dht          dit(          djt*          dkt          dlt0          dmt*          dnt*          dot*          dpt4          dqt*          drt4          dst.          dtt*          dut(          t4          t*          t          t*          t*          t4          t4          dvi dw          S (x  Nidr@   nameAster	countriesUS	rateLimitiM  hostnamezaster.markets	certifiedFproTdexurlszOhttps://github.com/user-attachments/assets/4982201b-73cd-4d7a-8907-e69e239e9609zhttps://www.asterdex.com/enzhttps://fapi.asterdex.com/fapizhttps://sapi.asterdex.com/api)
fapiPublicfapiPrivate
sapiPublicsapiPrivatez$https://github.com/asterdex/api-docszBhttps://docs.asterdex.com/product/asterex-simple/fees-and-slippagez+https://www.asterdex.com/en/referral/aA1c2Bg?)urldiscount)logowwwapidocfeesreferralhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateConvertTradecreateDepositAddresscreateLimitBuyOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTrailingPercentOrdercreateTriggerOrder	editOrder
editOrdersfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledAndClosedOrdersemulatedfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchConvertCurrenciesfetchConvertQuotefetchConvertTradefetchConvertTradeHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLastPricesfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransferfetchTransfersfetchUnderlyingAssetsfetchVolatilityHistoryfetchWithdrawAddressesfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMarginrepayCrossMarginrepayIsolatedMarginsandbox)setLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawrV   get)v1/pingv1/timev1/exchangeInfov1/depth	v1/tradesv1/historicalTradesv1/aggTrades	v1/klineszv1/indexPriceKlineszv1/markPriceKlineszv1/premiumIndexzv1/fundingRatezv1/fundingInfov1/ticker/24hrv1/ticker/pricev1/ticker/bookTickerzv1/adlQuantilezv1/forceOrders)v1/positionSide/dualv1/multiAssetsMarginv1/orderzv1/openOrderv1/openOrdersv1/allOrdersz
v2/balancez
v3/balancez
v3/accountz
v4/accountzv1/positionMargin/historyzv2/positionRiskzv3/positionRiskv1/userTradesz	v1/incomezv1/leverageBracketv1/commissionRate)r   r   r   zv1/order/testv1/batchOrdersv1/asset/wallet/transferzv1/countdownCancelAllzv1/leveragezv1/marginTypezv1/positionMarginv1/listenKeyr   )r   v1/allOpenOrdersr   r   )r   postputdelete)r   r   r   r   r   r   r   r   r   r   r   zv1/aster/withdraw/estimateFee)r   r   r   r   zv1/transactionHistoryz
v1/accountr   )r   r   zv1/asset/sendToAddresszv1/aster/user-withdrawr   )r   r  r   
timeframes1m3m5m15m30m1h2h4h6h8h12h1d3d1w1M)r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  precisionModerequiredCredentials)apiKeysecretrX   tradingz0.0001z0.00035)	tierBased
percentagemakertakeroptionsi'  GTC*0x0000000000000000000000000000000000000000SPOTFUTURE)r\   r_   linearr^   ETHBSCArbitrum)ERC20BEP20ARB   8   i  )r$  r%  r&  )defaultType
recvWindowdefaultTimeInForcezeroAddressquoteOrderQtyaccountsByTypenetworksnetworksToChainId
exceptionsz-1000z-1001z-1002z-1003z-1004z-1005z-1006z-1007z-1010z-1011z-1013z-1014z-1015z-1016z-1020z-1021z-1022z-1023z-1100z-1101z-1102z-1103z-1104z-1105z-1106z-1108z-1109z-1110z-1111z-1112z-1113z-1114z-1115z-1116z-1117z-1118z-1119z-1120z-1121z-1125z-1127z-1128z-1130z-1136z-2010z-2011z-2013z-2014z-2015z-2016z-2018z-2019z-2020z-2021z-2022z-2023z-2024z-2025z-2026z-2027z-2028z-4000z-4001z-4002z-4003z-4004z-4005z-4006z-4007z-4008z-4009z-4010z-4011z-4012z-4013z-4014z-4015z-4016z-4017z-4018z-4019z-4020z-4021z-4022z-4023z-4024z-4025z-4026z-4027z-4028z-4029z-4030z-4031z-4032z-4033z-4044z-4045z-4046z-4047z-4048z-4049z-4050z-4051z-4052z-4053z-4054z-4055z-4056z-4057z-4058z-4059z-4060z-4061z-4062z-4063z-4064z-4065z-4066z-4067z-4068z-4069z-4070z-4071z-4072z-4073z-4074z-4075z-4076z-4077z-4078z-4079z-4080z-4081z-4082z-4083z-4084z-4085z-4086z-4087z-4088z-4104z-4114z-4115z-4118z-4131z-4135z-4137z-4138z-4139z-4140z-4141z-4142z-4144)z-4161z-4164z-4165z-4183z-4184z-5060z-5076)exactbroad)deep_extendsuperr@   describer=   parse_numberr6   r7   r$   r8   r3   r)   r;   r:   r%   r2   r5   r4   r9   r(   r*   r/   r0   r-   r.   r1   r+   r'   r&   r,   )self	__class__s    H/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/aster.pyr9  zaster.describe+   s   eT 2 2 ; ; = = y@
'y@
Gy@
 $y@
 y@
 y@
 y@
 4y@
 4y@
 i4"B#C"A#B	  >\H #  y@
8  PPP %P 	P
 %P %P TP $UP 'P "4P tP P $UP  P %eP  '!P" &u#P P$ '%P& ''P( /)P* ,U+P, (-P. 0/P0 t1P2 3P4 75P6 &u7P8 (9P: ';P< &u=P> (?P@ "5APB (CPD -eEP P PF %eGPH UIPJ eKPL  MPN OPP  QPR &uSPT +EUPV )%WPX /
YPZ &z[P\ #E]P^ $Z_P` )%aPb $UcPd $UePf +EgP P Ph 'iPj (kPl "4mPn oPp &uqPr (sPt 1%uPv  wPx +EyPz *:{P| +E}P~ &tP@ '
APB (CPD #DEPF *4GPH $TIP P PJ uKPL "5MPN *:OPP +EQPR #ESPT "5UPV tWPX #EYPZ  [P\ !$]P^ %e_P` $UaPb &ucPd -eePf /gPh ":iPj #DkP P Pl +JmPn oPp !%qPr !%sPt "5uPv &uwPx +EyPz  {P| d}P~ $UP@ +EAPB !$CPD "4EPF uGPH #EIPJ dKPL !$MP P PN "5OPP tQPR #ESPT  UPV 'WPX $TYPZ !$[P\ (]P^ %d_P` )%aPb )%cPd uePf tgPh iPj TkPl tmPn "4oP P Pp #EqPr %jsPt &zuPv 'wPx $UyPz  {P| !%}P~ (P@ )%APB )%CPD "5EPF #EGPH +EIPJ KPL #EMPN &uOPP 5QP PR  $"!%#'  _P P P9y@
Z    .  &   '  I*  * X    "     '  )   el l[y@
t  uy@
V	 YW	y@
X	 "$ $Y	y@
`	 !%"&!..x88!..y99	 a	y@
p	 %'&+K!%"&&$	# # #"%   %& &# q	y@
^
 e_e \e 0	e
 .e -e Ze [e ^e _e -e Ze -e .e 1e  \!e" \#e$ 0%e e& Z'e* Z+e, Z-e. ./e0 Z1e2 Z3e4 .5e6 Z7e8 Z9e: Z;e< Y=e> Z?e@ ZAeB ZCeD ZEeF \GeH \Ie e eJ \KeL \MeN \OeP ZQeR YSeT 0UeV ZWeX ZYeZ Z[e\ \]e` \aeb ]ced ]eef 0geh 0iej \kel .me e en .oep -qer 5set .uev -wex .yez .{e| \}e~ Ze@ ZAeD \EeF \GeH \IeJ \KeL \MeN \OeP \Qe e eR \SeT \UeV \WeX \YeZ \[e\ .]e^ \_e` \aeb \ced \eef \geh \iej Zkel Zmen Zoep \qer \se e et \uev Zwex Zyez Z{e| Z}e~ Ze@ ZAeB ZCeD .EeF .GeH ZIeJ .KeL XMeN .OeP .QeR .SeT .Ue e eV .WeX XYeZ .[e\ .]e^ ._e` 0aeb 0ced \eef Xgeh \iej \kel .men Zoep Zqer Zset Zuev .we e ex .yez Z{e| \}e~ \e@ XAeB ZCeD \EeF .GeH .IeJ .KeL ZMeN ZOeP ZQeR ZSeT .UeV _WeX \Ye e eZ Z[e\ Z]e^ -_e` -aeb Yced \eef -geh .iej \kel \men \oep .qer \set .uev \wex \yez Y{e e| /)'))..Ie e eLOi i_
y@
 y y y	    NtypesubTypec                     ||dk    S |dk    S )Ndeliveryinverse r;  r?  r@  s      r=  
is_inversezaster.is_inverse'  s    ?:%&i''r>  c                 *    ||dk    p|dk    S |dk    S )Nr_   r^   r#  rD  rE  s      r=  	is_linearzaster.is_linear-  s&    ?8#88h&&r>  c                 P   |                      |          |                     |          g}|}|                     |di           }|                     |dg           }|                     |di           }|                     |dg           }|                     ||          }i }	t          dt          |                    D ]g}
||
         }|                     |d          }|                     |          }| 	                    ||||dddddddddddddddddd	          |	|<   h|	S )
a  
        fetches all available currencies on an exchange

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#trading-specification-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#exchange-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   assetsr*  assetNminmax)amountr   depositcrypto)infocoderC   rD   activerP  r   fee	precisionlimitsr2  r?  )
sapiPublicGetV1ExchangeInfofapiPublicGetV1ExchangeInfo	safe_dict	safe_listarray_concatrangelensafe_stringsafe_currency_codesafe_currency_structure)r;  paramspromisesresults
sapiResultsapiRows
fapiResultfapiRowsrowsresulticurrency
currencyIdrS  s                 r=  fetch_currencieszaster.fetch_currencies3  s    ,,V44,,V44
 ^^GQ33
>>*h;;^^GQ33
>>*h;;  844 q#d))$$ 	 	AAwH))(G<<J**:66D77   !  $# 
  $#! !
  $#     ! 39 9  F4LL6 r>  c                 
   |                      |          |                     |          g}|}|                     |di           }|                     |dg           }|                     |di           }|                     |dg           }|                     ||          }| j        }	g }
t          dt          |                    D ]}d}||         }|                     |d          }|                     |d          }|                     |d          }| 	                    |          }| 	                    |          }|                     |d          }|d	u}d
}|dk    rd
}d}d	}d	}d	}|dz   |z   }d	}d	}|rl|                     |d          }| 	                    |          }|r|dz   |z   }||k    }||k    }| 
                    |dd|                     d                    }d	}|rd}n|rd}|                     |d          }|dk    }|                     |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,                              d-d	d	d.d	d	d.d	d	d.d	d	d.d/|                     |d0          |d1          }!d2| v rl|                     | d2i           }"|                     |"d3          |                     |"d4          d.|!d5         d6<   |                     |"d7          |!d8         d6<   d9| v rl|                     | d9i           }"|                     |"d:          |!d8         d;<   |                     |"d<          |                     |"d=          d.|!d5         d;<   d>| v rM|                     | d>i           }"|                     |"d<          |                     |"d=          d.|!d5         d?<   d@| v sdA| v r=|                     | d@dAi           }"|                     |"dB          |!d5         dC         dD<   |
                    |!           |
S )Ea  
        retrieves data on all markets for bigone

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#trading-specification-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#exchange-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   symbolsr*  Fsymbol	baseAsset
quoteAssetcontractTypeNT	PERPETUAL/marginAsset:contractSizeunit1r\   r^   statusTRADINGfilters
filterTyperC   basequotesettlebaseIdquoteIdsettleIdr?  r]   r_   r`   rT  contractr#  r  r  r  quantityPrecisionpricePrecisionbaseAssetPrecisionquotePrecision)rO  pricer  r  rL  )leveragerO  r  costonboardDate)rC  r  r  ry  expiryexpiryDatetimestrike
optionTyperV  rW  createdrR  PRICE_FILTERminPricemaxPricerW  r  tickSizerV  LOT_SIZEstepSizerO  minQtymaxQtyMARKET_LOT_SIZEmarketMIN_NOTIONALNOTIONALnotionalr  rM  )rX  rY  rZ  r[  r\  rX   r]  r^  r_  r`  safe_number_2r:  index_bysafe_market_structureparse_precisionsafe_integersafe_numbersafe_dict_2append)#r;  rb  rc  rd  re  rf  rg  rh  ri  rX   rj  rk  r^   r  rC   r  r  r  r  rt  r  r\   ry  r#  rC  rq  r  r  unifiedTyper|  rT  r~  filtersByTypeentryfilters#                                      r=  fetch_marketszaster.fetch_marketsr  s    ,,V44,,V44
 ^^GQ33
>>*i<<^^GQ33
>>*i<<  844d yq#d))$$ q	! q	!AD!WF!!&(33B%%fk::F&&v|<<G**622D++G44E++FNCCL#4/HD{**LFGCZ%'FFH j++FMBB00:: 3#c\F2F5 D.#11&.&RVRcRcdgRhRhiiK %$ %$%%fh77Fy(FnnVY;;G MM'<@@M.. 40b40&40 40 	40
 &40 &40 740 H40 40 40 %40 40 %40 %40 &40  H!40" &#40$ #i1i1 ,"&""//0D0DTEUEUV\^qErEr0s0stt!..t/C/CDDTDTU[]mDnDn/o/opp --d.B.B4CSCSTZ\pCqCq.r.rss!..t/C/CDDTDTU[]mDnDn/o/opp	   $#! !
  $# 
  $# 
  $#  $  ,,V]CCg40 40 40 4 4Ej ..~rJJ++FJ??++FJ??, ,h( /3.>.>vz.R.Rk"7+]**z2FF/3/?/?
/S/Sk"8,++FH==++FH==- -h) !M117H"MM++FH==++FH==- -h) -//Z=5P5P))-UWXX151A1A&*1U1Uh'.MM%    r>  c                 X    |                      |          }|                     |d          S )a|  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#check-server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        
serverTime)fapiPublicGetV1Timer  )r;  rb  responses      r=  
fetch_timezaster.fetch_timeM  s/     ++F33   <888r>  r  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r*              )r  r  )r;  ohlcvr  s      r=  parse_ohlcvzaster.parse_ohlcv^  s    $ eQ''UA&&UA&&UA&&UA&&UA&&
 	
r>  r  rq  sincelimitc                 v   |t          | j        dz             |                                  |                     |          }i }|||d<   ||dk    rd}||d<   |                     d||          \  }}|                     | j        ||          |d<   |                     |d          }|d	k    }	|d
k    }
|                     |d          }d}|	r5|d         |d<   |                     | 	                    ||                    }n|
r5|d         |d<   | 
                    | 	                    ||                    }nf|d         |d<   |d         r*|                     | 	                    ||                    }n)|                     | 	                    ||                    }|                     |||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-data

        :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 str [params.price]: "mark" or "index" for mark price and index price candles
        :param int [params.until]: the latest time in ms to fetch orders for
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nz( fetchOHLCV() requires a symbol argument	startTimei  r  endTimeintervalr  markindexrC   rq  pairr#  )r(   rC   load_marketsr  handle_until_optionr_  r  omitfapiPublicGetV1MarkPriceKlinesextendfapiPublicGetV1IndexPriceKlinesfapiPublicGetV1KlinessapiPublicGetV1Klinesparse_ohlcvs)r;  rq  	timeframer  r  rb  r  requestr  isMarkisIndexr  s               r=  fetch_ohlcvzaster.fetch_ohlcvx  s     >#DG.X$XYYYV$$#(GK t||$GG229gvNN"..t	9UU
  116/G#67++ 	T &tGH::4;;wPV;W;WXXHH 	T$TlGFO;;DKKQW<X<XYYHH &tGHh T55dkk'66R6RSS55dkk'66R6RSS&   69eUKKKr>  tradec                    |                      |d          }|d         }|                      |d          }|                     |          }|                      |d          }|                      |d          }|                     |dd          }	|                     |d          }
|                     |d	          }|                     |d
          }d }||rd
nd}|                     |d          }||rdnd}|                     |||
|                     |
          ||                      |d          d |||||	|                     t          j
        |                      |d                              |dd|          S )NrC   rq  commissionAssetqtyr  quoteQtybaseQtytimesider  r  isBuyerMakersellbuyorderId
commission)r  rl  )rC   rR  	timestampdatetimerq  orderr?  r  takerOrMakerr  rO  r  rU  )r_  r`  safe_string_2r  safe_string_lower	safe_bool
safe_tradeiso8601r:  r>   
string_abs)r;  r  r  rC   rq  rm  currencyCodeamountStringpriceString
costStringr  r  isMakerr  r  s                  r=  parse_tradezaster.parse_trade  s   R eT**!%%e->??
..z::''u55&&ug66''z9EE
%%eV44	%%eV44..00&-:777L~~e^<<#)466uD"Y//%%eY77( "))'*<T=M=MeUa=b=b*c*cdd(  
  
" #  	r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}||dk    rd}||d<   d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#recent-trades-list
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#recent-trades-list

        :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>`
        Nz) fetchTrades() requires a symbol argumentrq  rC     r  r^   )r(   rC   r  r  fapiPublicGetV1Tradesr  sapiPublicGetV1Tradesparse_tradesr;  rq  r  r  rb  r  r  r  s           r=  fetch_tradeszaster.fetch_trades  s     >#DG.Y$YZZZV$$fTl
 t||$GG&> 	P11$++gv2N2NOOHH 11$++gv2N2NOOH   65%@@@r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   ||dk    rd}||d<   |                     d||          \  }}d}|d	         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |||||          S )
a  
        fetch all trades made by the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#account-trade-history-user_data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#account-trade-list-user_data

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms for the ending date filter, default is None
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentrq  rC   r  r  r  r  r^   )	r(   rC   r  r  r  fapiPrivateGetV1UserTradesr  sapiPrivateGetV1UserTradesr  r  s           r=  fetch_my_tradeszaster.fetch_my_trades;  s    >#DG.[$[\\\V$$fTl
 #(GK t||$GG229gvNN&> 	U66t{{7F7S7STTHH66t{{7F7S7STTH*   65%HHHr>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}||dk    rd}||d<   d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |d          }|                     |||d	d
          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#depth-information
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#order-book

        :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
        Nz, fetchOrderBook() requires a symbol argumentrq  rC   r  r  r^   Tbidsasks)	r(   rC   r  r  fapiPublicGetV1Depthr  sapiPublicGetV1Depthr  parse_order_book)r;  rq  r  rb  r  r  r  r  s           r=  fetch_order_bookzaster.fetch_order_bookr  s     >#DG.\$\]]]V$$fTl
 t||$GG&> 	O00Wf1M1MNNHH00Wf1M1MNNH( %%h44	$$Xvy&&QQQr>  c           
         |                                   i }| |                     |          }|d         |d<   |||d<   ||dk    rd}||d<   |                     d||          \  }}|                     |                     ||                    }g }t          dt          |                    D ]}	||	         }
|                     |
d	          }|                    |
| 	                    | 
                    |
d          ddd
          |                     |
d          ||                     |          d           |                     |d          }|                     ||||          S )a  
        fetches historical funding rate prices

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-funding-rate-history

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest funding rate
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        NrC   rq  r  r  r  r  r   fundingTimer^   fundingRate)rR  rq  r  r  r  r  )r  r  r  fapiPublicGetV1FundingRater  r]  r^  r  r  safe_symbolr_  r  r  sort_byfilter_by_symbol_since_limit)r;  rq  r  r  rb  r  r  r  ratesrk  r  r  sorteds                r=  fetch_funding_rate_historyz aster.fetch_funding_rate_history  s    	[[((F &tGH#(GK t||$GG229gvNN224;;w3O3OPP q#h--(( 		 		AQKE))%??ILL**4+;+;E8+L+LdTXZ`aa#//}EE& LL33      e[1100NNNr>  tickerc           	      v   |                      |d          }d }d|v rd}nd}|                     |d          }|                     ||d |          }|d         }|                     |d          }|                     |d          }|                     |d          }	t          j        |	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!|          S )"N	closeTimebidQtyr\   r  rq  	lastPrice	openPricepriceChangePercent100quoteVolumevolume	highPricelowPricer  r  highlowbidbidPrice	bidVolumeaskaskPrice	askVolumeaskQtyvwapopencloselastpreviousClosechanger  average)
baseVolumer  	markPrice
indexPricerR  )r  r_  safe_marketr>   
string_mulsafe_tickerr  )r;  r  r  r  
marketTypemarketIdrq  r#  r!  r  r  r'  r  r  s                 r=  parse_tickerzaster.parse_ticker  sj   ^ %%fk::	
vJJ#J##FH55!!(FD*EE!4444%%f.BCC
'
E::
&&v}==%%fh77
44vz22 !
f!
!
 Y//!
 D	!

 3!
 4##FJ77!
 ))&(;;!
 4##FJ77!
 ))&(;;!
 D!
 D!
 T!
 D!
 T!
 d!
  *!!
" t#!
$ %&-!
 !
 !
. /  	r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||          S )ap  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#24h-price-change
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics

        :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>`
        Nz) fetchTicker() requires a symbol argumentrq  rC   r^   )r(   rC   r  r  fapiPublicGetV1Ticker24hrr  sapiPublicGetV1Ticker24hrr/  r;  rq  rb  r  r  r  s         r=  fetch_tickerzaster.fetch_ticker/  s     >#DG.Y$YZZZV$$fTl
 &> 	T55dkk'66R6RSSHH, 55dkk'66R6RSSH2   6222r>  rp  c                    |                                   |                     |dddd          }|                     |          }d}|                     d||          \  }}d}|                     d||          \  }}d}|                     ||          r|                     |          }n9|dk    r|                     |          }nt          | j	        dz   |z   dz             | 
                    ||          S )aI  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#24h-price-change
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics

        :param str[] 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
        :param str [params.subType]: "linear" or "inverse"
        :param str [params.type]: 'spot', 'option', use params["subType"] for swap and future markets
        :returns dict: an array of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        NTr   r\   z! fetchTickers() does not support  markets yet)r  market_symbolsget_market_from_symbolshandle_market_type_and_paramshandle_sub_type_and_paramsrH  r1  r2  r4   rC   parse_tickers)r;  rp  rb  r  r?  r@  r  s          r=  fetch_tickerszaster.fetch_tickerst  s    	%%gtT4FF--g6699.&RXYYf99.&RXYY>>$(( 	f55f==HHV^^55f==HHtw)LLtSVddeee. !!(G444r>  c                 v   |                      |d          }|                     |d          }|                     |d          }|                      |d          }d }||dz   }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|iS )Nrq  nextFundingTimer  fundingIntervalHourshrR  r  r(  r)  interestRateestimatedSettlePricer  r  r  lastFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r_  r  r  r  r  )r;  r  r  r.  rG  r  r  intervalStrings           r=  parse_funding_ratezaster.parse_funding_rate  s   * ##Hh77#00;LMM%%h77	##H.DEE%^N
H
d&&xzJJ
 ))(K@@
 $**8\BB	

 D,,X~FF
 #D$4$4X?U$V$V
 
 Y//
 4++H6GHH
 
 t
 t
 #$8
 "4<<0D#E#E
 "4
  '!
" &t#
$ %
 
 	
r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a  
        fetch the current funding rate

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#mark-price

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        Nz. fetchFundingRate() requires a symbol argumentrq  rC   )r(   rC   r  r  fapiPublicGetV1PremiumIndexr  rM  r3  s         r=  fetch_funding_ratezaster.fetch_funding_rate  s     >#DG.^$^___V$$fTl
 33DKK4P4PQQ &&x888r>  c                     |                                   |                     |          }|                     |                     |                    }|                     ||          S )a  
        fetch the current funding rate for multiple symbols

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        )r  r7  rO  r  parse_funding_ratesr;  rp  rb  r  s       r=  fetch_funding_rateszaster.fetch_funding_rates  s`     	%%g..33DKK4G4GHH ''':::r>  c                     |                                   ||                     |          }|                     |          }|                     ||          S )a  
        fetch the funding rate interval for multiple markets

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-funding-rate-config

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        )r  r7  fapiPublicGetV1FundingInforR  rS  s       r=  fetch_funding_intervalszaster.fetch_funding_intervals  sZ     	))'22G226:: ''':::r>  c                    d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |dd          |d<   |                     |d          |d<   |                     |d          |d	<   |||<   |                     |          S )
NrR  r   rK  freemaxWithdrawAmountlockedusedwalletBalancetotal)r]  r^  r_  r`  accountr  safe_balance)r;  r  rj  rk  balancerm  rS  r_  s           r=  parse_balancezaster.parse_balance1  s    )q#h--(( 	# 	#AqkG))'7;;J**:66DllnnG"00&BUVVGFO"..wAAGFO#//IIGG"F4LL  (((r>  c                    d}|                      dd|          \  }}d}|                     dd|          \  }}d}d}|                     ||          r-|                     |          }|                     |dg           }nP|dk    r-|                     |          }|                     |dg           }nt          | j        dz   |z   dz             |                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#account-information-v4-user_data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#account-information-user_data

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.subType]: "linear" or "inverse"
        :param str [params.type]: 'spot', 'option', use params["subType"] for swap and future markets
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr   rJ  r\   balancesz! fetchBalance() does not support r6  )	r9  r:  rH  fapiPrivateGetV4Accountr[  sapiPrivateGetV1Accountr4   rC   rb  )r;  rb  r?  r@  r  datas         r=  fetch_balancezaster.fetch_balance>  s     99.$PVWWf99.$PVWW>>$(( $	f33F;;H>>(Hb99DD* V^^33F;;H>>(J;;DD tw)LLtSVddeee!!$'''r>  
marginModec                 p   |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  |                     |          }|d         |d}|                     |                     ||                    }|S )	a  
        set margin mode to 'cross' or 'isolated'

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-margin-type-trade

        :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 argumentCROSSCROSSEDISOLATEDz, marginMode must be either isolated or crossrC   )rq  
marginType)r(   rC   upperr)   r  r  fapiPrivatePostV1MarginTyper  )r;  ri  rq  rb  r  r  r  s          r=  set_margin_modezaster.set_margin_modew  s     >#DG.[$[\\\%%''
  "J*$$:+B+BTW'UUVVVV$$Tl$
 
 33DKK4P4PQQ r>  c                 f    |                      |          }|                     |d          }||du dS )a  
        fetchs the position mode, hedged or one way, hedged for aster is set identically for all linear markets or all inverse markets

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-current-position-modeuser_data

        :param str symbol: unified symbol of the market to fetch the order book for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        dualSidePositionT)rR  hedged) fapiPrivateGetV1PositionSideDualr  )r;  rq  rb  r  rs  s        r=  fetch_position_modezaster.fetch_position_mode  sH     88@@  >>(4FGG'4/
 
 	
r>  rt  c                 \    d|i}|                      |                     ||                    S )a  
        set hedged to True or False for a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-position-modetrade

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by bingx setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        rs  )!fapiPrivatePostV1PositionSideDualr  )r;  rt  rq  rb  r  s        r=  set_position_modezaster.set_position_mode  s4     
 55dkk'66R6RSSSr>  rU  c                     |                      |d          }|                     ||          }|                     ||          }|||                     |d          |                     |d          dddS )Nrq  makerCommissionRatetakerCommissionRateF)rR  rq  r  r  r  r  )r_  r*  r  r  )r;  rU  r  r.  rq  s        r=  parse_trading_feezaster.parse_trading_fee  s    ##C22!!(F33!!(F33%%c+@AA%%c+@AA
 
 	
r>  c                 N   |                                   |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||          S )a  
        fetch the trading fees for a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#get-symbol-fees
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#user-commission-rate-user_data

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rq  rC   Nr^   )r  r  fapiPrivateGetV1CommissionRater  sapiPrivateGetV1CommissionRater}  r3  s         r=  fetch_trading_feezaster.fetch_trading_fee  s     	V$$fTl
 &> 	Y::4;;wPV;W;WXXHH::4;;wPV;W;WXXH %%h777r>  r|  c                 B    ddddddd}|                      |||          S )Nr!  closedcanceled)NEWPARTIALLY_FILLEDFILLEDCANCELEDREJECTEDEXPIREDr_  )r;  r|  statusess      r=  parse_order_statuszaster.parse_order_status  s:     &""!
 
 &&999r>  c                 D    dddddddd}|                      |||          S )Nr  r  )LIMITMARKETSTOPSTOP_MARKETTAKE_PROFITTAKE_PROFIT_MARKETTRAILING_STOP_MARKETr  )r;  r?  typess      r=  parse_order_typezaster.parse_order_type  s=    #""*$,
 
 tT222r>  r  c                    |}|                      |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|          S )Nrq  r  r  
updateTimer|  r?  	stopPricerR  rC   r  clientOrderIdr  r  lastTradeTimestamplastUpdateTimestamptimeInForcepostOnlyr  triggerPricer&  avgPricer  cumQuoterO  origQtyexecutedQty
reduceOnlyro)filled	remainingr|  rU  tradesr  )r_  r*  r  r  safe_string_upperr:  	omit_zero
safe_orderr  r  r  r  safe_bool_2)r;  r  r  rR  r.  r  r  r  statusIdrawTypestopPriceStringr  s               r=  parse_orderzaster.parse_order  s   ` ##E844!!(F33%%eV44%%eV44	!..ulCC))%::((77**5+>>(()H)HII  
D 
$""5)44 
 T--e_EE 
 d&&x88	 

  
 Y// 
 !"4 
 "4#4#4UL#I#I 
 D))'22 
 4++E=AA 
  
 D 
 T%%eW55 
 L 
 t''z:: 
  D$$UJ77! 
" d&&ui88# 
$ &&um<<--h77**5,EE/ 
  
  
0 1  	r>  rC   c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   d}|d	         r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    ||          S )
a  
        fetches information on an order made by the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#query-order-user_data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#query-order-user_data

        :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
        :param str [params.clientOrderId]: a unique id for the order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentrq  rC   r  	clientOidorigClientOrderIdr  r^   )
r(   rC   r  r  r  r  fapiPrivateGetV1Orderr  sapiPrivateGetV1Orderr  r;  rC   rq  rb  r  r  r  r  s           r=  fetch_orderzaster.fetch_order\  s    >#DG.X$XYYYV$$fTl
 **6?KPP6O[#ABB$+8G'((!#GI&> 	P11$++gv2N2NOOHH11$++gv2N2NOOH&111r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   |                     |                     ||                    }|                     ||          S )	a  
        fetch an open order by the id

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#query-current-open-order-user_data

        :param str id: order id
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz, fetchOpenOrder() requires a symbol argumentrq  rC   r  r  r  r  )	r(   rC   r  r  r  r  fapiPrivateGetV1OpenOrderr  r  r  s           r=  fetch_open_orderzaster.fetch_open_order}  s     >#DG.\$\]]]V$$fTl
 **6?KPP6O[#ABB$+8G'((!#GI11$++gv2N2NOO&111r>  c                    |                                   |t          | j        dz             |                     |          }d|d         i}|||d<   ||dk    rd}||d<   |                     d||          \  }}d}|d	         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          S )
a  
        fetches information on multiple orders made by the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#query-all-orders-user_data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#all-orders-user_data

        :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>`
        Nz) fetchOrders() requires a symbol argumentrq  rC   r  r  r  r  r^   )	r  r(   rC   r  r  fapiPrivateGetV1AllOrdersr  sapiPrivateGetV1AllOrdersparse_ordersr  s           r=  fetch_orderszaster.fetch_orders  s    	>#DG.Y$YZZZV$$fTl
 #(GK t||$GG229gvNN&> 	T55dkk'66R6RSSHH55dkk'66R6RSSH  65%@@@r>  c                 4   |                                   i }d}d}d}|                     d||          \  }}| |                     |          }|d         |d<   |                     d||          \  }}d}	|                     ||          r*|                     |                     ||                    }	nM|dk    r*|                     |                     ||                    }	nt          | j	        dz   |z   dz             | 
                    |	|||          S )aT  
        fetch all unfilled currently open orders

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#current-open-orders-user_data
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#current-all-open-orders-user_data

        :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
        :param str [params.subType]: "linear" or "inverse"
        :param str [params.type]: 'spot', 'option', use params["subType"] for swap and future markets
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   rC   rq  r\   z$ fetchOpenOrders() does not support r6  )r  r:  r  r9  rH  fapiPrivateGetV1OpenOrdersr  sapiPrivateGetV1OpenOrdersr4   rC   r  )
r;  rq  r  r  rb  r  r  r?  r@  r  s
             r=  fetch_open_orderszaster.fetch_open_orders  s2    	99:KVU[\\[[((F &tGH99:KVU[\\f>>$(( 	i66t{{7F7S7STTHHV^^66t{{7F7S7STTHHtw)OORVVYgghhh<   65%@@@r>  r  rO  r  c                    |                                   |                     |          }|                     |dd          }|                     |d          }|                     ||||||          }	d}
|d         r.|r|                     |	          }
n+|                     |	          }
n|                     |	          }
|                     |
|          S )aH  
        create a trade order

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#place-order-trade
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#new-order--trade

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'STOP' or 'STOP_MARKET' or 'TAKE_PROFIT' or 'TAKE_PROFIT_MARKET' or 'TRAILING_STOP_MARKET'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of you want to trade in units of the base currency
        :param float [price]: the price that 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.reduceOnly]: for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to True or in hedge mode. For spot margin and option reduceOnly is a boolean.
        :param boolean [params.test]: whether to use the test endpoint or not, default is False
        :param float [params.trailingPercent]: the percent to trail away from the current market price
        :param float [params.trailingTriggerPrice]: the price to trigger a trailing order, default uses the price argument
        :param str [params.positionSide]: "BOTH" for one-way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
        :param float [params.triggerPrice]: the price that a trigger order is triggered at
        :param float [params.stopLossPrice]: the price that a stop loss order is triggered at
        :param float [params.takeProfitPrice]: the price that a take profit order is triggered at
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        testFNr^   )	r  r  r  r  create_order_requestfapiPrivatePostV1OrderTestfapiPrivatePostV1OrdersapiPrivatePostV1Orderr  )r;  rq  r?  r  rO  r  rb  r  r  r  r  s              r=  create_orderzaster.create_order  s    . 	V$$~~ffe4466**++FD$vVV&> 	< @::7CC66w??227;;H&111r>  ordersc           	         |                                   g }g }t          |          dk    rt          | j        dz             t	          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d	i           }|                     |||	|
||          }|	                    |           | 
                    |d
ddd          }|                     |d                   }|d         r#t          | j        dz   |d         z   dz             d|i}|                     |                     ||                    }|                     |          S )a  
        create a list of trade orders

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#place-multiple-orders--trade

        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  z' createOrders() order list max 5 ordersr   rq  r?  r  rO  r  rb  NFTr\   z! createOrders() does not support  ordersbatchOrders)r  r^  r/   rC   r]  r_  
safe_valuerZ  r  r  r7  r  r4   fapiPrivatePostV1BatchOrdersr  r  )r;  r  rb  ordersRequestsorderSymbolsrk  rawOrderr.  r?  r  rO  r  orderParamsorderRequestr  r  r  s                    r=  create_orderszaster.create_orders   s    	v;;??tw)RRSSSq#f++&& 		0 		0AayH''(;;H##Hf55D##Hf55D__Xx88FOOHg66E..8R@@K44XtT6SXZeffL!!,////**<udDQQ\!_--&> 	ktw)LLvV\~]`iijjj>
 44T[[&5Q5QRR  ***r>  c                    |                      |          }|                                }|dk    }	|dk    }
|d         |                                d}|                     |dd          }|||d<   |                     |dd	          }|                     |d
|          }|                     |d          }|                     |d          }|                     |dd          }|                     |g d          }|du}|dup|du}|du}|}d}|r+|d         r"d}||d<   ||                     ||          |d<   n|r|}|	rd}n|
rd}n|r|}|	rd}n|
rd}|                     |	d|          }|rd|d<   |                     |dd          }d}d}d}d}||d<   |dk    r|d         r|                     | j        dd          }|r|                     |dd          }|d          d!         } |&| 	                    |t          | | j                  |d<   n|e|                     |          }!|                     |          }"t          j        |!|"          }#| 	                    |#t          | | j                  |d<   nbd}n_d}n\d}nY|dk    rd}d}d}nL|dk    s|dk    rd}d}d}n9|dk    s|dk    r|sd}d}n&|dk    r ||d<   ||                     ||          |d<   |rT|                     |d          d"          }$|$du}%|%r|                     ||          |d#<   n|                     |          |d#<   |rs|t#          | j        d$z   |z   d%z             |                     |d          d!          }&|&du}'|'r|                     ||          |d!<   n|                     |          |d!<   |r:|t#          | j        d&z   |z   d%z             ||                     ||          |d	<   |rJ|                     |d          4|                     |d          |                     | j        d'          |d<   |                     |g d(          }(|                     ||(          S ))aL  
 @ignore
        helper function to build the 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 that 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
        :returns dict: request to be sent to the exchange
        r  r  rC   )rq  r  newClientOrderIdr  Nr  r  stopLossPricetakeProfitPricetrailingDeltatrailingTriggerPriceactivationPrice)trailingPercentcallbackRater  r^   r  r  r  r  r  r  GTXr  rh   Fr?  r\   r0  Tr  rV  r  rO  quantityz/ createOrder() requires a price argument for a z orderz6 createOrder() requires a stopPrice extra param for a r.  )
r  r  r  r  r  r  r  r  r  r  )r  ro  r  r_  safe_string_nprice_to_precisionis_post_onlyr  r  decimal_to_precisionr<   r  number_to_stringr>   r+  amount_to_precisionparse_to_numericr/   rC   r  r  ))r;  rq  r?  r  rO  r  rb  r  initialUppercaseTypeisMarketOrderisLimitOrderr  r  r  r  r  r  r  r  isTrailingPercentOrder
isStopLossisTakeProfituppercaseTyper  r  rh   timeInForceIsRequiredpriceIsRequiredtriggerPriceIsRequiredquantityIsRequiredr0  quoteOrderQtyNewrV  r  r  quoteOrderQuantitymarketAmountPrecisionisPrecisionAvailabler  isPricePrecisionAvailablerequestParamss)                                            r=  r  zaster.create_order_requestC  s    V$$#zz||,8+w6TlJJLL
 
 **63EWW$*7G&'))&.+NN((,OO**63DEE((AA#11&:PRcdd,,V5i5i5ijj!0!<"$.K-t2K
&d2,	! 	.f~ g 6*9''3151H1HQe1f1fG-. 	.%I ' - ' & 	.'I . 4 . -$$]D&AA 	+%*GM" vFF %!&"'H$$f~ * $t|_d S S  .'+'9'9&/SY'Z'Z$ &{ 3G <I'3373L3LM]_girtx  uG  4H  4H00*'+'<'<V'D'D&*&;&;E&B&B-4-?k-Z-Z*373L3LM_aiktvz  wI  4J  4J00-1**)-&&%)""g%%$(!!%"OOv%%=M+I+I!%"O%)""},,-CW2W2W  *%)"%)""444&5GN##/-1-D-DVMa-b-b)* 	D$($4$4VK5H($S$S!$9$E # D&*&>&>vv&N&N
##&*&;&;F&C&C
# 	@}"47-^#^ae#ehp#pqqq!--f[.A7KKN)7t)C%( @#'#:#:65#I#I  #'#8#8#?#? ! 	R "47-e#ehl#low#wxxx$'+'>'>vy'Q'Q$  	Zd&6&6v}&M&M&U\`\l\lmt  wD  ]E  ]E  ]M%)%5%5dlDX%Y%YGM"		&  +Z  +Z  +Z  [  [{{7M222r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }|                     d|i          gS )a%  
        cancel all open orders in a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#cancel-all-open-orders-trade
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-all-open-orders-trade

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- cancelAllOrders() requires a symbol argumentrq  rC   r^   rR  )r(   rC   r  r   fapiPrivateDeleteV1AllOpenOrdersr   sapiPrivateDeleteV1AllOpenOrdersr  r3  s         r=  cancel_all_orderszaster.cancel_all_orders  s     >#DG.]$]^^^V$$fTl
 &> 	[<<T[[RX=Y=YZZHH<<T[[RX=Y=YZZH OO  
 	
r>  c                    |t          | j        dz             |                                  |                     |          }d|d         i}|                     |g d          }|||d<   n||d<   |                     |g d          }d}|d         r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    ||          S )	a  
        cancels an open order

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#cancel-order-trade
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-order-trade

        :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 argumentrq  rC   )r  r  newClientStrategyIdr  r  r^   )
r(   rC   r  r  r  r  fapiPrivateDeleteV1Orderr  sapiPrivateDeleteV1Orderr  r  s           r=  cancel_orderzaster.cancel_order  s    >#DG.Y$YZZZV$$fTl
 **63p3p3pqq$+8G'((!#GI6#`#`#`aa&> 	S44T[[&5Q5QRRHH44T[[&5Q5QRRH&111r>  idsc                    |t          | j        dz             |                                  |                     |          }|d         r#t	          | j        dz   |d         z   dz             d|d         i}|                     |d	          }|||d	<   n||d
<   |                     |                     ||                    }|                     ||          S )a  
        cancel multiple orders

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-multiple-orders-trade

        :param str[] ids: order ids
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint

 EXCHANGE SPECIFIC PARAMETERS
        :param str[] [params.origClientOrderIdList]: max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
        :param int[] [params.recvWindow]:
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz* cancelOrders() requires a symbol argumentr\   z! cancelOrders() does not support r?  r  rq  rC   origClientOrderIdListorderIdList)	r(   rC   r  r  r4   r[  fapiPrivateDeleteV1BatchOrdersr  r  )r;  r  rq  rb  r  r  clientOrderIdListr  s           r=  cancel_orderszaster.cancel_orders	  s     >#DG.Z$Z[[[V$$&> 	ktw)LLvV\~]`iijjjfTl
 !NN63JKK(/@G+,,%(GM"66t{{7F7S7STTB   6222r>  r  c                 8   |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  |                     |          }|d         |d}|                     |                     ||                    }|S )a  
        set the level of leverage for a market

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-initial-leverage-trade

        :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*  }   z% leverage should be between 1 and 125rC   )rq  r  )r(   rC   r)   r  r  fapiPrivatePostV1Leverager  )r;  r  rq  rb  r  r  r  s          r=  set_leveragezaster.set_leverageN	  s     >#DG.Y$YZZZqLLhnnTW'NNOOOV$$Tl 
 
 11$++gv2N2NOO r>  c                     |                                   |                     |          }|                     ||d          S )a  
        fetch the set leverage for all markets

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data

        :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>`
        rq  )r  fapiPrivateGetV2PositionRiskparse_leveragesrS  s       r=  fetch_leverageszaster.fetch_leveragesm	  sC     	44V<<, ##Hgx@@@r>  c                 .   |                      |d          }|                     |d          }|                     |d          }d }d }|                     |d          }||dk    r|}|}n|dk    r|}n|dk    r|}||                     ||          |||dS )	Nrq  rn  positionSider  bothlongshort)rR  rq  ri  longLeverageshortLeverage)r_  r  r  r  )	r;  r  r  r.  ri  r  r  r  leverageValues	            r=  parse_leveragezaster.parse_leverage	  s    ( ##Hh77++HlCC
%%h??))(J??Ldfnn(L)MMV^^(LLW__)M&&x88$(*
 
 	
r>  c                     |                                   |                     |          }|                     ||dd          S )a  
        fetches margin mode of the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data

        :param str[] symbols: 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>`
        rq  r^   )r  r  parse_margin_modesrS  s       r=  fetch_margin_modeszaster.fetch_margin_modes	  sE     	44V<<0 &&x(FKKKr>  c                     |                      |d          }|                     ||          }||d         |                     |d          dS )Nrq  rn  )rR  rq  ri  )r_  r*  r  )r;  ri  r  r.  s       r=  parse_margin_modezaster.parse_margin_mode	  s[    ( ##J99!!(F33X&00\JJ
 
 	
r>  c                    |                                   |t          | j        dz             |                     |          }|                     |d          }|                     |d          }d|d         i}||dk    rdnd|d	<   |||d
<   |||d<   |||d<   |                     |                     ||                    }	|                     |	          }
| 	                    |
|||          S )a  
        fetches the history of margin added or reduced from contract isolated positions

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-position-margin-change-history-trade

        :param str symbol: unified market symbol
        :param str [type]: "add" or "reduce"
        :param int [since]: timestamp in ms of the earliest change to fetch
        :param int [limit]: the maximum amount of changes to fetch
        :param dict params: extra parameters specific to the exchange api endpoint
        :param int [params.until]: timestamp in ms of the latest change to fetch
        :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        Nz: fetchMarginAdjustmentHistory() requires a symbol argumentuntilrq  rC   addr*  r  r?  r  r  r  )
r  r(   rC   r  r  r  %fapiPrivateGetV1PositionMarginHistoryr  parse_margin_modificationsr  )r;  rq  r?  r  r  rb  r  r"  r  r  modificationss              r=  fetch_margin_adjustment_historyz%aster.fetch_margin_adjustment_history	  s    	>#DG.j$jkkkV$$!!&'2267++fTl
 $(EMMaaGFO#(GK $GG!&GI==dkk'SY>Z>Z[[ 77AA00uUUUr>  rg  c                    |                      |d          }|                     |d          }|                     |d          }|                      |d          }|                     ||d d          }|d u }|dk    }||d         |dk    rdnd	d
|                     |d          |                     |d          d |s|rdnd||                     |          d
S )Nr?  rS  rq  r  r^   200r*  r#  reduceisolatedrO  rK  okfailed)
rR  rq  r?  ri  rO  rS  r^  r|  r  r  )r  r_  r*  r  r  )	r;  rg  r  r  	errorCoder.  r  noErrorCodesuccesss	            r=  parse_margin_modificationzaster.parse_margin_modification)
  s    $ ##D&11$$T622	##D(33%%dF33	!!(FD&AA4'u$X&%llEE$&&tX66$$T733&D+DddH"Y//
 
 	
r>  c                 R   |                                   |                     |          }|                     ||          }||d         |d}|d         }|                     |                     ||                    }|                     |                     ||          d|i          S )NrC   )r?  rq  rO  r  rS  )r  r  r  fapiPrivatePostV1PositionMarginr  r1  )	r;  rq  rO  addOrReducerb  r  r  rS  r  s	            r=  modify_margin_helperzaster.modify_margin_helperO
  s    V$$))&&99Tl
 

 g77GV8T8TUU {{499(FKKDN
   	r>  c                 2    |                      ||d|          S )a  
        remove margin from a position

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#modify-isolated-position-margin-trade

        :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  r5  r;  rq  rO  rb  s       r=  reduce_marginzaster.reduce_marginf
       ((FCCCr>  c                 2    |                      ||d|          S )a  
        add margin

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#modify-isolated-position-margin-trade

        :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>`
        r*  r7  r8  s       r=  
add_marginzaster.add_margins
  r:  r>  c           
      b   |                      |d          }|                      |d          }|                     |d          }||                     ||d d          |                     |          ||                     |          |                      |d          |                     |d          dS )Nrq  rK  r  r^   tranIdincome)rR  rq  rS  r  r  rC   rO  )r_  r  r  r`  r  r  )r;  r?  r  r.  rm  r  s         r=  parse_incomezaster.parse_income
  s     ##FH55%%fg66
%%ff55	&&xvFF++J77"Y//""6844&&vx88
 
 	
r>  c                 h   |                                   d}ddi}| |                     |          }|d         |d<   |                     d||          \  }}|||d<   |t          |d          |d	<   |                     |                     ||                    }|                     ||||          S )
a  
        fetch the history of funding payments paid and received on self account

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-income-historyuser_data

        :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 int [params.until]: timestamp in ms of the latest funding history entry
        :param boolean [params.portfolioMargin]: set to True if you would like to fetch the funding history for a portfolio margin account
        :param str [params.subType]: "linear" or "inverse"
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        N
incomeTypeFUNDING_FEErC   rq  r  r  r  r  )r  r  r  rM  fapiPrivateGetV1Incomer  parse_incomesr  s           r=  fetch_funding_historyzaster.fetch_funding_history
  s     	-
 [[((F &tGH229gvNN#(GK "5$//GG..t{{7F/K/KLL!!(FE5AAAr>  itemrl  c                 z   |                      |d          }d }t          j        |d          rd}t          j        d|          }nd}|                      |d          }|                     ||          }|                     ||          }|                     |d          }|                      |d          }|                     ||                      |d	          |d d |                      |d
          |                     |          || 	                    |          || 
                    |          d d d d d|          S )Nr?  0out-1inrK  r  rB  r>  tradeId)rR  rC   	directionr_  referenceAccountreferenceIdr?  rl  rO  r  r  beforeafterr|  rU  )r_  r>   	string_ler+  r`  safe_currencyr  safe_ledger_entryparse_ledger_entry_typer:  r  )	r;  rG  rl  rO  rN  rm  rS  r  r?  s	            r=  parse_ledger_entryzaster.parse_ledger_entry
  sV    !!$11	VS)) 	I'f55FFI%%dG44
&&z8<<%%j(;;%%dF33	l33%%""422" $++D)<<0066''//"Y//'
 '
  !  	r>  c                 D    dddddddd}|                      |||          S )Nr   cashbackr  rU  r  
settlement)TRANSFERWELCOME_BONUSREALIZED_PNLrC  
COMMISSIONINSURANCE_CLEARMARKET_MERCHANT_RETURN_REWARDr  )r;  r?  
ledgerTypes      r=  rV  zaster.parse_ledger_entry_type
  s=    "'# &+-7
 

 
D$777r>  rS  c                    |                                   d}||                     |          }i }|||d<   |t          |d          |d<   |                     |d          }||                     |d          }||d<   |                     |                     ||                    }|                     ||||          S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-income-historyuser_data

        :param str [code]: unified currency code
        :param int [since]: timestamp in ms of the earliest ledger entry
        :param int [limit]: max number of ledger entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest ledger entry
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Nr  r  r  r"  r  )r  rl  rM  r  r  rD  r  parse_ledger)	r;  rS  r  r  rb  rl  r  r"  r  s	            r=  fetch_ledgerzaster.fetch_ledger
  s     	}}T**H#(GK "5$//GG!!&'22YYvw//F!&GI..t{{7F/K/KLL   8UEBBBr>  c                 f   |                      |d          }|                     ||d d          }|                      |d          }|                      |d          }|                     | j        di           }|                     ||g           }|                     |dd          }t          j        |          }	d }
t          dt          |                    D ]/}||         }t          j
        |	|d                   r n	|d         }
0|                     |	          }t          j        |                      |d	                    }|                     |          }|                      |d
          }|                     |          }|                     |                      |d                    }|                     |          }d }|                      |d          }||t          j        |d          rdnd}d }t          j        |d          rd}nt          j
        |d          rd}|                      |d          }|                     |          }|                     |d          }|                     |          }d|v }|dk    r|                     |di           }|                      |d          }|                     |dd          }|d u o|d u }|s|rd } |}!|dk    r+t          j        d|
          } t          j        d|!          }!nt          j        d|
          } t          j        ||           }"t          j        |"|!          }#|                     |                     |dd                    }$|$)t          j        t          j        |#|          d|$          }nd } |}!|dk    rt          j        d|
          } n*t          j        d|
          } t          j        d|!          }!t          j        ||          }#t          j        t          j        d|!          t          j        | |                    }%|                     |                      |d                    }&|&)t          j        t          j        |#|%          d|&          }n|                      |d          }|dn|}|                     |          }'|                     |                     |                      |d                              }(|                     |d          })|)dk    rd })|                     |
          }*t          j        |
|	          }+|+|                      |d          }+|                     |+          },d }-d }.|                      |d          }/|/t/          |/          }0|                     d|0z            }1t          j        d|/d          }.|1st          j        |.d           }.t          j        |	|.          }2t          j        |2dd          }-nA|                      |d!          }-t          j        |-d          }2t          j        |2|	d          }.d }3d }4t          j        |d          s|                     t          j        t          j        t          j        |+|          d"          dd#                    }3|                     t          j        t          j        ||-d#          d$                    }4|                      |d%          }5|5d&k    }6|                     i d'|d(d d|d)|d|d*|d|                     |/          d|d+|'d|d|(d|d,|)d!|                     |-          d-|                     |.          d.|,d/|*|3|                     |)          |||6|4d d d0          S )1Nrq  r  isolatedMarginleverageBracketsr  notionalValuer   r*  positionAmtunRealizedProfitliquidationPricern  rI  crossr+  r  r  
entryPricery  rV  r  r  r  r{  rK  r(  r  maintMarginr  r     1e-8initialMargin5e-5r  r  r  BOTHrR  rC   	contractsunrealizedPnl
collateralr  initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage)marginRatior  ri  r  rt  r  r  r  )r_  r*  rZ  r  r[  r  r>   r  r]  r^  	string_ltr:  r  	string_eq	string_gtr  r  
string_addr+  precision_from_string
string_div
string_subr  intis_round_numberstring_equalssafe_positionr  )7r;  positionr  r.  rq  isolatedMarginStringrg  leverageBracketnotionalStringnotionalStringAbs!maintenanceMarginPercentageStringrk  bracketr  contractsAbsrt  unrealizedPnlStringru  liquidationPriceStringrk  collateralStringri  r  entryPriceStringrm  ry  contractSizeStringr#  rV  basePrecisionValuequotePrecisionValueprecisionIsUndefined(onePlusMaintenanceMarginPercentageStringentryPriceSignStringinnerleftSider  	rightSidebasePrecisionrv  r(  r  ry  maintenanceMarginStringrx  initialMarginStringinitialMarginPercentageStringleverageStringr  rational	unroundedrz  r  r  rt  s7                                                          r=  parse_position_riskzaster.parse_position_risk  s   $ ##Hh77!!(FD*EE!!&(33#//:JKK>>$,8JBOO..)962FF++Hj/RR#.~>>,0)q#o..// 	; 	;A%a(G !2GAJ?? 07
--$$%677)$*:*:8]*S*STT%%l33	"..x9KLL))*=>>!%0@0@K]0^0^!_!_,,-CDD%%h==
"6"B$+$56JC$P$P`V`J^S11 	DD~s33 	D++HlCC&&'788
v~>>!22<@@(  v{B??I!%!1!1)V!D!D"&"4"4Y"Q"Q$6$$>#aEX\`E` ' { {?C<+;(wCJCUVY[|C}C}@/6/A$H\/]/],,CJCUVZ\}C~C~@#./EGoppE&1%9MNNH%)%?%?@R@RS\^egn@o@o%p%pN%1+2+=g>PQY[g>h>hjmo}+~+~( @D<+;(wCJCUVY[|C}C}@@CJCUVZ\}C~C~@/6/A$H\/]/],&1,@RSSH ' 273EcK_3`3`bibt  v^  `v  cw  cw  !x  !xI$($>$>t?O?OPY[a?b?b$c$cM$0+2+=g>PQY[d>e>egjly+z+z(#//:JKK#3#;33BR&&'788
%%dnnT5E5EhP[5\5\&]&]^^	%%h==	>>I&*&7&78Y&Z&Z#")"45VXi"j"j"*&*&6&6x&O&O# --.EFF"(,%))(J??%>**H++D8O<<H,3,>sNTU,V,V) j070BC`bh0i0i-*+<>[\\I")"4YQ"G"G"&"2"28_"M"M*+>DDI,3,>yJ[]^,_,_)
$%5s;; 	G++G,>w?QRYRde|  O  SP  SP  RX  @Y  @Y  [^  `a  -b  -b  c  cK**7+=g>PQdfy{|>}>}  @E  ,F  ,F  G  GJ''.AA'!! #
H#
$#
 f#
 	#

 L#
 ]#
 )).99#
  0#
 *#
 #
 #
 *#
 #
 T../BCC#
 &t'8'89V'W'W#
   !2!#
" *+F##
$ 'Y//$$!#3#
 #
 #
   	r>  c                 h   |,t          |t                    st          | j        dz             |                                  |                     d|           i }|                     |                     ||                    }g }t          dt          |                    D ]c}||         }| 
                    |d          }t          j        |d          r.|                    |                     ||                              d|                     |          }|                     |d|d          S )ai  
        fetch positions risk

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: data on the positions risk
        Nz< fetchPositionsRisk() requires an array argument for symbolsFr   rm  rI  rq  )
isinstancelistr(   rC   r  load_leverage_bracketsr  r  r]  r^  r_  r>   r}  r  r  r7  filter_by_array_positions)	r;  rp  rb  r  r  rj  rk  rawPositionr  s	            r=  fetch_positions_riskzaster.fetch_positions_risk  s1    gt,, r'2p(pqqq##E622244T[[&5Q5QRR( q#h--(( 	E 	EA"1+K#//\JJ !1377 Ed66x{CCDDD%%g..--fhOOOr>  c                 `   d}|                      |dd          \  }}|<|                     | j        d          }||                     | j        dd          }nd}|dk    r|                     ||          S |dk    r|                     ||          S t          | j        dz   |z   dz             )a  
        fetch all open positions

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.method]: method name to call, "positionRisk", "account" or "option", default is "positionRisk"
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nr   methodpositionRiskr_  z<.options["fetchPositions"]["method"] or params["method"] = "z@" is invalid, please choose between "account" and "positionRisk")handle_option_and_paramsrZ  r  r_  r  fetch_account_positionsr4   rC   )r;  rp  rb  defaultMethodr  s        r=  fetch_positionszaster.fetch_positions  s      $ = =fFVX` a av nnT\3CDDG $ 0 0?OQ_ ` ` .N**,,Wf===i''//@@@tw)ggjww  {}   }  ~  ~  ~r>  Fc           	         |                      |d          }|                      |dg           }i }t          dt          |                    D ]|}||         }|                     |d          }|                     |          }	|                     |d          }
|                     |d          }t          j        |
|          |
d||	<   }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d d d	          }|d
         r|d         n|d         }	|                     |d          }|dk    o|dk    }|r|r^|	|v rZ|                     | 	                    |||	         d         ||	         d         d          |          }|
                    |           |S )N	positionsrJ  r   rK  crossWalletBalance
crossUnPnl)crossMarginr  rq  r  r#  r  r  rn  rI  z
0.00000000r  )r[  r]  r^  r_  r`  r>   r~  r*  parse_account_positionr  r  )r;  r_  filterClosedr  rJ  rd  rk  r  rm  rS  r  r  rj  r  r.  r  rx  isPositionOpenparseds                      r=  parse_account_positionszaster.parse_account_positions  s   NN7K88	266q#f++&& 		 		A1IE))%99J**:66D!%!1!1%9M!N!N))%>>J&12DjQQ&8 HTNN q#i..)) 	* 	*A |H''(;;H%%hdJGGF&,X&6J6'??F6ND $ 0 0= I I/36_=NR^=^N *> *8##!88X'/~m'D.6tn=Q.RP P : :    F MM&)))r>  c           
         |                      |d          }|                     ||d d          }|                      |d          }|                      |d          }|t          |          nd }|                      |d          }|                     |          }d }	|Yt	          j        d|d          }	|                     d|z            }
|
s)t	          j        t	          j        |	d          dd          }	d	|v }|                      |d
          }|                     |          }|                      |d          }|                     |          }|                     |d	d          }t	          j	        |          }|                     |          }|                      |d          }t	          j	        |          }||t	          j
        t	          j
        ||          |          }|                      |d          }t	          j        ||          }t	          j        t	          j        |d          dd          }|                     |          }|                     | j        di           }|                     ||g           }d }t          dt          |                    D ]/}||         }t	          j        ||d                   r n	|d         }0|                     |          }|                      |d          }|                     |          }|                     |d          } | dk    rd } |                     |d          }!|!,|                      |d          }"t	          j        |"d           }!d }#d }$d }%|!r.d}#|                      |d          }%t	          j        |%|          }$n.d}#|                      |d          }%|                      |d          }$|                     |$          }&d }'d }(d })d }*d }+|                     |d          },|                     |,          }-t	          j        |d          rd }nt	          j        |d          rdnd}(|                     t	          j        t	          j        t	          j        ||$          d          dd                    }'|                     t	          j
        t	          j        ||d          d                     })|rd }.|}/|(dk    rt	          j        d|          }.n*t	          j        d!|          }.t	          j
        d!|/          }/t	          j        |%t	          j
        ||.                    }0t	          j        |/|.          }1t	          j        |0|1          }*nd }.|}/|(dk    rt	          j        d|          }.n*t	          j        d!|          }.t	          j
        d!|/          }/t	          j
        ||-          }2t	          j
        |2|.          }0t	          j        t	          j
        t	          j        d|/          |2          |%          }1t	          j        |0|1          }*|                     |                      |d"         d#                    }3|3dz   }4t3          |4          }5t	          d$|5z             }6t3          |6          }7t	          j        |7|*          }8t	          j        |8d|3          }9|9d         d%k    rd }9|                     |9          }+|                      |d&          }:|:d'k    };i d(|d)d d|d*| d+|                     |           d|d,|                     |	          d-|d.|d|d	|d|                     |          d/|d0|d|,d1|'d2|+d |&|#|(|;|)d3S )4Nrq  r  r  rq  r{  ro  r  rp  r  rn  rm  rh  ri  ry  z0.5r   rg  r*  unrealizedProfitr  r+  rf  rI  isolatedWalletrl  r  r  r  r  rr  r  r  rK  rV  r  z5e--r  rs  rR  rC   r  r  rw  rx  ry  ru  rt  rz  rk  )r(  rv  ri  r  rt  r  )r_  r*  r  r:  r>   r  r  r~  r  r  r+  rZ  r  r[  r]  r^  r{  r  r  r|  r  r  r  r  r  strr  )<r;  r  r  r.  rq  r  r  r  rq  r  r  usdmr  rx  r  rm  r  r  r  contractsStringcontractsStringAbsentryNotionalcontractSizeNewrt  rg  r  r  rk  r  ry  r  ru  r  r+  isolatedMarginRawri  r  r]  rv  rz  r  r  liquidationPriceStringRawrk  ry  r  r  r  r  r  sizer  pricePrecisionPlusOnepricePrecisionPlusOneStringrounderrounderStringliquidationPriceRoundedStringtruncatedLiquidationPricer  rt  s<                                                               r=  r  zaster.parse_account_position  s   ##Hh77!!(FD*EE!!&(33))(J??+9+E3~&&&D"..xII))*=>>(,%%,3,>sNTU,V,V)++D8O<<H F070B7CUVsu{C|C|  B  DE  1F  1F-h&"&"2"28]"K"K --.EFF++HlCC&&'788
++Hj/RR#.~>>$$%677**8]CC$/@@"#.w/A.Re/f/fhxyyM"..v~FFO%0PPO!(!3G4FX]4^4^`cef!g!g%%&899	>>$,8JBOO..)962FF,0)q#o..// 	; 	;A%a(G !2GAJ?? 07
--&*&7&78Y&Z&Z#"..x9KLL))*=>>%%h==	>>I>>(J77 $ 0 0;K L L",->DDDH
 	I#J ,,X7GHHM&1-ATUU J ,,X7KLLM#//-HH&&'788

$(!v~>>!22<@@ 55 4	LJJ%/DDP77&D++G,>w?QRYRde|  O  SP  SP  RX  @Y  @Y  [^  `a  -b  -b  c  cK**7+=g>PQdfy{|>}>}  @E  ,F  ,F  G  GJ !T <@8'7$7???F?QRUWx?y?y<<?F?QRVXy?z?z<+2+=dDX+Y+Y("-mW=OPb  eM  >N  >N  O  O#./CEmnn	,3,>x,S,S)) <@8'7$7???F?QRUWx?y?y<<?F?QRVXy?z?z<+2+=dDX+Y+Y()*<>PQQ"-d4\]]#.w/A'BTUXZnBoBoqu/v/v  yF  G  G	,3,>x,S,S)!778H8HP[I\^e8f8fggN$2Q$6!*-.C*D*D'e&AABBGLLM,3,>}Ng,h,h)(/(:;XZ]_m(n(n%(+s22 -1)#001JKK''.AA'
H
$
 f
 	

 Y//
 ]
 &t'8'89V'W'W
  !2
 *+F
 *
 
 )).99
 ]
 
 L
  ;!
"  0#
$ $$$/
 
 
 	
r>  c                    |,t          |t                    st          | j        dz             |                                  |                     d|           |                     |          }d}|                     |ddd          \  }}|                     ||          }| 	                    |          }| 
                    |d|d          S )aq  
 @ignore
        fetch account positions

        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: data on account positions
        Nz8 fetchPositions() requires an array argument for symbolsFfetchAccountPositionsr  rq  )r  r  r(   rC   r  r  re  r  r  r7  r  )r;  rp  rb  r  r  rj  s         r=  r  zaster.fetch_account_positions  s     gt,, n'2l(lmmm##E6222//77#<<VE\^lnsttf--hEE%%g..--fhOOOr>  c                    |                                   |                     | j        d          }||r|                     |          }|                                 | j        d<   t          dt          |                    D ]}||         }|                     |d          }|                     |d d d          }| 	                    |dg           }	g }
t          dt          |	                    D ]M}|	|         }|                     |d          }|                     |d          }|

                    ||g           N|
| j        d         |<   | j        d         S )Nrg  r   rq  r  bracketsnotionalFloormaintMarginRatio)r  rZ  r  fapiPrivateGetV1LeverageBracketcreate_safe_dictionaryr]  r^  r_  r  r[  r  )r;  reloadrb  rg  r  rk  r  r.  rq  r  rj  jr  
floorValuery  s                  r=  r  zaster.load_leverage_brackets  sj     >>$,8JKK$&$;;FCCH/3/J/J/L/LDL+,1c(mm,, B B ++E8<<))(D$
KK>>%R@@q#h--00 M MA&qkG!%!1!1'?!K!KJ262B2B7L^2_2_/MM:/J"KLLLL;A/088|.//r>  c                 6    d|                      |dd          z   S )N0xkeccakhex)hash)r;  messages     r=  keccak_messagezaster.keccak_message  s    dii59999r>  c                 d    |                      |                     |          |dd                    S )N)	sign_hashr  )r;  r  
privateKeys      r=  sign_messagezaster.sign_message  s-    ~~d11'::Jstt<LMMMr>  c                     |                      | j        d          }|                     |d          }|d|dd}dddd	d
dd	ddd	ddd	ddd	ddd	ddd	ddd	gi}d|                      |d          ||                      |d          |                      |d          |                      |d          |                     |d          dd}|                     |||          }|                     || j                  }	|	S )Nr/  chainIdrE   r{  )r  rD   verifyingContractversionActionr?  string)rD   r?  destinationaddressdestination ChaintokenrO  rU  nonceuint256aster chainWithdrawreceiverrK  Mainnet)r?  r  r  r  rO  rU  r  r  )r_  r  r  eth_encode_structured_datar  r  )
r;  withdrawPayloadnetworkr/  r  domainmessageTypesr   msg	signatures
             r=  sign_withdraw_payloadzaster.sign_withdraw_payload  s[   &&t|]CC##OY??!,	
 
 22&	::,h?? (33!84411 )44&99	
 ++OZHH!(%%ow??&&AA##OU;;&&@@$	
 	
 --flHMM%%c4?;;	r>  r  tagc                 n   |                      ||          \  }}|                     |           |                                  |                     |          }|d         ||                                 dz  d}|                     |d          }|                     | j        di           }	|                     |d          }
| 	                    |	|
|
          }
|4|
2|                     | j        di           }|                     ||
          }|t          | j        d	z             ||d<   | 	                    |d
          }|t          | j        dz             ||d
<   |                     |g 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 S )!a  
        make a withdrawal

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#withdraw-user_data

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        rC   r  )rK  r  r  r  r2  r  Nr3  z. withdraw require chainId or network parameterrU  z withdraw require fee parameter)r  r  rU  rO  userSignaturerR  
withdrawIdtxidr  r  r  r  	addressToaddressFromr  tagTotagFromr?  
withdrawalrl  r|  updatedinternalcommentrU  )handle_withdraw_tag_and_paramscheck_addressr  rl  millisecondsr  rZ  r  r  r_  r(   rC   r  currency_to_precisionr  "sapiPrivatePostV1AsterUserWithdrawr  )r;  rS  rO  r  r  rb  rl  r  r  r2  r  chainIdsrU  r  s                 r=  r   zaster.withdraw  s    99#vFFV7###==&&d^&&((4/
 

 ##FI66>>$,
B??((;;""8Wg>>O'"5~~dl4GLLH'''::G?#DG.^$^___$	vu--;#DG.O$OPPP6#@#@#@AA 66tVWMM#'#=#=gw#O#O ::4;;wPV;W;WXX
H
$""8\::
 D$$Xv66
 	

 
 w
 w
 
 4
 3
 S
 t
 L
 f
 
  d!
" t#
$ )
 
 
 	
r>  fromAccount	toAccountc                 b   |                                   |                     |          }|d         |                     ||          d}d}d}	|'|                     |                                          }	d}
|'|                     |                                          }
|	dk    r	|
dk    rd}n|	dk    r|
dk    rd}d}|r|                     |                                           }|                     |d|          }||d	<   ||d<   |                     | 	                    ||                    }n.||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S )a  
        transfer currency internally between wallets on the same account

        https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#transfer-asset-to-other-address-trade
        https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#transfer-between-futures-and-spot-user_data

        :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>`
        rC   )rK  rO  Nr!  r"  SPOT_FUTUREFUTURE_SPOTclientTranIdkindType	toAddressrR  r>  r  r  r  r  r  r  r  r  r  r  r?  r   rO  rl  r|  r  r  )r  rl  r  convert_type_to_accountro  r  r  r_  $fapiPrivatePostV1AssetWalletTransferr  #sapiPrivatePostV1AssetSendToAddress)r;  rS  rO  r  r  rb  rl  r  r?  fromIdtoIdr  defaultClientTranIdr  s                 r=  r   zaster.transferG  s    	==&&d^00v>>
 
 "11+>>DDFFF //	::@@BBDV 0 0 DDxDFNN D"&"7"78I8I8K8K"L"L++FNDWXXL"&GJ&2GN#@@WV\A]A]^^HH $-GK ??GU[@\@\]]H
H
$""8X66
 D
 	

 
 t
 t
 
 9
 4
 T
 t
 J
 f
 
  d!
" t#
$ )
 
 
 	
r>  c           
      ~   |                      |          }|                     d          }|                     d          }|                     ||                     d          ||                     |                     |                              }d|                     |                     ||          dd          z   S )N190azEthereum Signed Message:r  r  r  )binary_lengthbase16_to_binarybinary_concatencoder  r  )r;  binaryMessagebinaryMessageLengthx19newlineprefixs         r=  hash_messagezaster.hash_message  s    "00??##D))''--##C5O)P)PRY[_[f[fgkg|g|  ~Q  hR  hR  \S  \S  T  Tdii 2 26= I I8UZ[[[[r>  c                 ^   |                                   |                     |dd          |dd          dd           }|d         }|d         }|                     |                     d|d                             }d|                    dd	          z   |                    dd	          z   |z   S )
Nr  	secp256k1rs   vr  @   rI  )check_required_credentialsecdsaint_to_base16sumrjust)r;  r  r  r  r.  r/  r1  s          r=  r  zaster.sign_hash  s    '')))JJtCDDz:cdd+;[$OO	cNcNtxxIcN;;<<aggb#&&&S)9)99A==r>  publicGETc                 p   |                      | j        d         |                   dz   |z   }|dk    s|dk    r|r|d|                     |          z   z  }nY|dk    s|dk    rL|                                  d| j        i}|                                 }|                                 }	|                     | j        d	          }
| 	                    d
|i|          }|
|
|d	<   |                     |d	          }|||d	<   d }|dk    r|dk    r| 
                    |dg           }| 
                    |dg           }|                     |ddg          }|                     |          }t          |          }t          |          }|dk    r!|dz   dz   d                    |          z   dz   }|dk    r!|dz   dz   d                    |          z   dz   }n|                     |          }d}|                    d          dk    r?| j        d         }|t          | j        dz             t#          |                                          }|                     |          }i }t)          dt          |                    D ]"}||         }t+          ||                   ||<   #|                     |                     |                     g d|                     |          | j        ||	g          dd                    }|                     || j                  }| j        |d<   ||d<   |	|d<   |                     |          }nL|                     |                     |          |                     | j                  t@          j!                  }|d|z   z  }|d k    r	|d|z   z  }n|}d!|d"<   ||||d#S )$NrV   rv  rN   rP   ?rO   rQ   zX-MBX-APIKEYr-  r  DELETEr   r  r  r   &zorderidlist=%5Bz%2Cz%5Dzorigclientorderidlist=%5B v3signerAddressz2 requires signerAddress in options when use v3 api)r  r  r  r  r  binaryusersignerr  z&signature=r9  z!application/x-www-form-urlencodedzContent-Type)rR   r  bodyheaders)"implode_hostnamerM   	rawencoder3  r  r  microsecondsr  r  r  r[  r  r^  joinfindr(   rC   r  keyssortr]  r  r+  r  eth_abi_encodejsonwalletAddressr  r  hmacr%  r  hashlibsha256)r;  pathrV   r  rb  rE  rD  rR   r  r  defaultRecvWindowextendedParamsr-  queryorderidlistorigclientorderidlistorderidlistLengthorigclientorderidlistLengthr  r@  rK  
sortedKeyssigningPayloadrk  keysigningHashs                             r=  signz
aster.sign  s   ##DIe$4S$9::S@4G,#"5"5 4sT^^F3333M!!SM%9%9++---G ))++I%%''E $ 1 1$, M M![[Y* N !,/@|,**6<@@J%/9|,E(""1A)A)A"nn^]BOO(,~G^`b(c(c%!%>MKb;c!d!d~66$'$4$4!.12G.H.H+$q((!CK*;;ejj>U>UUX]]E.22!CK*EE

ShHiHiilqqE~66Iyy!## $_ = (+DG6j,jkkkN//1122!YYt__
!#q#j//22 C CA$Q-C*-nS.A*B*BN3''"//		$:M:M O O OIIn--t/A=RWX;Z ;Z[cem1o 1o p p !NN;HH	)-);v&+8x(*/w'~66 IIdkk%&8&8$++dk:R:RT[Tbcc	')33EsU{"*M'fdwOOOr>  httpCodereasonrR   r  rE  rD  c
                 z   |d S |                      |d          }
|                      |d          }|
|
dk    r| j        dz   |z   }|                     | j        d         ||           |                     | j        d         |
|           |                     | j        d         ||           t          |          d S )NrS  r  r)   r5  r6  )r_  rC   throw_exactly_matched_exceptionr4  throw_broadly_matched_exceptionr#   )r;  r`  ra  rR   r  rE  rD  r  requestHeadersrequestBodyrS  r  feedbacks                r=  handle_errorszaster.handle_errors  s    4 &11""8U33w}t+H001I7T\]]]001I4QYZZZ001I7T\]]])))tr>  )N)F)o__name__
__module____qualname__r   r9  r  r   boolrF  rH  r   rn  r"   r   r  r	   r  r  r  r  dictr   r  r  r  r   r   r
  r   r/  r4  r   r   r<  r   rM  rP  r   rT  rW  r   rb  rh  rq  rv  ry  r   r}  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'  r1  r5  r9  r<  r@  rF  r   r
   rW  rV  rd  r  r  r   r  r  r  r  r  r  r  r  r    r   r!   r   r+  r  r_  ri  __classcell__)r<  s   @r=  r@   r@   )   s       z# z z z z z zx( (s (S (D ( ( ( (' 'c 'C '4 ' ' ' ' ') = =Z = = = =~ $& Y Y$v, Y Y Y Yv !# 9 9s 9 9 9 9"
 
 
4 
 
 
 
4 26DW[df @L @L# @Lc @LQT @Lkoptku @L @L @L @LDJ J Jv J J J J JX 6:UW 3A 3A3 3As 3A# 3A\`af\g 3A 3A 3A 3Aj -1tRV_a 5I 5Ic 5I 5IC 5I 5I 5I 5In :>b 1R 1Rs 1R3 1RY 1R 1R 1R 1Rf 8<$]ajl /O /O /OC /OWZ /O /O /O /ObW W4 W W6 W W W Wr 02 C3 C33 C3f C3 C3 C3 C3J 04B 15 15W 157 15 15 15 15f/
 /
6 /
[ /
 /
 /
 /
b 68 9 9 9K 9 9 9 9@ 6:" ; ;7 ; ; ; ; ;: :>b ; ;w ;\ ; ; ; ;8) ) ) ) ) $& 7( 7(( 7( 7( 7( 7(r >B" ! !# !s ! ! ! !F 15R 
 
# 
 
 
 
, =A T T Tc T T T T,
 
T 
6 
EX 
 
 
 
 57 8 8 8;N 8 8 8 8<	: 	: 	: 	: 	:
3S 
3 
3 
3 
3R R Rv R R R R Rh 26b 2 2c 23 2 2 2 2B 7;2 2 23 2 2 2 2 26 *.Dt\^ !A !A3 !Ac !A !Acghmcn !A !A !A !AF /3TXac =A =A =A3 =Ac =Ahlmrhs =A =A =A =A~ gksu $2 $23 $2i $2y $2RW $2`c $2 $2 $2 $2L @B !+ !+D$6 !+ !+ !+ !+F os{} F3 F33 F3i F3y F3Z_ F3hk F3 F3 F3 F3P /32 !
 !
 !
 !
 !
 !
F 37r 2 2s 2C 2 2 2 2@ ;?r >3 >3c >3C >3 >3 >3 >3@ 9=R  S #    > 26b !A !Aw !AY !A !A !A !AF'
 '
t '
V '
x '
 '
 '
 '
R 59 #L #L' #L #L #L #L #LJ
 
D 
* 
 
 
 
8 =Adaetx  BD -V -Vc -V -V[^ -Vnq -V  IM  N`  Ia -V -V -V -V^$
 $
d $
F $
N` $
 $
 $
 $
L MO  3    . @B D DC D DFX D D D D =? D D De DCU D D D D
 
6 
 
 
 
4 37TX\eg B BC Bs BRU B B B B>) )t )x ); ) ) ) )V
8 
8 
8 (,$TZ\ )C )C )CC )Cs )Caefqar )C )C )C )CVW WF W W W Wr 7;2 +P +PG +P +P +P +PZ 26b ~ ~w ~T(^ ~ ~ ~ ~4   BS
 S
v S
 S
 S
 S
j :>b P Pw P P P P. -2" 0 0 0 0,: : :N N N! ! ! ! !F KOWY >
 >
S >
% >
# >
C >
^i >
 >
 >
 >
@ [] E
 E
S E
% E
c E
c E
an E
 E
 E
 E
N\ \ \> > > &eBSW @P @P @P @PDc 3 S # X\ dg        r>  r@   )Eccxt.base.exchanger   ccxt.abstract.asterr   rQ  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!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   ccxt.base.decimal_to_precisionr<   r=   ccxt.base.preciser>   r@   rD  r>  r=  <module>rx     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  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 0 0 0 0 0 - - - - - - . . . . . . - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . % % % % % % ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) * * * * * * 5 5 5 5 5 5 - - - - - - - - - - - - ) ) ) ) ) ) 1 1 1 1 1 1 , , , , , , ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) + + + + + + ( ( ( ( ( ( 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %H7 H7 H7 H7 H7Hk H7 H7 H7 H7 H7r>  