
    ei                    $   d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# 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 l@mBZB d d!lCmDZD  G d" d#ee          ZEd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    V/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/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                 x  K   |                      |          |                     |          g}t          j        |  d{V }|                     |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
        Nr   assetsr*  assetminmax)amountr   depositcrypto)infocoderC   rD   activerP  r   fee	precisionlimitsr2  r?  )sapiPublicGetV1ExchangeInfofapiPublicGetV1ExchangeInfoasynciogather	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_currencies4  s      ,,V44,,V44
  1111111^^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                 
  K   |                      |          |                     |          g}t          j        |  d{V }|                     |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
        Nr   symbolsr*  Fsymbol	baseAsset
quoteAssetcontractTypeT	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  r{  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\  r]  r^  rX   r_  r`  ra  rb  safe_number_2r:  index_bysafe_market_structureparse_precisionsafe_integersafe_numbersafe_dict_2append)#r;  rd  re  rf  rg  rh  ri  rj  rk  rX   rl  rm  r^   r  rC   r  r  r  r  rv  r  r\   r{  r#  rC  rs  r  r  unifiedTyper~  rT  r  filtersByTypeentryfilters#                                      r=  fetch_marketszaster.fetch_marketss  s      ,,V44,,V44
  1111111^^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                 h   K   |                      |           d{V }|                     |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
        N
serverTime)fapiPublicGetV1Timer  )r;  rd  responses      r=  
fetch_timezaster.fetch_timeN  sE       11&99999999   <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  rs  sincelimitc                   K   |t          | j        dz             |                                  d{V  |                     |          }i }|||d<   ||dk    rd}||d<   |                     d||          \  }}|                     | j        ||          |d<   |                     |d          }|d	k    }	|d
k    }
|                     |d          }d}|	r;|d         |d<   |                     | 	                    ||                     d{V }n|
r;|d         |d<   | 
                    | 	                    ||                     d{V }nr|d         |d<   |d         r0|                     | 	                    ||                     d{V }n/|                     | 	                    ||                     d{V }|                     |||||          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   rs  pairr#  )r(   rC   load_marketsr  handle_until_optionra  r  omitfapiPublicGetV1MarkPriceKlinesextendfapiPublicGetV1IndexPriceKlinesfapiPublicGetV1KlinessapiPublicGetV1Klinesparse_ohlcvs)r;  rs  	timeframer  r  rd  r  requestr  isMarkisIndexr  s               r=  fetch_ohlcvzaster.fetch_ohlcvy  sA       >#DG.X$XYYY!!!!!!!!!V$$#(GK t||$GG229gvNN"..t	9UU
  116/G#67++ 	Z &tGH!@@WV\A]A]^^^^^^^^HH 	Z$TlGFO!AA$++gW]B^B^________HH &tGHh Z!%!;!;DKKQW<X<X!Y!YYYYYYY!%!;!;DKKQW<X<X!Y!YYYYYYY&   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   rs  commissionAssetqtyr  quoteQtybaseQtytimesider  r  isBuyerMakersellbuyorderId
commission)r  rn  )rC   rR  	timestampdatetimers  orderr?  r  takerOrMakerr  rO  r  rU  )ra  rb  safe_string_2r  safe_string_lower	safe_bool
safe_tradeiso8601r:  r>   
string_abs)r;  r  r  rC   rs  ro  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                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}||dk    rd}||d<   d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||||          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 argumentrs  rC     r  r^   )r(   rC   r  r  fapiPublicGetV1Tradesr  sapiPublicGetV1Tradesparse_tradesr;  rs  r  r  rd  r  r  r  s           r=  fetch_tradeszaster.fetch_trades  s       >#DG.Y$YZZZ!!!!!!!!!V$$fTl
 t||$GG&> 	V!77GV8T8TUUUUUUUUHH "77GV8T8TUUUUUUUUH   65%@@@r>  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   ||dk    rd}||d<   |                     d||          \  }}d}|d	         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |||||          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 argumentrs  rC   r  r  r  r  r^   )	r(   rC   r  r  r  fapiPrivateGetV1UserTradesr  sapiPrivateGetV1UserTradesr  r  s           r=  fetch_my_tradeszaster.fetch_my_trades<  sM      >#DG.[$[\\\!!!!!!!!!V$$fTl
 #(GK t||$GG229gvNN&> 	[!<<T[[RX=Y=YZZZZZZZZHH!<<T[[RX=Y=YZZZZZZZZH*   65%HHHr>  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}||dk    rd}||d<   d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |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 argumentrs  rC   r  r  r^   Tbidsasks)	r(   rC   r  r  fapiPublicGetV1Depthr  sapiPublicGetV1Depthr  parse_order_book)r;  rs  r  rd  r  r  r  r  s           r=  fetch_order_bookzaster.fetch_order_books  s5      >#DG.\$\]]]!!!!!!!!!V$$fTl
 t||$GG&> 	U!66t{{7F7S7STTTTTTTTHH!66t{{7F7S7STTTTTTTTH( %%h44	$$Xvy&&QQQr>  c           
        K   |                                   d{V  i }| |                     |          }|d         |d<   |||d<   ||dk    rd}||d<   |                     d||          \  }}|                     |                     ||                     d{V }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   rs  r  r  r  r  r   fundingTimer^   fundingRate)rR  rs  r  r  r  r  )r  r  r  fapiPublicGetV1FundingRater  r_  r`  r  r  safe_symbolra  r  r  sort_byfilter_by_symbol_since_limit)r;  rs  r  r  rd  r  r  r  ratesrm  r  r  sorteds                r=  fetch_funding_rate_historyz aster.fetch_funding_rate_history  s      !!!!!!!!![[((F &tGH#(GK t||$GG229gvNN88Wf9U9UVVVVVVVV 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  rs  	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  ra  safe_marketr>   
string_mulsafe_tickerr  )r;  r  r  r  
marketTypemarketIdrs  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                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||          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 argumentrs  rC   r^   )r(   rC   r  r  fapiPublicGetV1Ticker24hrr  sapiPublicGetV1Ticker24hrr1  r;  rs  rd  r  r  r  s         r=  fetch_tickerzaster.fetch_ticker0  s       >#DG.Y$YZZZ!!!!!!!!!V$$fTl
 &> 	Z!;;DKKQW<X<XYYYYYYYYHH, ";;DKKQW<X<XYYYYYYYYH2   6222r>  rr  c                   K   |                                   d{V  |                     |dddd          }|                     |          }d}|                     d||          \  }}d}|                     d||          \  }}d}|                     ||          r|                     |           d{V }n?|dk    r|                     |           d{V }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  r3  r4  r4   rC   parse_tickers)r;  rr  rd  r  r?  r@  r  s          r=  fetch_tickerszaster.fetch_tickersu  sH      !!!!!!!!!%%gtT4FF--g6699.&RXYYf99.&RXYY>>$(( 	f!;;FCCCCCCCCHHV^^!;;FCCCCCCCCHH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 )Nrs  nextFundingTimer  fundingIntervalHourshrR  r  r*  r+  interestRateestimatedSettlePricer  r  r  lastFundingRatefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )ra  r  r  r  r  )r;  r  r  r0  rI  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                 4  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          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 argumentrs  rC   )r(   rC   r  r  fapiPublicGetV1PremiumIndexr  rO  r5  s         r=  fetch_funding_ratezaster.fetch_funding_rate  s       >#DG.^$^___!!!!!!!!!V$$fTl
 99$++gv:V:VWWWWWWWW &&x888r>  c                    K   |                                   d{V  |                     |          }|                     |                     |                     d{V }|                     ||          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>`
        N)r  r9  rQ  r  parse_funding_ratesr;  rr  rd  r  s       r=  fetch_funding_rateszaster.fetch_funding_rates  s       !!!!!!!!!%%g..99$++f:M:MNNNNNNNN ''':::r>  c                    K   |                                   d{V  ||                     |          }|                     |           d{V }|                     ||          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>`
        N)r  r9  fapiPublicGetV1FundingInforT  rU  s       r=  fetch_funding_intervalszaster.fetch_funding_intervals  s       !!!!!!!!!))'22G88@@@@@@@@ ''':::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`  ra  rb  accountr  safe_balance)r;  r  rl  rm  balancero  rS  ra  s           r=  parse_balancezaster.parse_balance2  s    )q#h--(( 	# 	#AqkG))'7;;J**:66DllnnG"00&BUVVGFO"..wAAGFO#//IIGG"F4LL  (((r>  c                   K   d}|                      dd|          \  }}d}|                     dd|          \  }}d}d}|                     ||          r3|                     |           d{V }|                     |dg           }nV|dk    r3|                     |           d{V }|                     |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 r8  )	r;  r<  rH  fapiPrivateGetV4Accountr]  sapiPrivateGetV1Accountr4   rC   rd  )r;  rd  r?  r@  r  datas         r=  fetch_balancezaster.fetch_balance?  s%      99.$PVWWf99.$PVWW>>$(( $	f!99&AAAAAAAAH>>(Hb99DD* V^^!99&AAAAAAAAH>>(J;;DD tw)LLtSVddeee!!$'''r>  
marginModec                   K   |t          | j        dz             |                                }|dk    rd}|dk    r|dk    rt          | j        dz             |                                  d{V  |                     |          }|d         |d}|                     |                     ||                     d{V }|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   )rs  
marginType)r(   rC   upperr)   r  r  fapiPrivatePostV1MarginTyper  )r;  rk  rs  rd  r  r  r  s          r=  set_margin_modezaster.set_margin_modex  s       >#DG.[$[\\\%%''
  "J*$$:+B+BTW'UUVVV!!!!!!!!!V$$Tl$
 
 99$++gv:V:VWWWWWWWW r>  c                 v   K   |                      |           d{V }|                     |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
        NdualSidePositionT)rR  hedged) fapiPrivateGetV1PositionSideDualr  )r;  rs  rd  r  ru  s        r=  fetch_position_modezaster.fetch_position_mode  s^       >>vFFFFFFFF  >>(4FGG'4/
 
 	
r>  rv  c                 l   K   d|i}|                      |                     ||                     d{V 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
        ru  N)!fapiPrivatePostV1PositionSideDualr  )r;  rv  rs  rd  r  s        r=  set_position_modezaster.set_position_mode  sK       
 ;;DKKQW<X<XYYYYYYYYYr>  rU  c                     |                      |d          }|                     ||          }|                     ||          }|||                     |d          |                     |d          dddS )Nrs  makerCommissionRatetakerCommissionRateF)rR  rs  r  r  r  r  )ra  r,  r  r  )r;  rU  r  r0  rs  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                 v  K   |                                   d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||          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>`
        Nrs  rC   r^   )r  r  fapiPrivateGetV1CommissionRater  sapiPrivateGetV1CommissionRater  r5  s         r=  fetch_trading_feezaster.fetch_trading_fee  s       !!!!!!!!!V$$fTl
 &> 	_!@@WV\A]A]^^^^^^^^HH!@@WV\A]A]^^^^^^^^H %%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ra  )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 )Nrs  r  r  
updateTimer~  r?  	stopPricerR  rC   r  clientOrderIdr  r  lastTradeTimestamplastUpdateTimestamptimeInForcepostOnlyr  triggerPricer(  avgPricer  cumQuoterO  origQtyexecutedQty
reduceOnlyro)filled	remainingr~  rU  tradesr  )ra  r,  r  r  safe_string_upperr:  	omit_zero
safe_orderr  r  r  r  safe_bool_2)r;  r  r  rR  r0  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                    K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   d}|d	         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    ||          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 argumentrs  rC   r  	clientOidorigClientOrderIdr  r^   )
r(   rC   r  r  r  r  fapiPrivateGetV1Orderr  sapiPrivateGetV1Orderr  r;  rC   rs  rd  r  r  r  r  s           r=  fetch_orderzaster.fetch_order]  sG      >#DG.X$XYYY!!!!!!!!!V$$fTl
 **6?KPP6O[#ABB$+8G'((!#GI&> 	V!77GV8T8TUUUUUUUUHH!77GV8T8TUUUUUUUUH&111r>  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |dd          }|                     |ddg          }|||d<   n||d<   |                     |                     ||                     d{V }|                     ||          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 argumentrs  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77GV8T8TUUUUUUUU&111r>  c                   K   |                                   d{V  |t          | j        dz             |                     |          }d|d         i}|||d<   ||dk    rd}||d<   |                     d||          \  }}d}|d	         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||||          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 argumentrs  rC   r  r  r  r  r^   )	r  r(   rC   r  r  fapiPrivateGetV1AllOrdersr  sapiPrivateGetV1AllOrdersparse_ordersr  s           r=  fetch_orderszaster.fetch_orders  sI      !!!!!!!!!>#DG.Y$YZZZV$$fTl
 #(GK t||$GG229gvNN&> 	Z!;;DKKQW<X<XYYYYYYYYHH!;;DKKQW<X<XYYYYYYYYH  65%@@@r>  c                 \  K   |                                   d{V  i }d}d}d}|                     d||          \  }}| |                     |          }|d         |d<   |                     d||          \  }}d}	|                     ||          r0|                     |                     ||                     d{V }	nS|dk    r0|                     |                     ||                     d{V }	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   rs  r\   z$ fetchOpenOrders() does not support r8  )r  r<  r  r;  rH  fapiPrivateGetV1OpenOrdersr  sapiPrivateGetV1OpenOrdersr4   rC   r  )
r;  rs  r  r  rd  r  r  r?  r@  r  s
             r=  fetch_open_orderszaster.fetch_open_orders  sn      !!!!!!!!!99:KVU[\\[[((F &tGH99:KVU[\\f>>$(( 	i!<<T[[RX=Y=YZZZZZZZZHHV^^!<<T[[RX=Y=YZZZZZZZZHHtw)OORVVYgghhh<   65%@@@r>  r  rO  r  c                   K   |                                   d{V  |                     |          }|                     |dd          }|                     |d          }|                     ||||||          }	d}
|d         r:|r|                     |	           d{V }
n7|                     |	           d{V }
n|                     |	           d{V }
|                     |
|          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>`
        NtestFr^   )	r  r  r  r  create_order_requestfapiPrivatePostV1OrderTestfapiPrivatePostV1OrdersapiPrivatePostV1Orderr  )r;  rs  r?  r  rO  r  rd  r  r  r  r  s              r=  create_orderzaster.create_order  s&     . !!!!!!!!!V$$~~ffe4466**++FD$vVV&> 	B F!%!@!@!I!IIIIIII!%!<!<W!E!EEEEEEE!88AAAAAAAAH&111r>  ordersc           	        K   |                                   d{V  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}|                     |                     ||                     d{V }|                     |          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>`
        Nr  z' createOrders() order list max 5 ordersr   rs  r?  r  rO  r  rd  FTr\   z! createOrders() does not support  ordersbatchOrders)r  r`  r/   rC   r_  ra  
safe_valuer\  r  r  r9  r  r4   fapiPrivatePostV1BatchOrdersr  r  )r;  r  rd  ordersRequestsorderSymbolsrm  rawOrderr0  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;;wPV;W;WXXXXXXXX  ***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   )rs  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  rq  r  ra  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;  rs  r?  r  rO  r  rd  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_requestD  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                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     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 argumentrs  rC   r^   rR  )r(   rC   r  r   fapiPrivateDeleteV1AllOpenOrdersr   sapiPrivateDeleteV1AllOpenOrdersr  r5  s         r=  cancel_all_orderszaster.cancel_all_orders  s      >#DG.]$]^^^!!!!!!!!!V$$fTl
 &> 	a!BB4;;wX^C_C_````````HH!BB4;;wX^C_C_````````H OO  
 	
r>  c                 "  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |g d          }|||d<   n||d<   |                     |g d          }d}|d         r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    ||          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 argumentrs  rC   )r  r  newClientStrategyIdr  r  r^   )
r(   rC   r  r  r  r  fapiPrivateDeleteV1Orderr  sapiPrivateDeleteV1Orderr  r  s           r=  cancel_orderzaster.cancel_order  sP      >#DG.Y$YZZZ!!!!!!!!!V$$fTl
 **63p3p3pqq$+8G'((!#GI6#`#`#`aa&> 	Y!::4;;wPV;W;WXXXXXXXXHH!::4;;wPV;W;WXXXXXXXXH&111r>  idsc                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         r#t	          | j        dz   |d         z   dz             d|d         i}|                     |d	          }|||d	<   n||d
<   |                     |                     ||                     d{V }|                     ||          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  rs  rC   origClientOrderIdListorderIdList)	r(   rC   r  r  r4   r]  fapiPrivateDeleteV1BatchOrdersr  r  )r;  r  rs  rd  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"<<T[[RX=Y=YZZZZZZZZB   6222r>  r  c                 T  K   |t          | j        dz             |dk     s|dk    rt          | j        dz             |                                  d{V  |                     |          }|d         |d}|                     |                     ||                     d{V }|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   )rs  r  )r(   rC   r)   r  r  fapiPrivatePostV1Leverager  )r;  r  rs  rd  r  r  r  s          r=  set_leveragezaster.set_leverageO	  s       >#DG.Y$YZZZqLLhnnTW'NNOOO!!!!!!!!!V$$Tl 
 
 77GV8T8TUUUUUUUU r>  c                    K   |                                   d{V  |                     |           d{V }|                     ||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>`
        Nrs  )r  fapiPrivateGetV2PositionRiskparse_leveragesrU  s       r=  fetch_leverageszaster.fetch_leveragesn	  sk       !!!!!!!!!::6BBBBBBBB, ##Hgx@@@r>  c                 .   |                      |d          }|                     |d          }|                     |d          }d }d }|                     |d          }||dk    r|}|}n|dk    r|}n|dk    r|}||                     ||          |||dS )	Nrs  rp  positionSider  bothlongshort)rR  rs  rk  longLeverageshortLeverage)ra  r  r  r  )	r;  r  r  r0  rk  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                    K   |                                   d{V  |                     |           d{V }|                     ||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>`
        Nrs  r^   )r  r  parse_margin_modesrU  s       r=  fetch_margin_modeszaster.fetch_margin_modes	  sm       !!!!!!!!!::6BBBBBBBB0 &&x(FKKKr>  c                     |                      |d          }|                     ||          }||d         |                     |d          dS )Nrs  rp  )rR  rs  rk  )ra  r,  r  )r;  rk  r  r0  s       r=  parse_margin_modezaster.parse_margin_mode	  s[    ( ##J99!!(F33X&00\JJ
 
 	
r>  c                   K   |                                   d{V  |t          | j        dz             |                     |          }|                     |d          }|                     |d          }d|d         i}||dk    rdnd|d	<   |||d
<   |||d<   |||d<   |                     |                     ||                     d{V }	|                     |	          }
| 	                    |
|||          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untilrs  rC   addr*  r  r?  r  r  r  )
r  r(   rC   r  r  r  %fapiPrivateGetV1PositionMarginHistoryr  parse_margin_modificationsr	  )r;  rs  r?  r  r  rd  r  r$  r  r  modificationss              r=  fetch_margin_adjustment_historyz%aster.fetch_margin_adjustment_history	  sA      !!!!!!!!!>#DG.j$jkkkV$$!!&'2267++fTl
 $(EMMaaGFO#(GK $GG!&GICCDKKPWY_D`D`aaaaaaaa 77AA00uUUUr>  ri  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  rs  r  r^   200r*  r%  reduceisolatedrO  rK  okfailed)
rR  rs  r?  rk  rO  rS  r`  r~  r  r  )r  ra  r,  r  r  )	r;  ri  r  r  	errorCoder0  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                 n  K   |                                   d {V  |                     |          }|                     ||          }||d         |d}|d         }|                     |                     ||                     d {V }|                     |                     ||          d|i          S )NrC   )r?  rs  rO  r  rS  )r  r  r  fapiPrivatePostV1PositionMarginr  r3  )	r;  rs  rO  addOrReducerd  r  r  rS  r  s	            r=  modify_margin_helperzaster.modify_margin_helperP
  s      !!!!!!!!!V$$))&&99Tl
 

 g==dkk'SY>Z>Z[[[[[[[[ {{499(FKKDN
   	r>  c                 B   K   |                      ||d|           d{V 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  Nr7  r;  rs  rO  rd  s       r=  reduce_marginzaster.reduce_marging
  4       ..vvq&IIIIIIIIIr>  c                 B   K   |                      ||d|           d{V 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*  Nr9  r:  s       r=  
add_marginzaster.add_margint
  r<  r>  c           
      b   |                      |d          }|                      |d          }|                     |d          }||                     ||d d          |                     |          ||                     |          |                      |d          |                     |d          dS )Nrs  rK  r  r^   tranIdincome)rR  rs  rS  r  r  rC   rO  )ra  r  r  rb  r  r  )r;  rA  r  r0  ro  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                   K   |                                   d{V  d}ddi}| |                     |          }|d         |d<   |                     d||          \  }}|||d<   |t          |d          |d	<   |                     |                     ||                     d{V }|                     ||||          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   rs  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44T[[&5Q5QRRRRRRRR!!(FE5AAAr>  itemrn  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 )NrA  0out-1inrK  r  rD  r@  tradeId)rR  rC   	directionra  referenceAccountreferenceIdr?  rn  rO  r  r  beforeafterr~  rU  )ra  r>   	string_ler-  rb  safe_currencyr  safe_ledger_entryparse_ledger_entry_typer:  r  )	r;  rI  rn  rO  rP  ro  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_PNLrE  
COMMISSIONINSURANCE_CLEARMARKET_MERCHANT_RETURN_REWARDr  )r;  r?  
ledgerTypes      r=  rX  zaster.parse_ledger_entry_type
  s=    "'# &+-7
 

 
D$777r>  rS  c                   K   |                                   d{V  d}||                     |          }i }|||d<   |t          |d          |d<   |                     |d          }||                     |d          }||d<   |                     |                     ||                     d{V }|                     ||||          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  rn  rM  r  r  rF  r  parse_ledger)	r;  rS  r  r  rd  rn  r  r$  r  s	            r=  fetch_ledgerzaster.fetch_ledger
  s       !!!!!!!!!}}T**H#(GK "5$//GG!!&'22YYvw//F!&GI44T[[&5Q5QRRRRRRRR   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 )1Nrs  r  isolatedMarginleverageBracketsr  notionalValuer   r*  positionAmtunRealizedProfitliquidationPricerp  rK  crossr-  r  r  
entryPricer{  rV  r  r  r  r}  rM  r*  r  maintMarginr  r     1e-8initialMargin5e-5r  r  r  BOTHrR  rC   	contractsunrealizedPnl
collateralr  initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage)marginRatior  rk  r  rv  r  r  r  )ra  r,  r\  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  r0  rs  isolatedMarginStringri  leverageBracketnotionalStringnotionalStringAbs!maintenanceMarginPercentageStringrm  bracketr  contractsAbsrv  unrealizedPnlStringrw  liquidationPriceStringrm  collateralStringrk  r  entryPriceStringro  r{  contractSizeStringr#  rV  basePrecisionValuequotePrecisionValueprecisionIsUndefined(onePlusMaintenanceMarginPercentageStringentryPriceSignStringinnerleftSider  	rightSidebasePrecisionrx  r*  r  r{  maintenanceMarginStringrz  initialMarginStringinitialMarginPercentageStringleverageStringr  rational	unroundedr|  r  r  rv  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                   K   |,t          |t                    st          | j        dz             |                                  d{V  |                     d|           d{V  i }|                     |                     ||                     d{V }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   ro  rK  rs  )
isinstancelistr(   rC   r  load_leverage_bracketsr  r  r_  r`  ra  r>   r  r  r  r9  filter_by_array_positions)	r;  rr  rd  r  r  rl  rm  rawPositionr  s	            r=  fetch_positions_riskzaster.fetch_positions_risk  sl      gt,, r'2p(pqqq!!!!!!!!!))%888888888::4;;wPV;W;WXXXXXXXX( 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                 |  K   d}|                      |dd          \  }}|<|                     | j        d          }||                     | j        dd          }nd}|dk    r|                     ||           d{V S |dk    r|                     ||           d{V 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positionRiskra  z<.options["fetchPositions"]["method"] or params["method"] = "z@" is invalid, please choose between "account" and "positionRisk")handle_option_and_paramsr\  r  ra  r  fetch_account_positionsr4   rC   )r;  rr  rd  defaultMethodr  s        r=  fetch_positionszaster.fetch_positions  s       $ = =fFVX` a av nnT\3CDDG $ 0 0?OQ_ ` ` .N**227FCCCCCCCCCi''55gvFFFFFFFFF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  rs  r  r#  r  r  rp  rK  z
0.00000000r  )r]  r_  r`  ra  rb  r>   r  r,  parse_account_positionr  r  )r;  ra  filterClosedr  rJ  rf  rm  r  ro  rS  r  r  rl  r  r0  r  rz  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 )4Nrs  r  r  rs  r}  rq  r  rr  r  rp  ro  rj  rk  r{  z0.5r   ri  r*  unrealizedProfitr  r-  rh  rK  isolatedWalletrn  r  r  r  r  rt  r  r  rM  rV  r  z5e--r  ru  rR  rC   r  r  ry  rz  r{  rw  rv  r|  rm  )r*  rx  rk  r  rv  r  )ra  r,  r  r:  r>   r  r  r  r  r  r-  r\  r  r]  r_  r`  r}  r  r  r~  r  r  r  r  r  strr  )<r;  r  r  r0  rs  r  r  r  rs  r  r  usdmr  rz  r  ro  r  r  r  contractsStringcontractsStringAbsentryNotionalcontractSizeNewrv  ri  r  r  rm  r  r{  r  rw  r  r-  isolatedMarginRawrk  r  r_  rx  r|  r  r  liquidationPriceStringRawrm  r{  r  r  r  r  r  sizer  pricePrecisionPlusOnepricePrecisionPlusOneStringrounderrounderStringliquidationPriceRoundedStringtruncatedLiquidationPricer  rv  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                   K   |,t          |t                    st          | j        dz             |                                  d{V  |                     d|           d{V  |                     |           d{V }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  rs  )r  r  r(   rC   r  r  rg  r  r  r9  r  )r;  rr  rd  r  r  rl  s         r=  r  zaster.fetch_account_positions  s      gt,, n'2l(lmmm!!!!!!!!!))%88888888855f========#<<VE\^lnsttf--hEE%%g..--fhOOOr>  c                   K   |                                   d {V  |                     | j        d          }||r!|                     |           d {V }|                                 | 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 )Nri  r   rs  r  bracketsnotionalFloormaintMarginRatio)r  r\  r  fapiPrivateGetV1LeverageBracketcreate_safe_dictionaryr_  r`  ra  r  r]  r  )r;  reloadrd  ri  r  rm  r  r0  rs  r  rl  jr  
floorValuer{  s                  r=  r  zaster.load_leverage_brackets  s     !!!!!!!!!  >>$,8JKK$&$!AA&IIIIIIIIH/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  )ra  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                   K   |                      ||          \  }}|                     |           |                                  d{V  |                     |          }|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<   |                     |                     ||                     d{V }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>`
        NrC   r  )rK  r  r  r  r2  r  r3  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?  
withdrawalrn  r~  updatedinternalcommentrU  )handle_withdraw_tag_and_paramscheck_addressr  rn  millisecondsr  r\  r  r  ra  r(   rC   r  currency_to_precisionr  "sapiPrivatePostV1AsterUserWithdrawr  )r;  rS  rO  r  r  rd  rn  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 @@WV\A]A]^^^^^^^^
H
$""8\::
 D$$Xv66
 	

 
 w
 w
 
 4
 3
 S
 t
 L
 f
 
  d!
" t#
$ )
 
 
 	
r>  fromAccount	toAccountc                   K   |                                   d{V  |                     |          }|d         |                     ||          d}d}d}	|'|                     |                                          }	d}
|'|                     |                                          }
|	dk    r	|
dk    rd}n|	dk    r|
dk    rd}d}|x|                     |                                           }|                     |d|          }||d	<   ||d<   |                     | 	                    ||                     d{V }n4||d
<   | 
                    | 	                    ||                     d{V }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>`
        NrC   )rK  rO  r!  r"  SPOT_FUTUREFUTURE_SPOTclientTranIdkindType	toAddressrR  r@  r  r  r  r  r  r  r  r  r  r  r?  r   rO  rn  r~  r	  r
  )r  rn  r  convert_type_to_accountrq  r  r  ra  $fapiPrivatePostV1AssetWalletTransferr  #sapiPrivatePostV1AssetSendToAddress)r;  rS  rO  r  r  rd  rn  r  r?  fromIdtoIdr  defaultClientTranIdr  s                 r=  r   zaster.transferH  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#!FFt{{SZ\bGcGcddddddddHH $-GK !EEdkkRY[aFbFbccccccccH
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  @   rK  )check_required_credentialsecdsaint_to_base16sumrjust)r;  r  r  r  r0  r1  r3  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   rx  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=r;  z!application/x-www-form-urlencodedzContent-Type)rR   r  bodyheaders)"implode_hostnamerM   	rawencoder5  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  rd  rG  rF  rR   r  r  defaultRecvWindowextendedParamsr-  queryorderidlistorigclientorderidlistorderidlistLengthorigclientorderidlistLengthr  rB  rM  
sortedKeyssigningPayloadrm  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  rG  rF  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  )ra  rC   throw_exactly_matched_exceptionr4  throw_broadly_matched_exceptionr#   )r;  rb  rc  rR   r  rG  rF  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   rp  r"   r   r  r	   r  r  r  r  dictr   r  r  r  r   r  r  r   r1  r6  r   r   r>  r   rO  rR  r   rV  rY  r   rd  rj  rs  rx  r{  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)  r3  r7  r;  r>  rB  rH  r   r
   rY  rX  rf  r  r  r   r  r  r  r  r  r  r  r  r    r   r!   r   r-  r  ra  rk  __classcell__)r<  s   @r=  r@   r@   *   s       z# z z z z z zx( (s (S (D ( ( ( (' 'c 'C '4 ' ' ' ' -/ = =: = = = =~ *, Y YV Y Y Y Yv ') 9 9S 9 9 9 9"
 
 
4 
 
 
 
4 8<$]ajl @L @L @LC @LWZ @Lquvzq{ @L @L @L @LDJ J Jv J J J J JX <@d[] 3A 3A 3AS 3A 3Abfglbm 3A 3A 3A 3Aj 37TX\eg 5I 5IC 5Is 5IRU 5I 5I 5I 5In @DB 1R 1RS 1R 1RS\ 1R 1R 1R 1Rf >BPTcgpr /O /Os /O# /O]` /O /O /O /ObW W4 W W6 W W W Wr 68 C3 C3 C3F C3 C3 C3 C3J 6:" 15 157 15 15 15 15 15f/
 /
6 /
[ /
 /
 /
 /
b <> 9 9s 9+ 9 9 9 9@ <@ ; ; ;| ; ; ; ;: @DB ; ;W ;S_ ; ; ; ;8) ) ) ) ) *, 7( 7( 7( 7( 7( 7(r DHPR ! ! !S ! ! ! !F 7;2 
 
 
 
 
 
, CGr Z Zd ZC Z Z Z Z,
 
T 
6 
EX 
 
 
 
 ;= 8 8c 8AT 8 8 8 8<	: 	: 	: 	: 	:
3S 
3 
3 
3 
3R R Rv R R R R Rh 8<B 2 2C 2 2 2 2 2B =A 2 2 2c 2 2 2 26 04$UYbd !A !A !AC !As !Aimnsit !A !A !A !AF 59tZ^gi =A =Ac =A =ATW =Anrsxny =A =A =A =A~ mqy{ $2 $2 $2I $2Y $2X] $2fi $2 $2 $2 $2L FH !+ !+$|*< !+ !+ !+ !+F os{} F3 F33 F3i F3y F3Z_ F3hk F3 F3 F3 F3P 59 !
 !
c !
 !
 !
 !
F 9=R 2 2S 2# 2 2 2 2@ AER >3 >3tCy >3# >3 >3 >3 >3@ ?C2  3     > 8<B !A !AW !A9 !A !A !A !AF'
 '
t '
V '
x '
 '
 '
 '
R ;?r #L #L #Lk #L #L #L #LJ
 
D 
* 
 
 
 
8 CGTXgkz~  HJ -V -VC -Vc -Vad -Vtw -V  OS  Tf  Og -V -V -V -V^$
 $
d $
F $
N` $
 $
 $
 $
L SU      . FH J J# Ju JL^ J J J J CE J Js JE JI[ J J J J
 
6 
 
 
 
4 9=4^bkm B B# BS BX[ B B B B>) )t )x ); ) ) ) )V
8 
8 
8 .2SW`b )C )Cs )C# )CS )Cgklwgx )C )C )C )CVW WF W W W Wr =A +P +P' +P +P +P +PZ 8<B ~ ~W ~4PX> ~ ~ ~ ~4   BS
 S
v S
 S
 S
 S
j @DB P PW P P P P. 38 0 0 0 0,: : :N N N! ! ! ! !F QU]_ >
 >
3 >
 >
 >
# >
do >
 >
 >
 >
@ ac E
 E
3 E
 E
C E
TW E
gt E
 E
 E
 E
N\ \ \> > > &eBSW @P @P @P @PDc 3 S # X\ dg        r>  r@   )F ccxt.async_support.base.exchanger   ccxt.abstract.asterr   rZ  rS  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>rz     s   6 5 5 5 5 5 + + + + + +   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>  