
    E#i                       S SK Jr  S SKJr  S SKrS SKrS SKJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#  S SK$J%r%  S SK&J'r'  S SK&J(r(  S SK&J)r)  S S	K&J*r*  S S
K&J+r+  S SK&J,r,  S SK&J-r-  S SK&J.r.  S SK&J/r/  S SK&J0r0  S SK&J1r1  S SK&J2r2  S SK&J3r3  S SK4J5r5  S SK6J7r7   " S S\\5      r8g)    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddress	IndexTypeIntLeverageLeverageTierLeverageTiersMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)NotSupported)OnMaintenance)InvalidNonce)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S\4S jjr0 4S\	4S jjr
0 4S\\   4S jjr0 4S jr0 4S	 jrS
0 4S\S\S\4S jjrSS\S\S\4S jjrS
S
0 4S\S\S\S\\   4S jjrSS\S\S\4S jjrSS
S
0 4S\S\S\S\S\\   4
S jjrSS\S\4S jjrS
0 4S\S\4S jjr0 4S\S\4S jjr SS\S\S\4S jjr!S
0 4S\4S  jjr"0 4S\S!\#4S" jjr$0 4S\S!\#4S# jjr%S
0 4S\S$\&S%\'S&\#S'\(4
S( jjr)S
S
0 4S) jr*S
S
0 4S* jr+S
S
0 4S+ jr,0 4S,\\-   4S- jjr.S
0 4S.\S\/4S/ jjr0S
S
S
0 4S\/S\S\S\\1   4S0 jjr2S
0 4S\/4S1 jjr3S
S
S
0 4S\/S\S\S\\1   4S2 jjr4S
S
S
0 4S\/S\S\S\\1   4S3 jjr5S
S
S
0 4S\/S\S\4S4 jjr6S
S
S
0 4S\/S\S\4S5 jjr7S
0 4S.\S\/4S6 jjr8S
0 4S7\\   S\/4S8 jjr9S
0 4S\/4S9 jjr:SS:\S\S\14S; jjr;S< r<S= r=S>\/4S? jr>S@ r?SSA\/4SB jjr@SC rA0 4S\\B   4SD jjrC0 4S\S\D4SE jjrES\F4SF jrGSG rH0 4S\F4SH jjrIS
S
S
0 4S\/S\S\4SI jjrJS
S
S
0 4S.\S\/S\S\4SJ jjrK0 4S\4SK jjrL0 4S\S&\#S\M4SL jjrN0 4S\S&\#S\M4SM jjrOS
0 4SN\PS\/4SO jjrQS
S
S
0 4S\/S\S\4SP jjrRSS\S\S4SQ jjrT0 4S\S\S4SR jjrU0 4S\S\S4SS jjrVS
S
S
0 4S\/S\S\4ST jjrWS
0 4S\S\X4SU jjrYSS\S\\Z   4SV jjr[SSW\\S\]4SX jjr^0 4SY\S\\]   4SZ jjr_0 4SY\S\]4S[ jjr`0 4SY\S\]4S\ jjraS
S
S
0 4SY\/S\S\S\\b   4S] jjrcS
S
S
0 4SY\/S\S\S\\b   4S^ jjrdSS_\SW\\S\b4S` jjreSSa jrf0 4S\4Sb jjrgS
0 4S\S\\h   4Sc jjriSSd\S\4Se jjrjS
0 4S.\SY\/S\k4Sf jjrlS
S
S
0 4SY\/S\S\S\\k   4Sg jjrm0 4SY\S&\#Sh\Si\S\k4
Sj jjrnSSk\SW\\S\k4Sl jjroSm rpS>\/S\/4Sn jrqS
0 4SY\S&\#So\Sp\/S\b4
Sq jjrrS
0 4Sr\sS\/4Ss jjrtS
0 4S\/4St jjruS
0 4Su\4Sv jjrvSSw jrwSSW\\4Sx jjrxS
0 4Su\4Sy jjrySSW\\4Sz jjrz0 4S\S\{4S{ jjr|SSN\S\S\{4S| jjr}0 S
4U 4S} jjr~S
S
S
0 4S\S\S\S\\h   4S~ jjrS
0 4S\S\/4S jjrS rSS0 S
S
4S jrSY\PS\S\S\S\S\4S jrSrU =r$ )mexc   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _SS_SS_SS_S S_0 S!S_S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S _S,S _S-S_S.S_S/S_S0S_S1S_E0 S2S_S3S_S4S_S5S_S6S_S7S _S8S_S9S_S:S_S;S_S<S _S=S_S>S _S?S_S@S_SASB_SCS_E0 SDS_SES_SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS _SPS _SQS_SRS_SSS_STS_E0 SUS_SVSB_SWS_SXS_SYS_SZS_S[S_S\S_S]S _S^S_S_S_S`S_SaS _SbS_ScS_SdSB_SeSB_E0 SfS_SgS_ShS_SiS _SjS_SkS_SlS_SmS_SnS_SoS_SpS_SqS_SrS _SsSB_StS_SuS _SvS_ESS SSSSSSSS S SSw.E_SxSySzSzS{.S|S|S{.S}S~S{.SS0S.SS/S/SS._SSSSSSSSSSSSSSSS.00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_ESSSSSSSSSSS.
E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS0SSSSSSSS.S.S{.S0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_00 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSS.E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S.S{.SSSSSSSSSSS.	0SSSSSSSSSSSSSSS.SSSSSS.SSSS.S.S{.SSSSSSSS.SSSSSSS.SS0S.0S._S[        _SSSSGS GSGSGSGSGSGSGS.
_GSGS	SSU R                  GS
5      U R                  GS
5      GS.0_GSSGSSSSGS.GSSSSGS.GS.0SSSSGS GSGSGSGSGSGS.	GSGSGSGSGSGSGSGSGSGSGS.
GS.SGSGSGS GS GS!GS"GS#.0 GS$GS%_GS&GS'_GS(GS)_GS*GS+_GS,GS-_GS.GS/_GS0GS1_GS2GS3_GS4GS5_GS6GS7_GS GS_GS8GS9_GS:GS;_GS<GS=_GS>GS?_GS@GSA_GSBGSC_GSDGSEGSFGSGGSHGSIGSJ.EGS;GS;GS;GS GSK.GSLGSMGSNGSO._GSPSSSSSSSGSQ.SSS SSSSGSR.SSSSSSSGSS.GSTGSU0SSGSVS SGSW.SSSSGSX.SS SSSGSY.SGSZGS[GS[SSSGS\.SGSZGS[GS[GS[SSSGS].GS^GSZ0GS_.	GS`SS0GSa.GS`SSSSGSQ.SSSSSSGSb.S SSGScGScGSd.GSeS0SSSSGSf.SSGScGScSSGSg.SSGScS GScSSGSh.GS^GSi0GSj.	GSkGSl0GSkGSl0GS.S S GS.GSm._GSn0 GSoGSp_GSqGSr_GSsGSt_GSuGSv_GSwGSx_GSyGSz_GS{GS{_GS|GS}_GS~GS_GSGS~_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGSGSGSGS.E_GS0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E[        [        [        [        [        [        [        [        [        [        [        [        [        [        GS.E[        [        [        [        [        [        [        [        [        [        [        GS.GS._5      $ (  Nidr3   namezMEXC Global	countriesSC	rateLimit2   versionv3	certifiedTprohasCORSspotmarginswapfutureFoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTriggerOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchL2OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfer)fetchTransfersfetchWithdrawalfetchWithdrawalsreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionModesignIntransferwithdrawurlszdhttps://user-images.githubusercontent.com/1294454/137283979-8b2a818d-8633-461b-bfca-de89e8c446b2.jpgzhttps://api.mexc.com)publicprivatez https://www.mexc.com/open/api/v2z)https://contract.mexc.com/api/v1/contractz(https://contract.mexc.com/api/v1/privater   z"https://api.mexc.com/api/v3/broker)rC   spot2contractbrokerzhttps://www.mexc.com/z&https://mexcdevelop.github.io/apidocs/zhttps://www.mexc.com/feez6https://www.mexc.com/register?inviteCode=mexc-1FQ1GNu1)logoapiwwwdocfeesreferralr   get   
      )pingtimeexchangeInfodepthtradeshistoricalTrades	aggTradesklinesavgPricezticker/24hrzticker/pricezticker/bookTickerzetf/infoorder   
openOrders   	allOrdersaccountmyTradestradeFeesub-account/listsub-account/apiKeyzcapital/config/getallzcapital/deposit/hisreczcapital/withdraw/historyzcapital/withdraw/addresszcapital/deposit/addresszcapital/transferzcapital/transfer/tranIdzcapital/transfer/internalz%capital/sub-account/universalTransferzcapital/convertzcapital/convert/listzmargin/loanzmargin/allOrderszmargin/myTradesmargin/openOrderszmargin/maxTransferablezmargin/priceIndexmargin/orderzmargin/isolated/accountzmargin/maxBorrowablezmargin/repayzmargin/isolated/pairzmargin/forceLiquidationReczmargin/isolatedMarginDatazmargin/isolatedMarginTierzrebate/taxQuery)
zrebate/detailzrebate/detail/kickbackzrebate/referCodezrebate/affiliate/commissionzrebate/affiliate/withdrawz"rebate/affiliate/commission/detailmxDeduct/enableuserDataStreamselfSymbolsasset/internal/transfer/recordz
order/testsub-account/virtualSubAccountsub-account/futureszsub-account/marginbatchOrderscapital/withdraw/applycapital/withdrawr   r   )r   r   r   r   r   r   r   )r   postputdeleter   detaild   support_currencieszdepth/{symbol}zdepth_commits/{symbol}/{limit}zindex_price/{symbol}zfair_price/{symbol}zfunding_rate/{symbol}zkline/{symbol}zkline/index_price/{symbol}zkline/fair_price/{symbol}zdeals/{symbol}tickerrisk_reversezrisk_reverse/historyzfunding_rate/historyzaccount/assetszaccount/asset/{currency}zaccount/transfer_recordzposition/list/history_positionszposition/open_positionszposition/funding_recordszposition/position_modezorder/list/open_orders/{symbol}zorder/list/history_ordersz&order/external/{symbol}/{external_oid}zorder/get/{order_id}zorder/batch_query   zorder/deal_details/{order_id}zorder/list/order_dealszplanorder/list/orderszstoporder/list/ordersz'stoporder/order_details/{stop_order_id})zaccount/risk_limitzaccount/tiered_fee_ratezposition/leveragezposition/change_marginzposition/change_leveragezposition/change_position_modezorder/submitzorder/submit_batch(   order/cancelzorder/cancel_with_externalzorder/cancel_allzaccount/change_risk_levelzplanorder/placezplanorder/cancelzplanorder/cancel_allzstoporder/cancelzstoporder/cancel_allzstoporder/change_pricezstoporder/change_plan_price)r   r   )	zmarket/symbolszmarket/coin/listzcommon/timestampzcommon/pingzmarket/tickerzmarket/depthzmarket/dealszmarket/klinezmarket/api_default_symbols)zaccount/infozorder/open_ordersz
order/listzorder/queryzorder/dealszorder/deal_detailzasset/deposit/address/listzasset/deposit/listzasset/address/listzasset/withdraw/listr   zaccount/balancezasset/internal/transfer/infozmarket/api_symbols)zorder/placezorder/place_batchzorder/advanced/place_batchasset/withdrawzasset/internal/transfer)r   zorder/cancel_by_symbolr   )r   r   r   )sub-account/universalTransferr   r   capital/deposit/subAddresszcapital/deposit/subHisrecz capital/deposit/subHisrec/getall)r   r   r   r   r   r   )rC   r   r   r   precisionMode
timeframes1m5m15m30m1h4h8h1d1w1M)
r   r   r   r   r   r   r   r   r   r   r   tradingz0.002)	tierBased
percentagemakertakeroptionsr   )zBTC/USDT:USDTzLTC/USDT:USDTzETH/USDT:USDTtypes)linearinverse)rC   rE   60m1W)	r   r   r   r   r   r   r   r   r   Min1Min5Min15Min30Min60Hour4Hour8Day1Week1Month1ETHERC20BTCLTC)r  USDTUSDCr  r  ZKSYNC	ZKSYNCERATRC20TRXTONTONCOINARBITRUMARBSTXSTACKSLUNCLUNASTARKSTARKNETAPTAPTOSPEAQPEAQEVMAVAXCAVAX_CCHAINACAACALABEP20BSCOPTIMISMOPASTRASTARBTMBTM2CRC20CRONOSDOTASSETHUBETFHECOROSEOKTRBTC)DOTETHFHRC20OASISOKCRSK)zBNB Smart Chain(BEP20-RACAV1)zBNB Smart Chain(BEP20-RACAV2)zBNB Smart Chain(BEP20)zEthereum(ERC20)  l   W CCXT)adjustForTimeDifferencetimeDifferenceunavailableContractsr   useCcxtTradeIdr   defaultTypedefaultNetworkdefaultNetworksnetworksnetworksById
recvWindowmaxTimeTillEndr   features)lastmarkindex)IOCFOKPOGTD)
marginModetriggerPricetriggerDirectiontriggerPriceTypestopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax      )rY  limitdaysBack	untilDayssymbolRequired)rY  triggerrb  rn  )rY  rk  ro  rb  rn       )rY  rk  rl  rm  ro  rb  rn  )rY  rk  rl  daysBackCanceledrm  ro  rb  rn  rk  )	sandboxrU   rV   r   r   r   r   rj   r   default)extendsrm   )rZ  r\  r[  r]  r^  ra  rc  rd  Z   )rY  rk  rl  rm  rY  )rY  rk  ro  rb  )rY  rk  rl  rm  ro  rb  )rY  rk  rl  rr  rm  ro  rb    )	ru  rU   rV   r   r   r   r   rj   r   ru  	forDerivs)rt  rC   rx  rE   rF   commonCurrenciesBEYONDPROTOCOLBEYONDBIFIBIFIFBYNBEYONDFICOFICOFIXDFI
DFISTARTERDFTDFUTUREDRKEGCEGORASCREDITFLUX1FLUXFREEFREEROSSDAOGASGASDAOGASNEOGMTGMTTOKENSTEPNHEROSTEPHEROMIMOMIMOSAPROSFINANCESINCITYTOKENSOULSWAPXBT)PROSSINSOULr  
exceptionsz-1128z-2011z-112110101200920113000433333444441002300193000520032005400600700118800488009880138801570000326602100011000710015100721007310095100961009710098100991010010102101031020010201102021020610211102121021610219102221023210259102651026820001200022222230000300013000230003300103001430016300183002030021300253002630027300283002930032300413008760005700001700002700004700005700006700007700008700013730001730002730000730003730100)730600730601730602730700730701730702730703730704730705730706730707730101140001140002)z+Order quantity error, please try to modify.z*Combination of optional parameters invalidzapi market order is disabledzContract not allow place order!OversoldzInsufficient positionzInsufficient balance!z'Bid price is great than max allow pricezInvalid symbol.zParam error!maintenance)exactbroad)deep_extendsuperr3   describer0   parse_numberr(   r)   r*   r,   r%   r#   r/   r$   r&   r.   )self	__class__s    Q/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/mexc.pyr  mexc.describe   s   dD : < ?
&?
M?
 $?
 	?

 t?
 ?
 4?
  sss $s 	s
 %s %s Ts $Us 's s "4s ts s $Us  s  '!s" /#s$ ,T%s& 0's( t)s* +s, &t-s. (/s0 '1s2 (3s4 "45s6 %d7s8 49s: T;s<  =s> ?s@  AsB &uCsD "5EsF +EGsH )%IsJ #EKsL ,UMsN &tOsP #DQsR $TSsT 'UsV (WsX "4YsZ [s\ &t]s^ (_s` 1$asb  csd *:esf +Dgsh &tisj 'ksl (msn #Dosp *4qsr $Usst "4usv *5wsx +Eysz )%{s| #D}s~ ts@ #DAsB  CsD !%EsF %dGsH /IsJ "5KsL +JMsN OsP !$QsR  SsT dUsV $UWsX +EYsZ !$[s\ "4]s^ d_s` !$asb "4csd tesf #Dgsh  isj '
ksl $Tmsn !$osp (qsr %dsst )%usv twsx tysz {s| T}s~ ts@ "4AsB #ECsD %dEsF &zGsH 'IsJ $TKsL  MsN #'#'$( $$)',#!%#'  es?
x ~ #9#9
 #E#E
 #N#M!
 "#G" /< / U5y?
p  $%$%,.%&&'01)*&'()+,,-12() $- #Q- (!-  (-  &r	- 
 '-  '-  /-  1!-  4R-  5a-  7-  7-  6r-  /-  6q-   8!- " DQ#- $ .q%- & 3A'- ( *1)- * /+- , .q-- . 0/- 0 5a1- 2 03- 4 +A5- 6 6q7- 8 3A9- : +A;- < 3A=- > 9!?- @ 8A- B 8C- D .qE- F ./6701;<9:BC/0./+,>@Y- \!#Q!(!! <Q! 1!	!
 21! 1!! *2! 5a! /! /! 8! 6q! DQ! .r! .q!  -a!!& -a  &'*+23,-12./01#IM %`F   "A $c  1!  -a	 
 =a  3A  21  4Q  -a  9!  8  -a  %a  +A  3A   3A! * ,a 6  6q  >q	 
 6q  7  5a  >q  8  Ea  3A  0  <Q  5a  4Q   4Q! " Fq# $ 347812) ,!4a!6! <Q! +A	!
 1"! +A! 9!! /! 8! .q! /! 3A! /! 3A! 5a!  :1!!/) +?D ./0101+,-.,-,-,-:;
  -.12*++,+,12:;232334>@/1<>23 " ,-12:;./79! -.67./#1 ,\ =>0123:;9:@A  >?23:;67=>34! 1!## _fq?
~ Y?
@ A?
X !&"&!..w7!..w7	Y?
h +0"#%)%)%))  $&*',!! #' #"$$#""""
 %$&&%%%$%&2  &"' ##  $@k@U@ 9@ 	@
 8@ F@ Z@ 7@ I@ ]@ U@ 7@ U@ @* G+@< 6=@D XE@N )!## !]@D 6;5:.3'.	!$ '"7 SJi?
~ $&*(-,1$)$)%*-
 */+06:#'#'"&#(	( #'$)$(+/27/4#(1$6 r% ',!$$&%)*.& ',#($)*.	# '+!%#($)*.( '+!%$%%&#($)*.$ '+!%$%,-%&#($)*.	*  #MIV  )!4(  )(,$($(%)-
 -1).+0"&$(+0$ %)&+!$$&%'	& %e# ',!$#'$)	( ',!$$&%'#'$)$ ',!$$&,0%'#'$)*  #c4n "; "; 	 ##]R?
d  ! (!! z! 	!
 |! y! u! ~! ! ! ! x! %! z! !  
!!" #!$ &%"+!e?
R fZf Zf Y	f
 .f Lf Jf .f Zf Zf Lf Zf \f Lf -f  :!f$ :%f& -'f( .)f* ]+f, \-f. ./f0 l1f2 -3f4 .5f6 07f8 Y9f: Z;f< Z=f> Z?f@ \AfB \CfD \EfF \GfH ZIfJ ZKfL \MfN ]OfP ZQfR ZSfT ZUfV ZWfX ZYfZ Z[f\ ]]f^ ]_f` Zafb Zcfd ]eff ]gfh Zifj ]kfl ]mfn Zofp ]qfr \sft \ufv \wfx \yfz \{f| \}f~ -f@ 0AfB ZCfD \EfF ZGfH \IfJ \KfL \MfN \OfP \QfR \SfT ]UfV 1WfX 1YfZ j[f\ l]f^ j_f` 1afb jcfd 1eff jgfh jifj mkfl mmfn mofp )((((((((((((1KfP DNBL4>7C 1->->?K'0$.#0QuS?
  	    c                   #    U R                  SSU5      u  p#SnSnSnUS:X  aX  U R                  U5      I Sh  vN n[        UR                  5       5      n[	        U5      nU(       a  U R                  U5      OSnO[US:X  aU  U R                  U5      I Sh  vN nU R                  US5      (       a  SOU R                  U5      nU R                  US5      nUUSSUS.$  N NJ7f)	a  
the latest known information on the availability of the exchange API

https://mexcdevelop.github.io/apidocs/spot_v3_en/#test-connectivity
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-server-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
r   NrC   okrE   successdata)statusupdatedurletainfo)	handle_market_type_and_paramsspotPublicGetPinglistkeyslenjsoncontractPublicGetPing
safe_valuesafe_integer)	r  params
marketTypequeryresponser  r  r  lengths	            r	  fetch_statusmexc.fetch_status  s      !>>}dTZ[
!33E::H (DYF,2TYYx(F6!!77>>H "__XyAATtyyQYGZF''&9G
 	
 ; ?s#   6C#CAC#C!A	C#!C#c                   #    U R                  SSU5      u  p#SnUS:X  a+  U R                  U5      I Sh  vN nU R                  US5      $ US:X  a+  U R                  U5      I Sh  vN nU R                  US5      $ g NH N7f)a  
fetches the current integer timestamp in milliseconds from the exchange server

https://mexcdevelop.github.io/apidocs/spot_v3_en/#check-server-time
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-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
r   NrC   
serverTimerE   r  )r  spotPublicGetTimer  r  )r  r  r  r   r!  s        r	  
fetch_timemexc.fetch_time  s      !>>{DRXY
!33E::H $$X|<<6!!77>>H $$Xv66 ; ?s!   2BA=0B%A?&B?Bc                   #    U R                  S5      (       d  0 $ U R                  U5      I Sh  vN n0 n[        S[        U5      5       GH/  nX$   nU R	                  US5      nU R                  U5      n0 nU R                  US/ 5      n	[        S[        U	5      5       H  n
X   nU R                  USS5      nU R                  U5      nUUUSU R                  USS5      U R                  US	S5      U R                  US
5      SSU R	                  US5      U R	                  US5      S.0U R	                  US5      S.
X'   M     U R                  UUUU R	                  US5      SSSSSSSSS.0SUS.5      X7'   GM2     U$  GNR7f)a  
fetches all available currencies on an exchange

https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
FNr   coinnetworkListnetWorknetworkdepositEnablewithdrawEnablewithdrawFeer   withdrawMinwithdrawMaxminrh  r   )
r  r7   r.  activer]   r   fee	precisionlimitsr   r8   amountcrypto)r  r7   coder8   r6  r]   r   r7  r8  r9  typerM  )check_required_credentials!spotPrivateGetCapitalConfigGetallranger  safe_stringsafe_currency_coder  safe_string_2network_id_to_code	safe_boolsafe_numbersafe_currency_structure)r  r  r!  resulticurrencyr7   r<  rM  chainsjchain	networkIdr.  s                 r	  fetch_currenciesmexc.fetch_currencies   s     ..u55I??GGN q#h-(A{H!!(F3B**2.DH__X}bAF1c&k*	 ..uiK	11)<!#&"#~~e_eL $u6F N++E=A!%"#'#3#3E=#I#'#3#3E=#I% !% 0 0
 C%!	 +*  77 ((6: !## !$#9 FL7 )\ m Hs   -FFEFc                   #    U R                   S   (       a  U R                  5       I Sh  vN   U R                  U5      nU R                  U5      n[        R
                  " X#/6 I Sh  vN u  pEU R                  XE5      $  NU N7f)aO  
retrieves data on all markets for mexc

https://mexcdevelop.github.io/apidocs/spot_v3_en/#exchange-information
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-information

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
rF  N)r  load_time_differencefetch_spot_marketsfetch_swap_marketsasynciogatherarray_concat)r  r  spotMarketPromiseswapMarketPromise
spotMarket
swapMarkets         r	  fetch_marketsmexc.fetch_markets  s|      <<12++--- 33F; 33F;'.~~8I7]'^!^
  88	 . "_s!   (BB =B(B)BBc                 0  #    U R                  U5      I Sh  vN nU R                  US/ 5      n/ n[        S[        U5      5       GH  nX5   nU R	                  US5      nU R	                  US5      nU R	                  US5      n	U R                  U5      n
U R                  U	5      nU R	                  US5      nU R                  US5      nS	nUS
:X  a	  U(       a  SnU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUR                  0 SU_SU
S-   U-   _SU
_SU_SS_SU_SU	_SS_SS_SS_SU_SS	_SS	_SS	_SU_SS	_S S_SUUSSSSSU R                  U R                  U R	                  US!5      5      5      U R                  U R                  U R	                  US"5      5      5      S#.SSS$.U R                  US%5      SS$.SSS$.U R                  US&5      US$.S'.SUS(.E5        GM     U$  GN7f))a,  
@ignore
       retrieves data on all spot markets for mexc

       https://mexcdevelop.github.io/apidocs/spot_v3_en/#exchange-information

       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: an array of objects representing market data
       Nsymbolsr   symbol	baseAsset
quoteAssetr  isSpotTradingAllowedF1TisMarginTradingAllowedmakerCommissiontakerCommissionmaxQuoteAmountr7   /basequotesettlebaseIdquoteIdsettleIdr=  rC   rD   rE   rF   rG   r6  r   r  baseAssetPrecisionquoteAssetPrecisionr:  pricer4  baseSizePrecisionquoteAmountPrecisionrc  r:  rs  costr  r  r   contractSizeexpiryexpiryDatetimestrike
optionTyper8  r9  createdr  )
spotPublicGetExchangeInfor  r@  r  rA  rB  rF  appendr  parse_precision)r  r  r!  r  rH  rI  marketr7   rm  rn  rj  rk  r  rc  r6  re  rf  rg  rh  s                      r	  rS  mexc.fetch_spot_markets  s     77??V xB7q#d)$AWF!!&(3B%%fk:F&&v|<G**62D++G4E%%fh7F#'??6;Q#R F#$8%)__V=U%V""..v7HIO"..v7HIO!--f6FGNMM 2b2$*u,2 2 	2
 $2 &2 72 D2 2 2 02 2 %2 %2 &2  E!2" $#2$  (( $"&""//0D0DTEUEUV\^rEs0tu!..t/C/CDDTDTU[]rDs/tu  $#!
  $//8KL#
  $#
  $//8NO-$  c2 2! %F a @s   HHG<Hc                 P  #    U R                   nU R                  U SS5        U R                  U5      I Sh  vN nU R                  U SU5        U R                  US/ 5      n/ n[	        S[        U5      5       GH  nXF   nU R                  US5      nU R                  US5      n	U R                  US5      n
U R                  US	5      nU R                  U	5      nU R                  U
5      nU R                  U5      nU R                  US
5      nX:H  nUR                  0 SU_SUS-   U-   S-   U-   _SU_SU_SU_SU	_SU
_SU_SS_SS_SS_SS_SS_SS_SUS:H  _SS_SU_U(       + U R                  US 5      U R                  US!5      U R                  US"5      SSSSU R                  US#5      U R                  US$5      S%.U R                  US&5      U R                  US'5      S(.U R                  US)5      U R                  US*5      S(.SSS(.SSS(.S+.SUS,.E5        GM     U$  GN7f)-a8  
@ignore
       retrieves data on all swap markets for mexc

       https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-information

       :param dict [params]: extra parameters specific to the exchange API endpoint
       :returns dict[]: an array of objects representing market data
       r;   r   Nr  r   r`  baseCoin	quoteCoin
settleCoinstater7   ri  :rj  rk  rl  rm  rn  ro  r=  rE   rC   FrD   TrF   rG   r6  0r   r  takerFeeRatemakerFeeRatery  volUnit	priceUnitrr  minLeveragemaxLeverager4  minVolmaxVolrv  rx  )
r;   set_propertycontractPublicGetDetailr  r@  r  rA  rB  r  rF  )r  r  	currentRlr!  r  rH  rI  r  r7   rm  rn  ro  rj  rk  rl  r  isLinears                    r	  rT  mexc.fetch_swap_markets  s     !NN	$R055f==$Y7Z x4q#d)$AWF!!&(3B%%fj9F&&v{;G''=H**62D++G4E,,X6F$$VW5EHMM 2b2$*u,s2V;2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 5C<2  D!2" (#2$  (<))&.A))&.A $ 0 0 H"&""..vyA!--fkB  $//F#//F!
  $//A#//A
  $#
  $#$  c2 2 %| ] >s   4H&H#G-H&Nr`  rk  c                 b  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X%S'   SnUS   (       ac  U R                  U R                  XS5      5      I Sh  vN nU R	                  US5      nU R                  XqU5      nU R	                  US5      US'   U$ US	   (       as  U R                  U R                  XS5      5      I Sh  vN nU R                  US
5      n	U R	                  U	S5      n
U R                  XU
5      nU R	                  U	S5      US'   U$  GN N NV7f)a]  

https://mexcdevelop.github.io/apidocs/spot_v3_en/#order-book
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-s-depth-information

fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr`  r7   rk  rC   	timestamplastUpdateIdnoncerE   r  r=   )load_marketsr  spotPublicGetDepthextendr  parse_order_bookcontractPublicGetDepthSymbolr  )r  r`  rk  r  r  request	orderbookr!  spotTimestampr  r  s              r	  fetch_order_bookmexc.fetch_order_book  s>     !!!V$fTl
 $G	&>!44T[[5QRRH !--hDM--hNI!%!2!28^!LIg2 1 F^!>>t{{7?[\\H& ??8V4D))$<I--dIFI!%!2!24!CIge 	" S$ ]s6   D/D(AD/)D+*A,D/D-AD/+D/-D/priceKey	amountKeycountOrIdKeyc                     SnU R                  X5      nU R                  X5      nU R                  X5      nUb  XgU/$ Xg/$ )Nr   )rF  )	r  bidaskr  r  r  countKeyrs  r:  counts	            r	  parse_bid_askmexc.parse_bid_ask  sP      2!!&4  25))r  sincec                   #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X6S'   SnUS   (       Ga@  U R                  USS/5      nUb  X&S'   Uc  [        U R                  S	-   5      eUb  Uc  [        U R                  S
-   5      eXS'   U R                  U R                  SS5      n	U R                  USU	5      n	U R                  US/5      nU	S:X  a)  U R                  U R                  Xd5      5      I Sh  vN nOU	S:X  a)  U R                  U R                  Xd5      5      I Sh  vN nOU	S:X  a)  U R                  U R                  Xd5      5      I Sh  vN nO\[        U R                  S-   5      eUS   (       a:  U R                  U R                  Xd5      5      I Sh  vN n
U R                  U
S5      nU R                  XuX#5      $  GN N N Nz N17f)a  

https://mexcdevelop.github.io/apidocs/spot_v3_en/#recent-trades-list
https://mexcdevelop.github.io/apidocs/spot_v3_en/#compressed-aggregate-trades-list
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-transaction-data

get the list of most recent trades for a particular symbol
: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
:param int [params.until]: *spot only* *since must be defined* the latest time in ms to fetch entries for
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nr`  r7   rk  rC   endTimeuntil	startTimezA fetchTrades() requires an until parameter when since is providedz@ fetchTrades() requires a since parameter when until is providedfetchTradesMethodspotPublicGetAggTradesmethodspotPublicGetHistoricalTradesspotPublicGetTradesz& fetchTrades() not support self methodrE   r  )r  r  safe_integer_nr'   r7   rA  r  omitr  r  r  r  r-   contractPublicGetDealsSymbolr  parse_trades)r  r`  r  rk  r  r  r  r   r  r  r!  s              r	  fetch_tradesmexc.fetch_trades  s     !!!V$fTl
 $G&>>''G0DEE ',$=+DGG6y,yzz =+DGG6x,xyy%*	"%%dll4GIabF%%fh?FYYvz2F11#::4;;w;WXX::#AA$++gB^__00#77G8TUU"477-U#UVV> F^!>>t{{7?[\\H" __Xv6F  >>] 	", Y_UD ]sY   G(GC4G(G .G(:G";.G()G$*A
G(4G&5)G( G("G($G(&G(trader  c                    S nS nS nS nS nS nS n	S n
S nS nS nSU;   ar  U R                  US5      nU R                  S U5      nUS   nU R                  US5      nU R                  US5      nU R                  U R                  US5      5      n	Sn
GOU R                  US5      nU R                  X5      nUS   nU R	                  USS5      nU R	                  US	S5      nU R                  US
5      nSU;   a  U R                  US5      nU R                  US5      nU R                  U R                  US5      5      n	U R                  US5      U R                  U R                  US5      5      S.nU R                  US5      (       a  SOSn
OU R                  USS5      nU R	                  USS5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  USS5      nUb  U(       a  SOSn
Ub  U(       a  SOSn	Ub  U(       a  SOSn	Sn
U R                  US5      nUb$  U R                  US5      U R                  U5      S.nUc5  U R                  U R                  SS 5      (       a  U R                  XIXU
5      nU R                  UUUU R                  U5      UUU	U
UUUUUS!.U5      $ )"Nvtr`  pTr  r7   ars  orderIdpositionModer  volsider7  feeCurrencyrw  rJ  r   r   qtyqquoteQtyisBuyerisMakerisBuyerMakermbuysellcommissionAsset
commissionrI  T)r7   r   r  datetimer`  r=  r  takerOrMakerrs  r:  rw  r7  r  )r  safe_marketrA  parse_order_siderC  rB  r  safe_integer_2safe_value_2rE  r  create_ccxt_trade_id
safe_tradeiso8601)r  r  r  r7   r  r  r`  r7  r=  r  r  priceStringamountString
costStringmarketIdr  r  
buyerMakerfeeAssets                      r	  parse_trademexc.parse_trade8  s   	
%< ))%5I%%dF3FH%F**5#6K++E37L(()9)9%)EFD"Lh ''x8H%%h7FH%F##E45B,,UGSAK&&ui8G& --e[A	#//u=,,T-=-=eV-LM ,,UE: $ 7 78H8HP]8^ _ +///%*I*Iww //vsC	#11%D!--eZ@
//%;//%;!..uncJ
&.577L&$+5D)%/6UD#*L++E3DE' $ 0 0 E$($;$;H$EC :$..7GNN**9LWcdB"Y/( " 
  	r  r   	timeframec           	        #    U R                  5       I Sh  vN   U R                  U5      nUS   (       a  SOSnSnU R                  USSS5      u  pU(       a  U R                  SXXBXW5      I Sh  vN $ U R	                  U R
                  S0 5      n	U R	                  XS	   0 5      n
U R                  X5      nU R                  U5      S-  nUS
   US.nSnUS   (       a  U R                  USS/5      nUb:  X=S'   Uc3  U R                  X7U-  5      nU R                  5       n[        UU5      US'   Ub  XMS'   Ub  U R                  US/5      nXS'   U R                  U R                  X5      5      I Sh  vN nUnGOIUS   (       Ga>  U R                  USS/S5      nUb  U R!                  US-  5      US'   Ub  U R                  US/5      nXS'   U R                  USS5      nU R                  US5      nSnUS:X  a)  U R#                  U R                  X5      5      I Sh  vN nOvUS:X  a)  U R%                  U R                  X5      5      I Sh  vN nOGUS:X  a)  U R'                  U R                  X5      5      I Sh  vN nO[)        U R*                  S-   5      eU R	                  US5      nU R-                  USSSSSS5      nU R/                  XX#U5      $  GN GNm GNk N N Nf7f) a  

https://mexcdevelop.github.io/apidocs/spot_v3_en/#kline-candlestick-data
https://mexcdevelop.github.io/apidocs/contract_v1_en/#k-line-data

fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
NrC   rp  rw  Fr   paginater   r=  r7   )r`  intervalr  r  r  rk  rE   gMbP?startendrs  rt  rT  rS  zA fetchOHLCV() not support self price type, [default, index, mark]r  r   openhighlowcloser  )r  r  handle_option_and_params"fetch_paginated_call_deterministicr  r  rA  parse_timeframer  summillisecondsr5  r  spotPublicGetKlinesr  safe_integer_product_nparse_to_intcontractPublicGetKlineSymbol&contractPublicGetKlineIndexPriceSymbol%contractPublicGetKlineFairPriceSymbolr-   r7   convert_trading_view_to_ohlcvparse_ohlcvs)r  r`  r  r  rk  r  r  maxLimitr  r  r   timeframeValuedurationr  candlesr  r  nowr!  	priceTyper  s                        r	  fetch_ohlcvmexc.fetch_ohlcv  s      !!!V$"6N488z[`a@@v^cpv  B  B  B//$,,bA__WVnbA
))*@''	2T9Tl&
 &>'')0DEE ',$=((5X*=>C++-C),S#GI& #(  6G95%*	"!55dkk'6RSSH GF^^//)8LeTE #'#4#4UT\#B  6G95!&(()DIYYvw/FHI%!%!B!B4;;wC_!``g%!%!L!LT[[Y`Mi!jjf$!%!K!KDKKX_Lh!ii"477-p#pqq  ??8V4D88vvvW\^eglmG  )EJJc 	" B0 T6 ajism   K)KAK)0K1DK)5K 6B,K)"K##.K)K%.K) K'AK)K) K)#K)%K)'K)c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r   r   r      r   )r  rF  )r  ohlcvr  s      r	  parse_ohlcvmexc.parse_ohlcv%  sl    eQ'UA&UA&UA&UA&UA&
 	
r  r_  c                   #    U R                  5       I Sh  vN   0 nSnSnUb3  [        U5      nUS:H  nU R                  US5      nU R                  U5      nU R	                  SXB5      u  pSn
U(       a  US   US'   US:X  a)  U R                  U R                  X95      5      I Sh  vN n
OAUS	:X  a;  U R                  U R                  X95      5      I Sh  vN nU R                  US
/ 5      n
U(       a  U
/n
U R                  X5      $  N Nc N67f)aO  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://mexcdevelop.github.io/apidocs/spot_v3_en/#24hr-ticker-price-change-statistics
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-trend-data

:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr   r   r   r7   r`  rC   rE   r  )
r  r  rA  r  r  spotPublicGetTicker24hrr  contractPublicGetTickerr  parse_tickers)r  r_  r  r  r  isSingularMarketr"  firstSymbolr  r   tickersr!  s               r	  fetch_tickersmexc.fetch_tickers/  s     !!! \F%{**7A6K[[-F >>~v^
 &tGH 88W9TUUG2 6!!99$++g:UVVH8 ooh;GiG!!'33Q 	" V4 Ws4   DDBD%D	&.DD3D	DDc                   #    U R                  5       I Sh  vN   U R                  U5      nU R                  SX25      u  pESnSUS   0nUS:X  a)  U R                  U R	                  Xu5      5      I Sh  vN nOAUS:X  a;  U R                  U R	                  Xu5      5      I Sh  vN nU R                  US0 5      nU R                  Xc5      $  N NY N,7f)a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://mexcdevelop.github.io/apidocs/spot_v3_en/#24hr-ticker-price-change-statistics
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-trend-data

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r`  r7   rC   rE   r  )r  r  r  r  r  r  r  parse_ticker)	r  r`  r  r  r  r   r   r  r!  s	            r	  fetch_tickermexc.fetch_ticker  s      !!!V$ >>}f]
fTl
 77G8STTF. 6!!99$++g:UVVH4 __Xvr:F  00y 	" U0 Ws4   CC
AC2C3.C!C")CCCr   c                    U R                  US5      nU R                  X25      nS nS nS nS nS nS n	S n
S nS nS nS nS nS nU R                  US5      nU(       d  SU;   a  U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  US	5      nU R                  US
5      nU R                  US5      n[        R
                  " US5      nGO=U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R                  " US5      (       a  S n[        R                  " US5      (       a  S nU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n[        R
                  " US5      nU R                  0 SUS   _SU_SU R                  U5      _SU_SU_SU_SU R                  US 5      _S!U_S"U_S#U_S$U_S%S _S&U_S'U_S(U_S)S _S*U	_U
US+.EU5      $ ),Nr`  rE   r  bid1ask1volume24amount24high24Pricelower24PriceriseFallValueriseFallRate100	closeTimebidPriceaskPricebidQtyaskQtyr  volumequoteVolume	openPrice	highPricelowPriceprevClosePricepriceChangepriceChangePercentr  r  r  r  r  	lastPricebid	bidVolumeask	askVolumevwappreviousClosechanger   average
baseVolume)r)  r  )	rA  r  r  r  r1   
string_mul	string_eqsafe_tickerr  )r  r   r  r  r  r1  r3  r2  r4  r9  r)  r  r  r  
changePcntchangeValue	prevCloseisSwaps                     r	  r  mexc.parse_ticker  sr   ##FH5!!(3			

	0kV+, ))&+>I""662C""662C))&*=J**6:>K##FM:D""6>:C**6?CK))&.AJ ++J>J0 ))&+>I""6:6C""6:6C((:I((:I  C00 	  C00 	))&(;J**6=AK##FK8D##FK8D""6:6C((1ABI**6=AK))&2FGJ ++J>J !
fX&!
!
 Y/!
 D	!

 D!
 3!
 T%%fk:!
 3!
 !
 3!
 !
 D!
 Y!
 k!
 *!
  t!!
" *#!
$ ''!
( ) 	r  c                   #    U R                  5       I Sh  vN   SnSnUb$  [        U5      nUS:H  nU R                  US   5      nU R                  SX25      u  pgSnUS:X  a  U R	                  U5      I Sh  vN nO$US:X  a  [        U R                  S-   U-   S	-   5      eU(       a  U/nU R                  X5      $  N NF7f)
a  
fetches the bid and ask price and volume for multiple markets

https://mexcdevelop.github.io/apidocs/spot_v3_en/#symbol-order-book-ticker

:param str[]|None symbols: unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr   r   ra   rC   rE   z& fetchBidsAsks() is not available for z markets)r  r  r  r  spotPublicGetTickerBookTickerr-   r7   r  )	r  r_  r  r  r  r"  r  r   r  s	            r	  fetch_bids_asksmexc.fetch_bids_asks>  s      !!! \F%{[[,F >>PV_
 >>uEEG 6!tww)QQT^^akklliG!!'337 	" Fs#   B?B;AB?6B=7AB?=B?rw  c                 
  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSU0nU R	                  USSSSU R                  XS5      5      I Sh  vN $  Nh N7f)a  
create a market buy order by providing the symbol and cost

https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrC   9 createMarketBuyOrderWithCost() supports spot orders onlyrw  r  r  r   r  r  r-   r7   create_orderr  r  r`  rw  r  r  reqs         r	  !create_market_buy_order_with_cost&mexc.create_market_buy_order_with_coste  s      !!!V$f~tww)ddeeD
 &&vx4UXIabbb 	" c"   BA?A#B:B;BBc                 
  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSU0nU R	                  USSSSU R                  XS5      5      I Sh  vN $  Nh N7f)a  
create a market sell order by providing the symbol and cost

https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
NrC   rG  rw  r  r  r   rH  rJ  s         r	  "create_market_sell_order_with_cost'mexc.create_market_sell_order_with_costy  s      !!!V$f~tww)ddeeD
 &&vxD$++VYJbccc 	" drN  r=  r  r:  rs  c           	        #    U R                  5       I Sh  vN   U R                  U5      nU R                  SU5      u  pUS   (       a  U R                  XrX4XXU	5      I Sh  vN $ U R	                  XrX4XXU	5      I Sh  vN $  Nk N" N7f)a  
       create a trade order

       https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
       https://mexcdevelop.github.io/apidocs/contract_v1_en/#order-under-maintenance
       https://mexcdevelop.github.io/apidocs/contract_v1_en/#trigger-order-under-maintenance

       :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 of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.marginMode]: only 'isolated' is supported for spot-margin trading
       :param float [params.triggerPrice]: The price at which a trigger order is triggered at
       :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
       :param bool [params.reduceOnly]: *contract only* indicates if self order is to reduce the size of a position
       :param bool [params.hedged]: *swap only* True for hedged mode, False for one way mode, default is False
       :param str [params.timeInForce]: 'IOC' or 'FOK', default is 'GTC'
EXCHANGE SPECIFIC PARAMETERS
       :param int [params.leverage]: *contract only* leverage is necessary on isolated margin
       :param long [params.positionId]: *contract only* it is recommended to hasattr(self, fill) parameter when closing a position
       :param str [params.externalOid]: *contract only* external order ID
       :param int [params.positionMode]: *contract only*  1:hedge, 2:one-way, default: the user's current config
       :param boolean [params.test]: *spot only* whether to use the test endpoint or not, default is False
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       NrU   rC   )r  r  handle_margin_mode_and_paramscreate_spot_ordercreate_swap_order)
r  r`  r=  r  r:  rs  r  r  rY  r   s
             r	  rI  mexc.create_order  s     8 !!!V$ >>}fU
&>//dE_deee//dE_deee 	" fes4   BBA
B!B"B=B>BBBc                    US   nUR                  5       n	US   U	UR                  5       S.n
US:X  a  U R                  USS5      nU R                  US5      nUb  UnU R                  X5      U
S'   O{Uc  U R	                  X5      U
S'   OcU R                  U5      nU R                  U5      n[        R                  " X5      nUnU R                  X5      U
S'   OU R	                  X5      U
S'   Ub  U R                  X5      U
S'   U R                  US	5      nUb  XS
'   U R                  USS	/5      nUb$  US:w  a  [        U R                  S-   U-   S-   5      eS nU R                  US:H  US:H  U5      u  nnU(       a  SU
S'   U R                  US5      nUb)  U R                  US5      nUS:X  a  SU
S'   OUS:X  a  SU
S'   U R                  X5      $ )Nr`  r7   )r`  r  r=  r  rw  quoteOrderQtyquantityrs  clientOrderIdnewClientOrderIdr=  isolatedz+ createOrder() does not support marginMode  for spot-margin tradingLIMIT_MAKERr`  rU  IMMEDIATE_OR_CANCELrV  FILL_OR_KILL)uppersafe_number_2r  cost_to_precisionamount_to_precisionnumber_to_stringr1   r:  price_to_precisionrA  r(   r7   handle_post_onlyr  )r  r  r=  r  r:  rs  rY  r  r`  	orderSider  rw  r  r  quoteAmountrZ  postOnlytifs                     r	  create_spot_order_requestmexc.create_spot_order_request  s   !JJL	TlJJL

 8%%ffoFDYYvv.F+/+A+A&+Q(=*.*B*B6*RGJ'#'#8#8#@L"&"7"7">K")"4"4\"OK(F/3/E/Ef/UGO,"&":":6"JGJ#66vEGG((A$*7&'YYv'@AF!Z' +X!X[e!e  iC  "C  D  D001A4=CXZ`a&+GFOv}5?YYv}5Fe|"7"0{{7++r  c           	        #    U R                  5       I Sh  vN   U R                  USS5      nU R                  US5      nU R                  XX4XVU5      n	Sn
U(       a  U R	                  U	5      I Sh  vN n
OU R                  U	5      I Sh  vN n
U R                  X5      nX;S'   X+S'   U R                  US5      c  X[S'   U R                  US5      c  XKS'   U$  N Ni NQ7f)aa  
@ignore
       create a trade order

       https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order

       :param str market: 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 of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param str [marginMode]: only 'isolated' is supported for spot-margin trading
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       NtestFr  r=  rs  r:  )r  rE  r  rl  spotPrivatePostOrderTestspotPrivatePostOrderparse_orderrA  )r  r  r=  r  r:  rs  rY  r  ro  r  r!  r   s               r	  rT  mexc.create_spot_order  s     " !!!~~ffe466*00tU`fg!::7CCH!66w??H(   2ffE7+3"'NE8,4$(OG 	" D?s5   CCAC1C2CCACCCc                   #    U R                  5       I Sh  vN   US   nU R                  U R                  S0 5      n	U R                  XS5      n
U
(       a  [	        U R
                  S-   U-   5      eSnUb*  US:X  a  SnO4US:X  a  S	nO+[        U R
                  S
-   5      eU R                  USS5      nUS:w  aB  US:w  a<  US	:w  a6  US:w  a0  US:w  a*  US:w  a$  US:w  a  US:w  a  [        U R
                  S-   5      eSnU R                  US:H  US:H  U5      u  pU(       a  SnOUS:X  a  S	nOUS:X  a  SnUS   [        U R                  X5      5      UUS.nUS:w  a)  US:w  a#  US:w  a  [        U R                  X5      5      US'   US	:X  a-  U R                  US5      nUc  [        U R
                  S-   5      eU R                  USS5      nU R                  USS5      nSnU(       a3  U(       a  U R                  US5      nUS:X  a  SOSnUS:X  a  S	OSnS	US'   OU(       a  US:X  a  SOSnO
US:X  a  S	OSnUUS'   U R                  USS5      nUb  UUS'   U R                  US S!5      nU R                  U/ S"Q5      nSnU(       a  U R                  UU5      US '   U R                  US#S	5      US#'   U R                  US$S	5      US$'   U R                  US%S	5      US%'   U R                  US&S	5      US&'   U R!                  U R#                  X5      5      I Sh  vN nO(U R%                  U R#                  X5      5      I Sh  vN nU R'                  US'5      nU R)                  SU0U5      $  GNS NV N/7f)(a  
@ignore
       create a trade order

       https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
       https://mexcdevelop.github.io/apidocs/contract_v1_en/#order-under-maintenance
       https://mexcdevelop.github.io/apidocs/contract_v1_en/#trigger-order-under-maintenance

       :param str market: 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 of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param str [marginMode]: only 'isolated' is supported for spot-margin trading
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param float [params.triggerPrice]: The price at which a trigger order is triggered at
       :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
       :param bool [params.reduceOnly]: indicates if self order is to reduce the size of a position
       :param bool [params.hedged]: *swap only* True for hedged mode, False for one way mode, default is False

EXCHANGE SPECIFIC PARAMETERS
       :param int [params.leverage]: leverage is necessary on isolated margin
       :param long [params.positionId]: it is recommended to hasattr(self, fill) parameter when closing a position
       :param str [params.externalOid]: external order ID
       :param int [params.positionMode]: 1:hedge, 2:one-way, default: the user's current config
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       Nr`  rH  Fz4 createSwapOrder() does not support yet self symbol:crossr   r\  r   zN createSwapOrder() marginMode parameter should be either "cross" or "isolated"openTyperk  r  r   r  r      z createSwapOrder() order type must either limit, market, or 1 for limit orders, 2 for post-only orders, 3 for IOC orders, 4 for FOK orders, 5 for market orders or 6 to convert market price to current pricer7   )r`  r  r=  rv  rs  rc  zK createSwapOrder() requires a leverage parameter for isolated margin orders
reduceOnlyra  r  r  r  r  rZ  externalOidrZ  	stopPrice)rZ  ry  rj  rz  rZ  ra  triggerTypeexecuteCycletrend	orderTyper  )r  r  r  rE  r-   r7   r'   r  r,   rg  floatrd  rf  r  rC  rb  !contractPrivatePostPlanorderPlacer  contractPrivatePostOrderSubmitrA  
safe_order)r  r  r=  r  r:  rs  rY  r  r`  rH  isContractUnavaiablerv  rj  r  rc  rx  ra  sideIntegerrZ  rZ  r!  r  s                         r	  rU  mexc.create_swap_order	  s    8 !!!!#t||=SUWX#~~.BERtww)__bhhii!W$z)'  3C  )C  D  D((Q?HGO$("2QRY]abYbimqriry}  BC  zC  JN  RS  JStww  *y   y  z  z001A419fUDW_DXDTl11&AB  #
4 AIDAIDH,<$T%<%<V%KLGGq=((<H'2(  A  A^^FL%@
%86<8"&%-ve $!AK&'GN#$(EMa$(EMa%**6?MR$%2GM"))&.+N6#vw&*&=&=fl&SGN#%)%6%6v}a%PGM"&*&7&7PQ&RGN##00!DGG#'#4#4V[!#LGK !CCDKKPWD`aaH!@@WA]^^H &1d|V44A 	"j b^s4   M0M)K>M0M,(M0>M.?+M0,M0.M0ordersc           
        #    U R                  5       I Sh  vN   / nSn[        S[        U5      5       GH  nX   nU R                  US5      nU R	                  U5      nUS   (       d  [        U R                  S-   5      eUc  UnOXG:w  a  [        U R                  S-   5      eU R                  US5      n	U R                  US5      n
U R                  US	5      nU R                  US
5      nU R                  US0 5      nSnU R                  SU5      u  pU R                  XXXU5      nUR                  U5        GM	     SU R                  U5      0nU R                  U5      I Sh  vN nU R                  U5      $  GNf N7f)a  
*spot only*  *all orders must have the same symbol* create a list of trade orders

https://mexcdevelop.github.io/apidocs/spot_v3_en/#batch-orders

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]: extra parameters specific to api endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r`  rC   z2 createOrders() is only supported for spot marketsz; createOrders() requires all orders to have the same symbolr=  r  r:  rs  r  rU   r   )r  r@  r  rA  r  r-   r7   r(   r  rS  rl  r  r  spotPrivatePostBatchOrdersparse_orders)r  r  r  ordersRequestsr`  rI  rawOrderr  r  r=  r  r:  rs  orderParamsrY  orderRequestr  r!  s                     r	  create_ordersmexc.create_orders	  s     !!!q#f+&AyH''(;H[[*F&>"477-a#abb~!%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAKJ!%!C!CMSY!ZJ99&V[ituL!!,/' '* 499^4
 88AA*   **_ 	"4 Bs"   FE<EF&E?'F?Fr7   c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nSnUS   (       a  U R	                  US5      nUb  U R                  US5      nXuS'   OXS'   U R                  S	U5      u  pUbM  US
:w  a  [        U R                  S-   U-   S-   5      eU R                  U R                  XY5      5      I Sh  vN nOqU R                  U R                  XY5      5      I Sh  vN nOHUS   (       a>  XS'   U R                  U R                  XS5      5      I Sh  vN n
U R                  U
S5      nU R                  Xd5      $  GN? N Nc N.7f)a%  
fetches information on an order made by the user

https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-order
https://mexcdevelop.github.io/apidocs/contract_v1_en/#query-the-order-based-on-the-order-number

: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
:param str [params.marginMode]: only 'isolated' is supported, for spot-margin trading
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz( fetchOrder() requires a symbol argumentr`  r7   rC   rZ  origClientOrderIdr  r   r\  z* fetchOrder() does not support marginMode r]  rE   order_idr  )r'   r7   r  r  rA  r  rS  r(   spotPrivateGetMarginOrderr  spotPrivateGetOrder!contractPrivateGetOrderGetOrderIdr  rr  )r  r7   r`  r  r  r  r  rZ  rY  r   r!  s              r	  fetch_ordermexc.fetch_order	  s     >#DGG.X$XYY!!!V$fTl
 &> ,,V_EM(6?;/<+,%'	" $ B B<QW XJ%+$TWW/[%[^h%h  lF  &F  G  G!;;DKK<WXX!55dkk'6QRRZ F^"$J!CCDKKPWD`aaHB ??8V4D--I 	"" YR^ bsF   /E9E0B6E9(E3)(E9E56E9E7	(E93E95E97E9c                   #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   U R                  US5      nU R                  US5      nU R	                  SXd5      u  pUS:X  a  Uc  [        U R                  S-   5      eU R                  SU5      u  pUb  X%S'   Ub  XuS	'   Ub  X5S
'   SnU
bM  U
S:w  a  [        U R                  S-   U
-   S-   5      eU R                  U R                  X[5      5      I Sh  vN nO(U R                  U R                  X[5      5      I Sh  vN nU R                  XX#5      $ Ubn  X%S'   U R                  USU5      nUc"  U R                  X R                  S   5      US'   O]X-
  U R                  S   :  a  [        U R                  S-   5      eXuS'   O+Ub(  U R                  XpR                  S   S-  5      US'   XuS'   Ub  X5S'   U R                  U R                  SS5      nU R                  U	SU5      n/ n/ nUS:X  a;  U R!                  U R                  XY5      5      I Sh  vN nU R#                  US5      nO:U R%                  U R                  XY5      5      I Sh  vN nU R#                  US5      nU R'                  UU5      nU R                  UXbX45      $  GN GN GN N NF7f)aB  
fetches information on multiple orders made by the user

https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list

: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
:param str [params.marginMode]: only 'isolated' is supported, for spot-margin trading
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr7   r`  r  r   rC   z9 fetchOrders() requires a symbol argument for spot marketr  r  rk  r\  z+ fetchOrders() does not support marginMode r]  
start_timeend_timerP  z. end is invalid, i.e. exceeds allowed 90 days.	page_size(contractPrivateGetOrderListHistoryOrdersr  r  )r  r  r  r  r  r'   r7   rS  r(   spotPrivateGetMarginAllOrdersr  spotPrivateGetAllOrdersr  r  r  rA  r  r  %contractPrivateGetPlanorderListOrdersrW  )r  r`  r  rk  r  r  r  r  r  r   rY  
queryInnerr!  r  r  ordersOfRegularordersOfTriggermergeds                     r	  fetch_ordersmexc.fetch_ordersD
  s      !!![[(F &tGH!!&'267+ >>}f]
~'2m(mnn%)%G%GW]%^"J ',$ %*	" #( H%+$TWW/\%\_i%i  mG  &G  H  H!%!C!CDKKPWDd!ee!%!=!=dkk'>^!__b $$XuDD (-%''
EB;*.((5,,GW:X*YGJ't||4D'EE(3c)cdd.3
+"(,EU8VY[8[(\%&+
# ',$%%dllMCmnF%%eXv>F O OCC!%!N!Nt{{[bOj!kkF #'//(F"C "&!K!KDKKX_Lg!hh6 #'//(F"C&&HF$$VVEJJG 	". f_N lL isY   KK C2K	K
(K2K3DK	K	
:KK<KKK	KKc                   #    U R                  5       I S h  vN   0 nS nUb  U R                  U5      nUS   US'   U R                  SXS5      u  pgUS:X  a  [        U R                  S-   U-   5      eSR                  U5      US'   U R                  U R                  XG5      5      I S h  vN nU R                  US5      n	U R                  X5      $  N N)7f)	Nr7   r`  fetchOrdersByIdsrC   z) fetchOrdersByIds() is not supported for ,	order_idsr  )
r  r  r  r(   r7   join!contractPrivateGetOrderBatchQueryr  	safe_listr  )
r  idsr`  r  r  r  r  r   r!  r  s
             r	  fetch_orders_by_idsmexc.fetch_orders_by_ids
  s     !!![[(F &tGH >>?QSYb
TWW'RRU__``#&88C=GK !CCDKKPWD_``HF >>(F3D$$T22_ 	" as"   CCBC'C((CCc                 >  #    U R                  5       I Sh  vN   0 nSnSnUb  U R                  U5      nU R                  SXd5      u  ptUS:X  a  Ub  US   US'   U R                  SU5      u  pSn
UbM  US:w  a  [	        U R
                  S-   U-   S-   5      eU R                  U R                  XY5      5      I Sh  vN n
O(U R                  U R                  XY5      5      I Sh  vN n
U R                  XX#5      $ U R                  S	XX45      I Sh  vN $  N N\ N5 N
7f)
a  
fetch all unfilled currently open orders

https://mexcdevelop.github.io/apidocs/spot_v3_en/#current-open-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list

: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.marginMode]: only 'isolated' is supported, for spot-margin trading
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   rC   r7   r`  r\  z/ fetchOpenOrders() does not support marginMode r]  r   )r  r  r  rS  r(   r7   spotPrivateGetMarginOpenOrdersr  spotPrivateGetOpenOrdersr  fetch_orders_by_state)r  r`  r  rk  r  r  r  r  rY  r   r!  s              r	  fetch_open_ordersmexc.fetch_open_orders+  sF     !!!
[[(F!??@QSYb
!$*4L! $ B BCTV\ ]JH%+$TWW/`%`cm%m  qK  &K  L  L!%!D!DT[[QXE`!aa!%!>!>t{{7?Z![[b $$XuDD 33AveTTTK 	" b[h UsF   DDB#D:D;(D#D$,DDDDDDc                 D   #    U R                  SXX45      I Sh  vN $  N7f)a  
fetches information on multiple closed orders made by the user

https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list

: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
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
r   Nr  r  r`  r  rk  r  s        r	  fetch_closed_ordersmexc.fetch_closed_orders  "      //6%PPPP     c                 D   #    U R                  SXX45      I Sh  vN $  N7f)a  
fetches information on multiple canceled orders made by the user

https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: timestamp in ms of the earliest order, default is None
:param int [limit]: max number of orders to return, default is None
: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>`
r  Nr  r  s        r	  fetch_canceled_ordersmexc.fetch_canceled_orders  r  r  c           	      2  #    U R                  5       I S h  vN   0 nS nUb  U R                  U5      nU R                  SXu5      nUS:X  a  [        U R                  S-   U-   5      eXS'   U R                  X#X@R                  Xe5      5      I S h  vN $  N| N7f)NfetchOrdersByStaterC   z+ fetchOrdersByState() is not supported for states)r  r  r  r-   r7   r  r  )	r  r  r`  r  rk  r  r  r  r  s	            r	  r  mexc.fetch_orders_by_state  s     !!![[(F778Lf]
tww)VVYccdd %H**6%WA]^^^ 	" _s"   BBA7BBBBc                   #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   SnU R                  SXS5      u  pcU R                  SU5      u  pxSn	US:X  a  Uc  [	        U R
                  S-   5      eSUS   0n
U R                  US5      nUb  U R                  US5      nXS'   OXS	'   UbN  US
:w  a  [        U R
                  S-   U-   S-   5      eU R                  U R                  X5      5      I Sh  vN n	GOU R                  U R                  X5      5      I Sh  vN n	OU R                  U R                  SS5      nU R                  USU5      nSnUS:X  a  U R                  U/5      I Sh  vN nO9US:X  a  U R                  U/5      I Sh  vN nO[        U R
                  S-   5      eU R!                  US5      n	U R!                  U	S5      nU R!                  USS5      nUS:w  a!  [#        U R
                  S-   U-   S-   U-   5      eU R%                  X5      $  GN GN. GN N N7f)ao  
cancels an open order

https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-order
https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-order-under-maintenance
https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-stop-limit-trigger-order-under-maintenance

: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
:param str [params.marginMode]: only 'isolated' is supported for spot-margin trading
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr7   r`  rM   rC   z) cancelOrder() requires a symbol argumentrZ  r  r  r\  z+ cancelOrder() does not support marginMode r]  contractPrivatePostOrderCancelr  "contractPrivatePostPlanorderCancelz& cancelOrder() not support self methodr  r   errorMsg r  z! cancelOrder() the order with id z cannot be cancelled: )r  r  r  rS  r'   r7   rA  r  r(   spotPrivateDeleteMarginOrderr  spotPrivateDeleteOrderr  r  r  r-   r  r,   rr  )r  r7   r`  r  r  r  r  rY  r   r  requestInnerrZ  r  r!  r   r  s                   r	  cancel_ordermexc.cancel_order  sm     !!![[(F &tGH
!??v^
 >>}fU
~'2](]^^&,"L !,,V_EM(5/:4A01*,Y'%+$TWW/\%\_i%i  mG  &G  H  H!>>t{{<?_``!88\9YZZJ %%dllMCcdF%%eXv>FH99!%!D!DbT!JJ??!%!H!H"!NN"477-U#UVV ??8V4DOOD!,Euj"=H9$"477-P#PSU#UXp#ps{#{||--w 	"2 aZR KNsZ   IH4C2I	H7
)I3H:4AIH= I'H?(BI7I:I=I?Ir  c                 L  #    U R                  5       I Sh  vN   Ub  U R                  U5      OSnU R                  SXC5      nUS:X  a  [        U R                  S-   U-   5      eU R                  U5      I Sh  vN nU R                  US5      nU R                  Xt5      $  N N)7f)aq  
cancel multiple orders

https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-order-under-maintenance

:param str[] ids: order ids
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrN   rC   z% cancelOrders() is not supported for r  )r  r  r  r(   r7   r  r  r  )r  r  r`  r  r  r  r!  r  s           r	  cancel_ordersmexc.cancel_orders  s      !!!)/);V$$77W
TWW'NNQ[[\\!@@EEH >>(F3D$$T22+ 	" Fs"   B$B A!B$8B"9(B$"B$c                   #    U R                  5       I Sh  vN   Ub  U R                  U5      OSn0 nSnU R                  SX25      u  pRU R                  SU5      u  pgUS:X  a  Uc  [	        U R
                  S-   5      eUS   US'   SnUbM  US:w  a  [        U R
                  S-   U-   S	-   5      eU R                  U R                  XG5      5      I Sh  vN nO(U R                  U R                  XG5      5      I Sh  vN nU R                  X5      $ Ub  US   US'   U R                  U R                  SS
5      n	U R                  USU	5      n	SnU	S
:X  a)  U R                  U R                  XG5      5      I Sh  vN nO.U	S:X  a(  U R                  U R                  XG5      5      I Sh  vN nU R                  US/ 5      n
U R                  X5      $  GN N N N^ N17f)a  
cancel all open orders

https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-all-open-orders-on-a-symbol
https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-all-orders-under-a-contract-under-maintenance
https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-all-trigger-orders-under-maintenance

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: only 'isolated' is supported for spot-margin trading
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NrL   rC   z5 cancelAllOrders() requires a symbol argument on spotr7   r`  r\  z/ cancelAllOrders() does not support marginMode r]  !contractPrivatePostOrderCancelAllr  %contractPrivatePostPlanorderCancelAllr  )r  r  r  rS  r'   r7   r(   !spotPrivateDeleteMarginOpenOrdersr  spotPrivateDeleteOpenOrdersr  rA  r  r  r  r  )r  r`  r  r  r  r  rY  r   r!  r  r  s              r	  cancel_all_ordersmexc.cancel_all_orders;  s     !!!)/);V$$
!??@QSYb
 >>?PRXY
~'2i(ijj &tGHH%+$TWW/`%`cm%m  qK  &K  L  L!%!G!GT[Hc!dd!%!A!A$++gB]!^^J $$X66!$*4L! %%dll4EGjkF%%eXv>FH<<!%!G!GT[Hc!ddBB!%!K!KDKKX_Lg!hh >>(FB7D$$T22S 	" e^^ ehsY   GGB;GG(G;G<A;G7G8.G&G')GGGGGr   c                    U R                  US5      nUb%  U R                  USU R                  US5      S.5      $ S n[        U[        5      (       a  UnOU R                  USS5      nU R                  U R                  US5      5      nU R                  US5      nUc  U R                  U5      nU R                  US	5      nU R                  Xr5      nU R                  U/ S
Q5      nS n	U R                  US5      n
U
bN  U R                  US5      nU R                  US5      n[        R                  " X5      nU
U R                  U5      S.n	U R                  0 SU_SU R                  US5      _SU_SU R                  U5      _SS _SU R                  US5      _SU R                  U R                  USS5      5      _S	US	   _SU R                  U5      _SU_SU R!                  U R                  US5      5      _SU R#                  US5      _SU R%                  USS5      _SU R#                  US5      _SU R%                  USS5      _S U R#                  US!5      _S"U R%                  US#S$5      _S U	S US%.EU5      $ )&Nr<  rejectedr[  )r  r  rZ  r  r7   r`  r=  r`  )r   
createTimetransactTimer  takerFeemakerFee)rJ  rw  rZ  r  r  lastTradeTimestamplastUpdateTimestamp
updateTimer  r  r  rs  rZ  rz  r8  dealAvgPricer:  origQtyr  rw  cummulativeQuoteQtyfilledexecutedQtydealVol)	remainingr7  r   r  )r  r  rA  
isinstancestrrC  parse_order_time_in_forceget_tif_from_raw_order_typer  r  r1   
string_addr  r  parse_order_statusparse_order_typer  rF  rb  )r  r   r  r<  r7   r`  typeRawr  r  r7  r  r  r  feeSums                 r	  rr  mexc.parse_order  s   V   /??$!%!1!1%9K!L$  
 eS!!B##E9d;B44T5E5Ee]5[\""5&1::7CK##E84!!(3''/UV	&&um<"''z:H''z:H'';F'))&1C   
" 
T--e_E 
  
 Y/	 

 !$ 
 "4#4#4UL#I 
 d--d.@.@RY.Z[ 
 fX& 
 D))'2 
 ; 
 D))$*:*:5&*IJ 
 T%%eW5 
 D..uk>R 
 t''~> 
 d((	5A 
  D$$U,AB! 
" d((yI# 
$ + 
, - 	r  c                 4    SSSSS.nU R                  X!U5      $ )Nr  r  )BUYSELLrd  2rA  r  r  statusess      r	  r  mexc.parse_order_sidet  s*    	
 &99r  c                 6    SSSSSS.nU R                  X!U5      $ )Nr  rk  )MARKETLIMITr^  r_  r`  r  r  s      r	  r  mexc.parse_order_type~  s-    "#*#
 &99r  r  c           	      <    SSSSSSSSS.nU R                  X!U5      $ )Nr  closedcanceled)NEWFILLEDCANCELEDPARTIALLY_FILLEDPARTIALLY_CANCELEDr  34r  r  s      r	  r  mexc.parse_order_status  s8    " &", 
 &99r  c                 2    SSSS.nU R                  X!U5      $ )NGTCrV  rU  )r  rV  rU  r  r  s      r	  r  mexc.parse_order_time_in_force  s'    

 &99r  r~  c                 6    SSSSSS.nU R                  X!U5      $ )Nr  	POST_ONLYrU  rV  )r  r^  r_  r`  r  r  )r  r~  r  s      r	  r   mexc.get_tif_from_raw_order_type  s-    &#(!
 Y??r  c                    #    US:X  a  U R                  U5      I S h  vN $ US:X  a+  U R                  U5      I S h  vN nU R                  US5      $ g  N6 N7f)NrC   rE   r  )spotPrivateGetAccountcontractPrivateGetAccountAssetsr  )r  r=  r  r!  s       r	  fetch_account_helpermexc.fetch_account_helper  s^     6>33F;;;: V^!AA&IIH& ??8V44e << Js   AAAAAAc                   #    U R                  SSU5      u  p#U R                  5       I Sh  vN   U R                  X#5      I Sh  vN nU R                  US/ 5      n/ n[	        S[        U5      5       Ha  nXW   nU R                  USS5      n	U R                  U	5      n
UR                  U R                  US5      U R                  US5      U
US	.5        Mc     U$  N N7f)
a  
fetch all the accounts associated with a profile

https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
r_   Nbalancesr   assetrJ  r7   r=  )r7   r=  r<  r  )
r  r  r  r  r@  r  rC  rB  r  rA  )r  r  r  r   r!  r  rH  rI  r   
currencyIdr<  s              r	  fetch_accountsmexc.fetch_accounts  s      !>>PTV\]
!!!22:EExR8q#d)$AgG++GWjIJ**:6DMM&&w5((&9	 	 %  	"Es"   )CCCCBCCc                 ~  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      I Sh  vN nU R                  US0 5      nUUU R                  US5      U R                  US5      SSS	.$  N NB7f)
a3  
fetch the trading fees for a market

https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-mx-deduct-status

: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>`
NrC   z- fetchTradingFee() supports spot markets onlyr`  r7   r  rf  rg  )r  r`  r   r  r   r   )r  r  r(   r7   spotPrivateGetTradeFeer  	safe_dictrF  r  r`  r  r  r  r!  r  s          r	  fetch_trading_feemexc.fetch_trading_fee  s      !!!V$f~TWW'VVWWfTl
 44T[[5QRR ~~h3%%d,=>%%d,=>
 	
) 	" Ss#   B=B9A!B=8B;9AB=;B=c                    S nUS:X  a  U R                  US/ 5      nO-US:X  a  U R                  US/ 5      nOU R                  US/ 5      nSU0nUS:X  a  [        S[        U5      5       H  nX5   nU R                  US5      nU R	                  US 5      nU R                  US	0 5      n	U R                  US
0 5      n
U R                  U R                  U	S5      5      nU R                  U R                  U
S5      5      n0 nU R                  U	5      X'   U R                  U
5      X'   U R                  U5      XH'   M     U$ US:X  a  [        S[        U5      5       Hh  nX5   nU R                  US5      nU R                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   UXO'   Mj     U R                  U5      $ [        S[        U5      5       Hh  nX5   nU R                  US5      nU R                  U5      nU R                  5       nU R                  US5      US'   U R                  US5      US'   UXO'   Mj     U R                  U5      $ )NrD   assetsrE   r  r  r  r   r`  ra  rb  r  rJ  availableBalancefreefrozenBalanceusedlocked)	r  r@  r  rA  safe_symbolrB  parse_balance_helpersafe_balancer   )r  r!  r  walletrH  rI  entryr  r`  rj  rk  baseCode	quoteCode	subResultr  r<  r   s                    r	  custom_parse_balancemexc.custom_parse_balance$  sk   z !__Xx<F6!__Xvr:F__Xz2>F(#!1c&k*	++E8<))(D9uk2>|R@2243C3CD'3RS 33D4D4DUG4TU	"$	&*&?&?&E	#'+'@'@'G	$!%!2!29!= + M6!1c&k*	!--eZ@
..z:,,."&"2"25:L"M"&"2"25/"J& + $$V,,1c&k*	!--eW=
..z:,,."&"2"25&"A"&"2"25("C& + $$V,,r  c                    U R                  5       nU R                  US5      US'   U R                  US5      US'   U R                  US5      US'   U R                  US5      nU R                  US5      n[        R                  " X45      US'   U$ )	Nr'  r&  r$  
totalAssettotalborrowedinterestdebt)r   rA  r1   r  )r  r,  r   r7  r6  s        r	  r)  mexc.parse_balance_helper  s    ,,.**5(;**5&9++E<@z2##E:6!,,T<r  c                   #    U R                  5       I Sh  vN   Sn0 nU R                  SSU5      u  p!U R                  US5      nU R                  USS5      nU R	                  USS/5      nSnUc  U(       d  US:X  a  SnU R                  US5      nUc6  U R                  US5      n	U	b   SR                  U R                  U	5      5      nOU R                  U5      n
U
S	   nU R                  SUS
5        SnXsS'   U R	                  USS/5      nU R                  U R                  X15      5      I Sh  vN nOvUS:X  a)  U R                  U R                  X15      5      I Sh  vN nOGUS:X  a)  U R                  U R                  X15      5      I Sh  vN nO[        U R                  S-   5      eU R!                  Xb5      $  GN N Nb N57f)a?  
query for balance and get the amount of funds available for trading or funds locked in orders

https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
https://mexcdevelop.github.io/apidocs/spot_v3_en/#isolated-account

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.symbols]:  # required for margin, market id's separated by commas
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr`   rY  rD   Fr`  r_  r  r7   zsymbol or symbolsrC   rE   z' fetchBalance() not support self method)r  r  rA  rE  r  r  r  
market_idsr  check_required_argument#spotPrivateGetMarginIsolatedAccountr  r  r  r-   r7   r0  )r  r  r  r  rY  isMarginr!  parsedSymbolsr`  r_  r  s              r	  fetch_balancemexc.fetch_balance  s     !!!
!??PTV\]
%%fl;
>>&(E:6Hl#;<"jH6L M%%fh7F~//&)<&$'HHT__W-E$FMV, &t((H[\!J!.IYYv)'<=F!EEdkkRYFbccH6!!77G8TUUH6!!AA$++gB^__Htww)RRSSj ((>>c 	", dU_sF   GF?DG2G3.G!G".GG/GGGGc                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSnU R	                  SXT5      u  pdSUS   0nSnUS:X  ab  Ub  X'S'   Ub  X7S'   U R                  US	5      n	U	b  U R                  US	5      nXS
'   U R                  U R                  Xt5      5      I Sh  vN nO~Ub:  X'S'   U R                  US5      n
U
c!  U R                  X R                  S   5      US'   Ub  X7S'   U R                  U R                  Xt5      5      I Sh  vN nU R                  US5      nU R                  XX#5      $  GN- N N-7f)ap  
fetch all trades made by the user

https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-trade-list
https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-transaction-details-of-the-user-s-order

: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]: the latest time in ms to fetch trades for
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nz+ fetchMyTrades() requires a symbol argumentr   r`  r7   rC   r  rk  r  r  r  r  rP  r  r  )r'   r7   r  r  r  r  r  spotPrivateGetMyTradesr  r  r  %contractPrivateGetOrderListOrderDealsr  r  )r  r`  r  rk  r  r  r  r  r   r  r  r!  s               r	  fetch_my_tradesmexc.fetch_my_trades  s     >#DGG.[$[\\!!!V$
!??QW`
fTl
  ',$ #( %%fg6E 673%*	"66t{{77STTF.  (-%''
;;*.((5,,GW:X*YGJ' ',$!GGT[HdeeH0 __Xv6F  >>Q 	"" U< fs5   /E%EBE%E!	A,E%5E#6)E%!E%#E%c                   #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nU R                  SXu5      u  pSn
US:X  aP  Uc  [        U R                  S-   5      eUS   US'   XS'   U R                  U R                  Xi5      5      I Sh  vN n
O>XS'   U R                  U R                  Xi5      5      I Sh  vN nU R                  US	5      n
U R                  XX4U	5      $  N NX N-7f)
a=  
fetch all the trades made from a single order

https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-trade-list
https://mexcdevelop.github.io/apidocs/contract_v1_en/#query-the-order-based-on-the-order-number

:param str id: order id
: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 to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr   rC   z. fetchOrderTrades() requires a symbol argumentr7   r`  r  r  r  )
r  r  r  r'   r7   rB  r  )contractPrivateGetOrderDealDetailsOrderIdr  r  )r  r7   r`  r  rk  r  r  r  r  r   r   r!  s               r	  fetch_order_tradesmexc.fetch_order_tradeso  s     !!![[(F >>?QSYb
~'2b(bcc &tGH!#I66t{{77RSSF. #%J!KKDKKX_LghhH0 __Xv6F  uEE{ 	" T0 is4   C6C0BC6C2,C6C4*C62C64C6c                    #    U R                  US5      nUc  [        U R                  S-   5      eU R                  5       I S h  vN   UUUS.nU R	                  U R                  Xd5      5      I S h  vN nU$  N4 N7f)N
positionIdz5 modifyMarginHelper() requires a positionId parameter)rK  r:  r=  )r  r'   r7   r  'contractPrivatePostPositionChangeMarginr  )r  r`  r:  addOrReducer  rK  r  r!  s           r	  modify_margin_helpermexc.modify_margin_helper  s     &&v|<
#DGG.e$eff!!!$

 EEdkkRYFbcc  	" ds$   AA<A8-A<1A:2A<:A<c                 D   #    U R                  XSU5      I Sh  vN $  N7f)aw  
remove margin from a position

https://mexcdevelop.github.io/apidocs/contract_v1_en/#increase-or-decrease-margin

: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>`
SUBNrN  r  r`  r:  r  s       r	  reduce_marginmexc.reduce_margin  "      ..vufMMMMr  c                 D   #    U R                  XSU5      I Sh  vN $  N7f)aZ  
add margin

https://mexcdevelop.github.io/apidocs/contract_v1_en/#increase-or-decrease-margin

:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
ADDNrR  rS  s       r	  
add_marginmexc.add_margin  rV  r  rc  c                   #    U R                  5       I Sh  vN   SU0nU R                  US5      nUcl  U R                  US5      nU R                  US5      nUb  U R                  U5      OSnUb  Ub  Uc  [	        U R
                  S-   5      eXdS'   US   US'   XtS'   OXTS'   U R                  U R                  XC5      5      I Sh  vN $  N N7f)	a<  
set the level of leverage for a market

https://mexcdevelop.github.io/apidocs/contract_v1_en/#switch-leverage

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nrc  rK  rv  positionTypez setLeverage() requires a positionId parameter or a symbol argument with openType and positionType parameters, use openType 1 or 2 for isolated or cross margin respectively, use positionType 1 or 2 for long or short positionsr7   r`  )r  r  rF  r  r'   r7   )contractPrivatePostPositionChangeLeverager  )	r  rc  r`  r  r  rK  rv  r\  r  s	            r	  set_leveragemexc.set_leverage  s      !!!
 &&v|<
''
;H++FNCL-3-?T[[(dF l&:'  3V  )V  W  W&.
#$*4L!*6'$.L!CCDKKPWD`aaa# 	"" bs"   CCB0CCCCc                 (  #    U R                  5       I Sh  vN   Sn0 nUb  U R                  U5      nUS   US'   Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R	                  US0 5      nU R	                  US/ 5      n	/ n
[        S[        U	5      5       Ha  nX   nU R                  US5      nU
R                  UUSUU R                  U5      U R                  US5      U R                  US	5      S
.5        Mc     U
$  N N7f)a  
fetch the history of funding payments paid and received on self account

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-details-of-user-s-funding-rate

: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
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
Nr7   r`  r  r  
resultListr   
settleTimefunding)r  r`  r<  r  r  r7   r:  )r  r  (contractPrivateGetPositionFundingRecordsr  r  r@  r  r  r  r  rF  )r  r`  r  rk  r  r  r  r!  r  ra  rH  rI  r,  r  s                 r	  fetch_funding_historymexc.fetch_funding_history  s*     !!!
 [[(F &tGH#(K FFt{{SZGcddB x4__T<<
q#j/*AME))%>IMM & LL3&&ud3**5)<  + { 	" es#   DDAD%D&B)DDc                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  XRS S5      nU R                  US5      nU R                  US5      nS n	Ub  US-   n	0 SU_SU_S	S _S
S _SS _SS _SU_SU R	                  U5      _SU_SU_SU R	                  U5      _SS _SS _SS _SS _SS _SS _SU	0E$ )NfundingRatenextSettleTimer`  r   r  collectCyclehr  	markPrice
indexPriceinterestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )rF  r  rA  r(  r  )
r  r   r  rr  rs  r  r`  r  r  intervalStrings
             r	  parse_funding_ratemexc.parse_funding_rateQ  sz    **8]C#00;KL##Hh7!!(D*E%%h<	##Hn=%^N
H
f
 
 $	

 D
 #D
 
 Y/
 ?
  4
 t||,@A
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 @   #    U R                  X5      I Sh  vN $  N7f)aP  
fetch the current funding rate interval

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-funding-rate

: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>`
N)fetch_funding_rate)r  r`  r  s      r	  fetch_funding_intervalmexc.fetch_funding_interval{  s      ,,V<<<<s   c                 
  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US0 5      nU R                  Xc5      $  Nh N*7f)aG  
fetch the current funding rate

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-funding-rate

: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>`
Nr`  r7   r  )r  r  "contractPublicGetFundingRateSymbolr  r  ry  )r  r`  r  r  r  r!  rH  s          r	  r|  mexc.fetch_funding_rate  s      !!!V$fTl
 @@WA]^^  626&&v66- 	"
 _!   BA??BB)BBc           
        #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      I Sh  vN nU R                  US5      nU R                  US/ 5      n	/ n
[        S[        U	5      5       Hr  nX   nU R                  US5      nU R                  U5      nU R                  US	5      nU
R                  UUU R                  US
5      UU R                  U5      S.5        Mt     U R                  U
S5      nU R!                  UUS   X#5      $  GN& N7f)a$  
fetches historical funding rate prices

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-funding-rate-history

:param str symbol: unified symbol of the market to fetch the funding rate history for
:param int [since]: not used by mexc, but filtered internally by ccxt
:param int [limit]: mexc limit is page_size default 20, maximum is 100
: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-history-structure>`
Nz5 fetchFundingRateHistory() requires a symbol argumentr`  r7   r  r  ra  r   rb  rh  )r  r`  rh  r  r  r  )r'   r7   r  r  #contractPublicGetFundingRateHistoryr  r  r@  r  rA  r(  r  r  rF  r  sort_byfilter_by_symbol_since_limit)r  r`  r  rk  r  r  r  r!  r  rH  ratesrI  r,  r  symbolInnerr  sorteds                    r	  fetch_funding_rate_historymexc.fetch_funding_rate_history  sd     >#DGG.e$eff!!!V$fTl

 #(K AA$++gB^__2 x0|R8q#f+&AIE''x8H**84K))%>ILL%#//}E& LL3  ' e[1009I5XXe 	" `s#   /EEAE8E9CEEc                    #    U R                  5       I Sh  vN   U R                  USSS5      nU R                  U5      I Sh  vN nU R                  US5      nU R	                  XAS5      $  NU N*7f)a0  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes, if a market has a leverage tier of 0, then the leverage tiers cannot be obtained for self market

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-information

:param str[] [symbols]: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
NrE   Tr  r`  )r  market_symbolsr  r  parse_leverage_tiersr  r_  r  r!  r  s        r	  fetch_leverage_tiersmexc.fetch_leverage_tiers  sq      !!!%%gvtTB55f==\ ~~h/((AAc 	"=s!   A0A,,A0A.)A0.A0c                 
   U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      n	Sn
/ nU R                  US	5      nUS:X  a<  S
U R                  X2S S5      U R                  U5      S S S U R                  US5      US./$ [        R
                  " X5      (       Ga  [        R                  " X5      nUR                  U R                  [        R                  " X5      5      U R                  X2S S5      U R                  U5      U R                  U
5      U R                  U5      U R                  U5      U R                  [        R                  " SU5      5      US.5        [        R                  " XY5      n[        R                  " XH5      nUn
[        R
                  " X5      (       a  GM  U$ )Nr`  maintenanceMarginRateinitialMarginRater  riskIncrVolriskIncrMmrriskIncrImrr  r  r   r   r  )tierr`  rJ  minNotionalmaxNotionalr  r  r  rd  )
rA  r(  rB  rF  r1   	string_ltr  r  r  
string_div)r  r  r  r  r  r  r  r  r  r  floortiersrn  caps                 r	  parse_market_leverage_tiers mexc.parse_market_leverage_tiers(  s   N ##D(3 $ 0 07N O ,,T3FG!!$1&&t];&&t];&&t];""45# "..xzR $ 7 7 @#'#'-1#'#3#3D-#H 	  ..$$U8CLL))'*<*<S*NO**8T:N 33G<#007#005)-):):;P)Q#001C1CCIZ1[\	 	 !( 2 23D R$+$6$67L$Z!E .. r  rJ  c                     U R                  US5      nU R                  US5      nU R                  US5      nU R                  U5        UU R                  XB5      U R                  XT5      UU R                  US5      S.$ )Naddressr+  r-  memo)r  rJ  r.  r  tag)rA  check_addressrB  rD  )r  depositAddressrJ  r  r  rN  s         r	  parse_deposit_addressmexc.parse_deposit_addressw  s     "">9=%%nf=
$$^Y?	7#"//
E..yE##NF;
 	
r  r<  c                 R  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  US5      nSnUbr  U R                  XQ5      nU R	                  US0 5      nXx;   a8  U R	                  X0 5      n	U R                  U	S0 5      n
U R                  U
S5      nOU R                  XQ5      nUb  XdS'   U R                  US5      nU R                  U R                  XB5      5      I Sh  vN nU R                  USS5      nU R                  US5      $  GN N,7f)a  
fetch a dictionary of addresses for a currency, indexed by network

https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network

:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `address structures <https://docs.ccxt.com/#/?id=address-structure>` indexed by the network
Nr+  r7   r.  rM  r  F)r  rJ  rA  rD  r  r  network_code_to_idr  #spotPrivateGetCapitalDepositAddressr  parse_deposit_addressesindex_by)r  r<  r  rJ  r  networkCoderN  networkUnifiedrM  r.  networkInfor!  addressStructuress                r	  "fetch_deposit_addresses_by_network'mexc.fetch_deposit_addresses_by_network  s1     !!!==&HTN
 &&vy9	"!44[GN~~h
B?H)..2F"oogvrB ,,[)D	 33KF	 !*I69-AA$++gB^__ !884O}}.	::C 	"( `s"   D'D"C!D'8D%9*D'%D'c                 Z  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  US5      nUc  [        U R                  S-   5      eSnU R                  XQ5      nU R                  US0 5      nXx;   a8  U R                  X0 5      n	U R                  U	S0 5      n
U R                  U
S5      nOU R                  XQ5      nUb  XdS'   U R                  US5      nU R                  U R                  XB5      5      I Sh  vN nU R                  X5      $  GN N7f)a  
create a currency deposit address

https://mexcdevelop.github.io/apidocs/spot_v3_en/#generate-deposit-address-supporting-network

:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the blockchain network name
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
Nr+  r7   r.  z4 createDepositAddress requires a `network` parameterrM  r  )r  rJ  rA  r'   r7   rD  r  r  r  r  $spotPrivatePostCapitalDepositAddressr  r  )r  r<  r  rJ  r  r  rN  r  rM  r.  r  r!  s               r	  create_deposit_addressmexc.create_deposit_address  s/     !!!==&HTN
 &&vy9#DGG.d$dee	00C>>(J;%nnXrBG//'62>K((i@I//BI !*I69-BB4;;wC_`` ))(==9 	"* as"   D+D&C9D+D)D+)D+c                   #    U R                  US5      nU R                  X5      I Sh  vN nSnUb!  U R                  X@R                  X15      5      nO~U R                  U R                  S5      nU R                  Xa5      nUb  U R                  XG5      nO<[        UR                  5       5      nU R                  US5      n	U R                  XI5      nUc$  [        U R                  S-   U-   S-   U-   S-   5      eU$  N7f)a  
fetch the deposit address for a currency associated with self account

https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-address-supporting-network

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the chain of currency, self only apply for multi-chain currency, and there is no need for single chain currency
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r.  NrL  r   z9 fetchDepositAddress() cannot find a deposit address for z, and networkzMconsider creating one using .createDepositAddress() method or in MEXC website)	rA  r  r  rD  r  r  r  r+   r7   )
r  r<  r  r.  r  rH  r  defaultNetworkForCurrencyr  keys
             r	  fetch_deposit_addressmexc.fetch_deposit_address  s     ""695"&"I"I$"WW^^$57N7Nw7]^FnnT\\3DEG(,(8(8(G%(4(9U-2245&&tQ/(9?> +f!fim!mp!  CJ  "J  M\  "\  ]  ] Xs   'C=C;CC=c                   #    U R                  5       I Sh  vN   0 nSnUbN  U R                  U5      nUS   US'   U R                  US5      nUb   U R                  US5      nUS   S-   U-   US'   Ub  X%S'   Ub  US:  a  [	        S5      eX5S	'   U R                  U R                  XT5      5      I Sh  vN nU R                  XX#5      $  N N7f)
a  
fetch all deposits made to an account

https://mexcdevelop.github.io/apidocs/spot_v3_en/#deposit-history-supporting-network

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr7   r+  r.  -r  rp  .This exchange supports a maximum limit of 1000rk  )r  rJ  rA  r  r#   "spotPrivateGetCapitalDepositHisrecr  parse_transactions)	r  r<  r  rk  r  r  rJ  
rawNetworkr!  s	            r	  fetch_depositsmexc.fetch_deposits  s      !!!
 }}T*H&tnGFO ))&)<J%695")&/C"7*"D#(K t|#$TUU$G@@WA]^^( &&x5HHY 	"0 _s"   CC	BC2C3CCc                 4  #    U R                  5       I Sh  vN   0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  US:  a  [        S5      eX5S'   U R                  U R	                  XT5      5      I Sh  vN nU R                  XvX#5      $  N} N7f)a  
fetch all withdrawals made from an account

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-history-supporting-network

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr7   r+  r  rp  r  rk  )r  rJ  r#   $spotPrivateGetCapitalWithdrawHistoryr  r  )r  r<  r  rk  r  r  rJ  r!  s           r	  fetch_withdrawalsmexc.fetch_withdrawals9  s      !!!
 }}T*H&tnGFO#(K t|#$TUU$GBB4;;wC_``0 &&x5HHU 	"$ as"   BBA&B=B>BBtransactionc                 |   U R                  USS5      nUc  SOSnU R                  USS5      nU R                  US5      nS nU R                  US5      nUb  UR	                  S	5      S
   nS n	U R                  US5      n
U
b  U R                  U
5      n	U R                  Xr5      nU R                  U R                  US5      U5      nU R                  US5      nU R                  US5      nU R                  USS5      nS nU R                  US5      nUb  U R                  U5      US.nUS:X  a  [        R                  " UU5      n0 SU_SU_SU_SU_SU R                  U5      _SU	_SU_SU_SS _SU R                  US5      _SS _SS _SU_SU R                  U5      _SU_SU_SU_U R                  US 5      S US!.E$ )"Nr7   tranIdr]   
withdrawal
insertTime	applyTimer  r+  r  r   r.  r  r:  r  	transHashtxIdtransactionFeer  r  txidr  r  	addressToaddressFromr  r  tagTotagFromr=  rJ  r  remark)commentinternalr7  )rC  r  r  rA  splitrD  rB   parse_transaction_status_by_typer  r1   
string_subr  )r  r  rJ  r7   r=  r  r  r  currencyWithNetworkr.  r  r<  r  r  r  r  r7  feeCostStrings                     r	  parse_transactionmexc.parse_transactionq  su   l T8<Zyl''\;O	##K>
"..{FC*,2237:J%%k9=
!--j9G&&z<66t7G7GU]7^`de''X>"";	:!!+{FC((6FG$))-8 C <"--lMJL
K
"
 D
 	

 Y/
 w
 w
 
 4
 4##K8
 T
 t
 D
 d''5
 
  f!
" w#
$ ''X>)
 	
r  c                 z    SSSSSSSS.SSSSSSSSSSS.
S.nU R                  X20 5      nU R                  XAU5      $ )Nfailedpendingr  )rd  r  r  r  567r  )
rd  r  r  r  r  r  r  8910)r]   r  )r  rA  )r  r  r=  statusesByTyper  s        r	  r  %mexc.parse_transaction_status_by_type  so       
. ??><&99r  c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  SU R                  XB5      5      I Sh  vN nU R	                  US5      $  NW N7f)a  
fetch data on a single open contract trade position

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information

:param str symbol: unified market symbol of the market the position is held in, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr`  r7   r   )r  r  fetch_positionsr  r  )r  r`  r  r  r  r!  s         r	  fetch_positionmexc.fetch_position  ss      !!!V$fTl
 --dDKK4PQQx++ 	"
 Rs"   A2A.A A2A0A20A2c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  US/ 5      nU R                  XA5      $  NA N*7f)af  
fetch all open positions

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
Nr  )r  'contractPrivateGetPositionOpenPositionsr  parse_positionsr  s        r	  r  mexc.fetch_positions  sZ      !!!EEfMM> ~~h3##D22C 	"Ms   AAAA)AApositionc                    U R                  U R                  US5      US S5      nUS   nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUS:X  a  SOS	nU R                  US
5      n	U	S:X  a  SOSn
U R                  US5      nU R                  US5      nU R                  US5      nU R	                  0 SU_SS _SU_SU R                  U5      _SS _SU_SS _SU_SS _SU R                  U5      _SS _SU
_SS _SS _SS _SU_SU R                  U5      _S S S S UU R                  U5      S S S S S.
E5      $ ) Nr`  rE   holdVolopenAvgPriceimr\  rd  longshortmargin_moder\  ru  rc  liquidatePricer  r  r7   	contractsry  
entryPrice
collateralr  unrealizedPnlr   rY  notionalrl  r0  liquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  r  ra  r]  r^  r  )r  rA  rF  r  safe_positionr  r  )r  r  r  r`  r  r  r  rawSider  rv  
marginTyperc  r  r  s                 r	  parse_positionmexc.parse_position3  s   z !!$"2"28X"FPTV\]!$$Xy9	%%h?
((48""8^<!S.vw##Hm<$,OZ'
##Hj9++H6FG%%h=	!! #
H#
$#
 f#
 **95	#

 D#
 *#
 $#
 D#
 T#
 ))(3#
 $#
 *#
 #
 #
 #
   0!#
" T..}=##
$ (,!%+/"Y/!##'7#
  	r  c                 \  #    U R                  SSU5      u  pEU R                  5       I Sh  vN   US:X  aP  SU0nU R                  U R                  Xe5      5      I Sh  vN nU R	                  US0 5      nU R                  U5      $ US:X  a  [        U R                  S-   U-   5      eg N| NL7f)a^  
fetches a transfer

https://mexcdevelop.github.io/apidocs/spot_v2_en/#internal-assets-transfer-order-inquiry

:param str id: transfer id
:param str [code]: not used by mexc fetchTransfer
:param dict params: extra parameters specific to the exchange api endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r   NrC   transact_idr  rE   z& fetchTransfer() is not supported for )r  r  )spotPrivateGetAssetInternalTransferRecordr  r  parse_transferr(   r7   )	r  r7   r<  r  r  r   r  r!  r  s	            r	  fetch_transfermexc.fetch_transfer  s      !>>PTV\]
!!!rG "KKDKKX_LghhH >>(FB7D&&t,,6!TWW'OOR\\]]/ 	"
 is"   )B,B(1B,B*AB,*B,c                 r  #    SnU R                  SSU5      u  pTU R                  5       I Sh  vN   0 nSnUb  U R                  U5      nSnU R                  USS5      u  pSSSSSS.n	Ub  U R	                  XU5      US'   O[        U R                  S-   5      eSn
U R                  USS5      u  pU
b  U R	                  XU
5      US'   O[        U R                  S	-   5      e/ nUS
:X  a[  Ub  X&S'   Ub  US:  a  [        S5      eX6S'   U R                  U R                  Xd5      5      I Sh  vN nU R                  US/ 5      nOYUS:X  aS  Ub  X6S'   U R                  U R                  Xd5      5      I Sh  vN nU R                  US5      nU R                  US5      nU R                  XX#5      $  GN N N?7f)a  
       fetch a history of internal transfers made on an account

       https://mexcdevelop.github.io/apidocs/spot_v2_en/#get-internal-assets-transfer-records
       https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-39-s-asset-transfer-records
       https://www.mexc.com/api-docs/spot-v3/wallet-endpoints#query-user-universal-transfer-history    :param str code: unified currency code of the currency transferred

@param code
       :param int [since]: the earliest time in ms to fetch transfers for
       :param int [limit]: the maximum number of  transfers structures to retrieve
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param str [params.fromAccountType]: 'SPOT' for spot wallet, 'FUTURES' for contract wallet
       :param str [params.toAccountType]: 'SPOT' for spot wallet, 'FUTURES' for contract wallet
       :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
       Nr   fromAccountTypeSPOTFUTURES)rC   rE   futuresrF   rD   zP fetchTransfers() requires a fromAccountType parameter, one of "SPOT", "FUTURES"toAccountTypezN fetchTransfers() requires a toAccountType parameter, one of "SPOT", "FUTURES"rC   r  r   z,This exchange supports a maximum limit of 50sizerowsrE   r  r  ra  )r  r  rJ  r  rA  r'   r7   r#   spotPrivateGetCapitalTransferr  r  'contractPrivateGetAccountTransferRecordr  parse_transfers)r  r<  r  rk  r  r  r  rJ  r  accountTypesr  ra  r!  r  s                 r	  fetch_transfersmexc.fetch_transfers  s      
!??@PRVX^_
!!!}}T*H"&"?"?HXZk"l 
 &)-)9)9,Yh)iG%&#DGG  /A  %A  B  B $ = =fFVXg h$'+'7'7Ub'cGO$#DGG.~$~
 ',$ 3;'(VWW"'!??G@\]]H& &"=J6! ',$!II$++V]JfggH??8V4D|<J2 ##J%GGe 	"@ ^. hs5   +F7F0C>F7,F3-AF75F56;F73F75F7fromAccount	toAccountc                 L  #    U R                  5       I Sh  vN   U R                  U5      nSSSS.nU R                  XsU5      nU R                  XtU5      n	UcC  [        UR	                  5       5      n
[        U R                  S-   SR                  U
5      -   5      eU	cC  [        UR	                  5       5      n
[        U R                  S-   SR                  U
5      -   5      eUS   UUU	S	.nUS
:X  d  U	S
:X  aX  U R                  US5      nU R                  US5      nUc  [        U R                  S-   5      eU R                  U5      nUS   US'   U R                  U R                  X5      5      I Sh  vN nU R                  X5      nU R                  UUUUS.5      $  GN N.7f)a:  
transfer currency internally between wallets on the same account

https://mexcdevelop.github.io/apidocs/spot_v3_en/#user-universal-transfer

: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
:param str [params.symbol]: market symbol required for margin account transfers eg:BTCUSDT
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
Nr  r  )rC   rE   rF   z fromAccount must be one of z, z toAccount must be one of r7   )r  r:  r  r  ISOLATED_MARGINr`  z: transfer() requires a symbol argument for isolated margin)r:  r"  r#  )r  rJ  rA  r  r  r#   r7   r  r  r'   r  spotPrivatePostCapitalTransferr  r  )r  r<  r:  r"  r#  r  rJ  accountsfromIdtoIdr  r  r`  r  r!  r  s                   r	  r   mexc.transfer%  s     !!!==&

 !!(EY?>(D*H H499UY? Z[[<(D*F FSW XYYd^%!	
 ''T5F-F%%fh7FYYvx0F~'2n(noo[[(F &tGH<<T[[=YZZ ))(={{;&")
  	G 	"8 [s"   F$FEF$3F"4,F$"F$r   c                 x   U R                  USS5      nU R                  U/ SQ5      nU R                  USS5      nUb  U R                  U5      OS nU R	                  US5      nS nS n	U R	                  US5      n
U R	                  US5      nU
b  Ub  U
nUn	O<Ub  US	:X  a  S
OSnUS	:X  a  SOS
n	O$U R	                  US5      nU R	                  US5      n	UUUUU R                  X25      U R                  US5      U R                  U5      U R                  U	5      U R                  U R                  U/ SQ5      5      S.	$ )NrJ  r  )r  r  r  r  r  r=  r  r  INMAINCONTRACTfromtor:  )transact_stater  r  )	r  r7   r  r  rJ  r:  r"  r#  r  )	rC  safe_string_nr  r  rA  rB  rF  parse_account_idparse_transfer_status)r  r   rJ  r  r7   r  r  	directionaccountFrom	accountTor  r  s               r	  r  mexc.parse_transfer\  s]   V ''*gF
*KL'',L	/8/D4<<	*4$$Xv6		**85FG((?C'm.G)K%I"%.$%6&ZK'0D'8
vI**8V<K((48I" //
E&&x:00=..y9001C1CHNs1tu

 
	
r  c                 4    SSSSS.nU R                  X!U5      $ )NrC   rE   )r  r  r-  r.  r  r  s      r	  r3  mexc.parse_account_id  s*    	
 &99r  c                 2    SSSS.nU R                  X!U5      $ )Nr  r  r  )SUCCESSFAILEDWAITr  r  s      r	  r4  mexc.parse_transfer_status  s'    

 &99r  r  r  c                 \  #    U R                  5       I Sh  vN   U R                  U5      nU R                  XE5      u  pEU R                  USS5      nU(       a  U R	                  US5      nUS   UUS.nU R                  US5      n	U	c  [        U R                  S-   5      eU R                  U R                  X5      5      I Sh  vN n
U R                  X5      $ U R                  U R                  S0 5      nU R                  US	S
5      nU R                  XU5      nU R                  XS   5      nU R                  U5        US   UUS.nUb  XMS'   Ub  XS
'   U R	                  US	S
/5      nU R!                  U R                  X5      5      I Sh  vN nU R                  X5      $  GN N N7f)a  
make a withdrawal

https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-new
https://www.mexc.com/api-docs/spot-v3/wallet-endpoints#internal-transfer

: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
:param dict [params.internal]: False by default, set to True for an "internal transfer"
:param dict [params.toAccountType]: skipped by default, set to 'EMAIL|UID|MOBILE' when making an "internal transfer"
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr  Fr7   )r  r:  r#  r  zc withdraw() requires a toAccountType parameter for internal transfer to be of: EMAIL | UID | MOBILErM  r.  r-  r<  )r+  r  r:  r  )r  rJ  handle_withdraw_tag_and_paramsrE  r  rA  r'   r7   &spotPrivatePostCapitalTransferInternalr  r  r  r  rC  r  r  spotPrivatePostCapitalWithdraw)r  r<  r:  r  r  r  rJ  r  requestForInternalr  responseForInternalrM  r.  r  r!  s                  r	  r   mexc.withdraw  s      !!!==&99#F>>&*e<YYvz2F!$ $"
 !,,V_EM$'  3X  )X  Y  Y(,(S(STXT_T_`rT{(|"| ))*=HH>>$,,
B?$$VY	B""8g>))'F3CD7#TN

 ?!FO!(IYYv	9'=>F<<T[[=YZZ %%h99U 	" #}, [s5   F,F%B-F,F(C
F,F*F,(F,*F,ra  c                 |   #    SU(       a  SOS0nU R                  U R                  XC5      5      I Sh  vN nU$  N7f)a\  
set hedged to True or False for a market

https://mexcdevelop.github.io/apidocs/contract_v1_en/#change-position-mode

:param bool hedged: set to True to use dualSidePosition
:param str symbol: not used by mexc setPositionMode()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
r  r   r   N)-contractPrivatePostPositionChangePositionModer  )r  ra  r`  r  r  r!  s         r	  set_position_modemexc.set_position_mode  sC      AQ
 KKDKKX_Lhii  js   1<:<c                 t   #    U R                  U5      I Sh  vN nU R                  US5      nUUS:H  S.$  N7f)a  
fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-position-mode

:param str symbol: not used by mexc fetchPositionMode
: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
Nr  r   )r  ra  )&contractPrivateGetPositionPositionModer  )r  r`  r  r!  r  s        r	  fetch_position_modemexc.fetch_position_mode	  sI      DDVLL ((6:#q(
 	
 Ms   868codesc                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  X15      $  N. N7f)\  
fetch deposit and withdrawal fees

https://mexcdevelop.github.io/apidocs/spot_v3_en/#query-the-currency-information

:param str[]|None codes: returns fees for all currencies if None
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
N)r  r?  parse_transaction_feesr  rO  r  r!  s       r	  fetch_transaction_feesmexc.fetch_transaction_fees!  sG      !!!??GG< **8;;? 	"Gs   A	AA	AA	A	c                    0 n[        S[        U5      5       Hj  nX   nU R                  US5      nU R                  U5      nU R                  US5      nUb  U R	                  X5      (       d  MW  U R                  XW5      X8'   Ml     U0 US.$ )Nr   r+  r<  )r   r]   r  )r@  r  rA  safe_currencyin_arrayparse_transaction_fee)	r  r!  rO  withdrawFeesrI  r,  r  rJ  r<  s	            r	  rR  mexc.parse_transaction_feesL  s    q#h-(AKE))%8J))*5H##Hf5D4==#=#=%)%?%?%P" ) %
 	
r  c                     U R                  US/ 5      n0 n[        S[        U5      5       HN  nX5   nU R                  US5      nU R                  U R                  S   Xw5      nU R                  US5      n	XU'   MP     U$ )Nr,  r   r.  rM  r1  )r  r@  r  rA  r  rF  )
r  r  rJ  r,  rH  rL  networkEntryrN  r  r7  s
             r	  rY  mexc.parse_transaction_fee[  s    6 ook="Eq#k*+A&>L((yAI**4<<
+CYZK""<?C"%; , r  c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  X1S5      $  N/ N7f)rQ  Nr+  )r  r?  parse_deposit_withdraw_feesrS  s       r	  fetch_deposit_withdraw_fees mexc.fetch_deposit_withdraw_fees  sI      !!!??GG< //HH? 	"Gs   A
AA
AA
A
c                 T   U R                  US/ 5      nU R                  U5      n[        S[        U5      5       H[  nX5   nU R	                  US5      nU R                  XpR	                  US5      5      nU R                  US5      S S.S S S.S.US   U'   M]     U R                  U5      $ )	Nr,  r   r.  r<  r1  )r7  r   )r   r]   rM  )r  deposit_withdraw_feer@  r  rA  rD  rF  $assign_default_deposit_withdraw_fees)	r  r7  rJ  r,  rH  rL  r]  rN  r  s	            r	  parse_deposit_withdraw_feemexc.parse_deposit_withdraw_fee  s    6 ooc="=**3/q#k*+A&>L((yAI11)=M=MhX^=_`K  ++L-H"&
  "&	/F:{+	 , 88@@r  c                 
  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US/ 5      nU R                  Xc5      $  Nh N*7f)a7  
fetch the set leverage for a market

https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-leverage

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
Nr`  r7   r  )r  r  "contractPrivateGetPositionLeverager  r  parse_leverager  s          r	  fetch_leveragemexc.fetch_leverage  s      !!!V$fTl
 @@WA]^^> ~~h3""400K 	"
 _r  c                 "   S nS nS n[        S[        U5      5       Hf  nX   nU R                  US5      nU R                  US5      n	U	S:X  a  U R                  US5      nOU	S:X  a  U R                  US5      nUS:X  a  SOSnMh     UUS	   UUUS
.$ )Nr   rv  r\  r   rc  r   r\  ru  r`  )r  r`  rY  longLeverageshortLeverage)r@  r  r  )
r  rc  r  rY  rn  ro  rI  r,  rv  r\  s
             r	  rj  mexc.parse_leverage	  s    
q#h-(AKE((
;H,,UNCLq #00
C" $ 1 1% D(0AGJ ) X&$(*
 	
r  c                    > U R                  U R                  S5      nU R                  USS5      nSn[        [        U ]  XU5      u  pbUS:X  d  USL a  SnXb/$ )a  
@ignore
       marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
       :param dict [params]: extra parameters specific to the exchange API endpoint
       :param bool [params.margin]: True for trading spot-margin
       :returns Array: the marginMode in lowercase
       rJ  rD   FNTr\  )rA  r  rE  r  r3   rS  )r  
methodNamer  defaultValuerJ  r=  rY  r  s          r	  rS  "mexc.handle_margin_mode_and_params  sf     &&t||]C>>&(E:
"4LZamn
8#T)9#J##r  c                 p  #    U R                  5       I Sh  vN   0 nUb-  [        U5      nUS:X  a  U R                  US   5      nUS   US'   Ub  X5S'   U R                  U R	                  XT5      5      I Sh  vN nU R                  US5      n	U R                  XU5      n
U R                  XU5      $  N N<7f)u  
       fetches historical positions

       https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information

       :param str[] [symbols]: unified contract symbols
       :param int [since]: not used by mexc fetchPositionsHistory
       :param int [limit]: the maximum amount of candles to fetch, default=1000
       :param dict [params]: extra parameters specific to the exchange api endpoint

EXCHANGE SPECIFIC PARAMETERS
       :param int [params.type]: position type，1: long, 2: short
       :param int [params.page_num]: current page number, default is 1
       :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
       Nr   r   r7   r`  r  r  )r  r  r  .contractPrivateGetPositionListHistoryPositionsr  r  r  filter_by_since_limit)r  r_  r  rk  r  r  symbolsLengthr  r!  r  	positionss              r	  fetch_positions_historymexc.fetch_positions_history.  s       !!!LM!WQZ0$*4L!#(K LLT[[Y`MijjR ~~h/((?	)))EBBi 	" ks"   B6B2A B67B48;B64B6rY  c                 x  #    U R                  5       I Sh  vN   U R                  U5      nUS   (       a  [        U R                  S-   5      eUR	                  5       nUS:w  a  US:w  a  [        U R                  S-   5      eU R                  US5      nUc  [        U R                  S-   5      eU R                  US	S
5      nUUS:X  a  SOSS.nUb  US   US'   Ub  US:X  a  SOSUS'   U R                  US	5      nU R                  U R                  Xs5      5      I Sh  vN nU R                  X5      $  GN N7f)a  
set margin mode to 'cross' or 'isolated'

https://mexcdevelop.github.io/apidocs/contract_v1_en/#switch-leverage

:param str marginMode: 'cross' or 'isolated'
:param str [symbol]: required when there is no position, else provide params["positionId"]
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.positionId]: required when a position is set
:param str [params.direction]: "long" or "short" required when there is no position
:returns dict: response from the exchange
NrC   z/ setMarginMode() supports contract markets onlyr\  ru  z@ setMarginMode() marginMode argument should be isolated or crossrc  z. setMarginMode() requires a leverage parameterr5  rK  r   r   )rc  rv  r7   r`  r  r\  )r  r  r)   r7   lowerr(   r  r'   safe_string_lower_2r  r]  r  rj  )	r  rY  r`  r  r  rc  r5  r  r!  s	            r	  set_margin_modemexc.set_margin_modet  sF     !!!V$&>DGG&WWXX%%'
#
g(=TWW'iijj$$VZ8#DGG.^$^__,,V[,O	 (J6Q
  &tGH ,5,@aqGN#6;/GGT[Hdee ""8441 	"( fs"   D:D5DD:D8 D:8D:c                 ^    U R                  5       U R                  U R                  SS5      -
  $ )NrG  r   )r  r  r  )r  s    r	  r  
mexc.nonce  s+      "T%6%6t||EUWX%YYYr  r   GETc                    U R                  US5      nU R                  US5      nU R                  X5      u  pS n	US:X  d  US:X  Ga  US:X  a  U R                  S   U   U   S-   U-   n	O+U R                  S   U   U   S-   U R                  -   S-   U-   n	Un
US:X  a  US:X  aR  US	:X  d  US
:X  d  US:X  a@  U R	                  5       U R                  U R                  SS5      S.n
U R                  U5      nO3U R	                  5       U
S'   U R                  U R                  SS5      U
S'   SnU
(       a  U R                  U
5      nU	SU-   -  n	US:X  a  U R                  5         U R                  U R                  U5      U R                  U R                  5      [        R                  5      nU	SU-   -  n	U R                  U R                  U R                  SS5      S.nUS	:X  d  US
:X  d  US:X  a  SUS'   GOUS:X  d  US:X  Gas  U R                  S   U   U   S-   U R!                  X5      -   n	U R#                  X@R%                  U5      5      nUS:X  a   U(       a  U	SU R                  U5      -   -  n	GOU R                  5         ['        U R	                  5       5      nSnU R                  USU R                  U R                  SS5      S.nUS	:X  a  U R                  U5      nUnO3U R)                  U5      nU(       a  XR                  U5      -  nU	SU-   -  n	U R                  U-   U-   nU R                  U R                  U5      U R                  U R                  5      [        R                  5      nXS'   XXeS.$ )Nr   r   rC   r   r   ri  z/api/r   POSTPUTDELETErO  rD  )r  rO  r  r  ?z&signature=rE  )zX-MEXC-APIKEYsourcezapplication/jsonContent-Typer   r   r   )ApiKeyzRequest-Timer  r  	Signature)r  r  bodyheaders)rA  resolve_pathr   r=   r  r  r  r  	urlencoder>  hmacencodesecrethashlibsha256apiKeyimplode_paramsr  extract_paramsr  keysort)r  pathr   r  r  r  r  sectionaccessr  	urlParamsparamsEncoded	signaturer  auths                  r	  sign	mexc.sign  s]   ""3*!!#q)((6f8 3("ii&w/7#=Dii&w/7'ADLLPSVVY]]I"h&Vv-=6U?X^bjXj%)ZZ\&*&7&7lTX&Y!I  99V,D-1ZZ\Ik*.2.?.?l\`.aIl+M $y 9s]**"//1 IIdkk-&@$++dkkBZ\c\j\jk	)I55%)[["..t||XvN & fo6X;M*<'
"g&8))E"7+F3c9D<O<OPT<]]CYYv':':4'@AF!3!777C//1

-	"kk$-$6"..t||XvN	 V#99V,DD!\\&1Fv 66sTz){{Y.5 IIdkk$&7T[[9QSZSaSab	'0$dOOr  reasonr  r  r  r  c
                 8   Uc  g U R                  USS5      n
U
SL a  g U R                  USS 5      nUbg  US:w  aa  US:w  a[  U R                  S-   U-   nU R                  U R                  S   Xl5        U R                  U R                  S	   X5        [        U5      eg )
Nr  FTr<  200r   r  r  )rE  rA  r7   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr#   )r  r<  r  r  r  r  r  r!  requestHeadersrequestBodyr  responseCodefeedbacks                r	  handle_errorsmexc.handle_errors  s     ..9e<d?''&$?$<5+@|WZGZww}t+H001I4Z001I<b))r   )r   r   r   )N)__name__
__module____qualname____firstlineno__r   r  r#  r   r(  r   rO  r"   r   r\  rS  rT  r  r   r  r   r  r   r  dictr  r  r  r
  r   r   r  r   r  r  rD  r  rL  rP  r   r   r   rI  rl  rT  rU  r   r  r   r  r   r  r  r  r  r  r  r  r  r  rr  r  r  r  r  r  r  r   r  r   r  r   r0  r)  r?  rD  rH  rN  r   rT  rY  intr^  re  r   ry  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  r3  r4  r   boolrI  rM  rT  rR  rY  ra  rf  r   rk  rj  rS  rz  r  r  r  r  __static_attributes____classcell__)r  s   @r	  r3   r3      sv
   @# @D )+ #
J ') S 4 -/ e: eN *, 9V 9" /1 zx /1 zx @DB >S > >S\ >@i 	 en  <@d[] ]? ]?S ]? ]?bfglbm ]?~H Hv H HT ?CQUdhqs aK aK aK3 aK^a aKx|  ~B  yC aKF
 
4 
 6:" S47 S4 S4j 68 G1 G1F G1Ro4 o o6 ob 8<B %4W %4N XZ cc c c( Y[ ds d% d( mqy{ "f "fI "fY "fX] "ffi "fH KO[_hj -,^ IMY]fh 4l IMY]fh |5| FH 9+$|*< 9+v 8<B s.C s. s.j 04$UYbd sK sKC sKs sKimnsit sKj <@ 03S 03d 59tZ^gi TUc TU TUTW TUnrsxny TUl 7;\`ik Q Q3 QVY Qptuzp{ Q  9=4^bkm Q# QS QX[ Q  @DRVeirt _ _C __b _ 9=R i.S i.# i.V AER  3tCy  3#  3D 59 V3c V3p_ _v _ _B:	:: : :@S @4l +- g 8 ;= %
c %
AT %
Nf-H f-P *, }? }?~ 37TX\eg X?C X?s X?RU X?t ?CQUdhqs KF3 KF KF3 KF^a KFZ SU  $ FH N# Nu NL^ N CE Ns NE NI[ N ?C2 b3 b b< 9=4^bkm I# IS IX[ IV(
6 (
[ (
T @B 
=3 
=k 
= <>  7s  7+  7D >BPTcgpr @Ys @Y# @Y]` @YD =A ;B' ;BP] ;BzM M$|J\ M^
h 
R` 
* JL +;S +;PTUcPd +;Z >@ '> '>N '>R =?  > : 04$UYbd 8I 8IC 8Is 8Iimnyiz 8It 37TX\eg 6IC 6Is 6IRU 6Ilpq|l} 6Ipf
T f
X f
Q\ f
P:6 8: ,3 ,$ 8<B +3W +34PX> +3Zet eV eN 9=R #s ## #M #J 154VZce dH# dHS dHPS dHjno|j} dHL ac 53 5 5C 5TW 5gt 5nG
t G
x G
= G
R::C :C : QU]_ ::3 :: :: ::# ::do ::x CGr d C . 7;2 
 
0 =A )<' )<V
#8 #J BFb )Iw )IV+A +AZ 8: /13 /1h /1b
t 
V 
x 
* @BPT $  @DRVeirt DCW DCC DC_b DCy}  G  zH DCL DHPR %5 %5S %5NZ &eBSW >P@# s  c TX `c  r  r3   )9 ccxt.async_support.base.exchanger   ccxt.abstract.mexcr   rU  r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3   r  r  r	  <module>r     s    6 *   U  U  U  U  U  U  U  U  * 0 - - . ' & . + ) ) * ) 4 %W[8[ W[r  