
    E#i                    x   S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"  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%J/r/  S SK%J0r0  S SK%J1r1  S SK%J2r2  S SK3J4r4  S SK5J6r6   " S S\\5      r7g)    )Exchange)ImplicitAPIN)AccountAnyBalances
CurrenciesCurrencyDepositAddress	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    C/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/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  aP  U R                  U5      n[        UR                  5       5      n[	        U5      nU(       a  U R                  U5      OSnOSUS:X  aM  U R                  U5      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.$ )	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[
--e4H (DYF,2TYYx(F6!11%8H "__XyAATtyyQYGZF''&9G
 	
r  c                     U R                  SSU5      u  p#SnUS:X  a#  U R                  U5      nU R                  US5      $ US:X  a#  U R                  U5      nU R                  US5      $ g)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
--e4H $$X|<<6!11%8H $$Xv66r  c                    U R                  S5      (       d  0 $ U R                  U5      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$ )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
Fr   coinnetworkListnetWorknetworkN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99&A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 )\ r  c                     U R                   S   (       a  U R                  5         U R                  U5      nU R                  U5      nX#/u  pEU R	                  XE5      $ )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  )r  load_time_differencefetch_spot_marketsfetch_swap_marketsarray_concat)r  r  spotMarketPromiseswapMarketPromise
spotMarket
swapMarkets         r	  fetch_marketsmexc.fetch_markets  s[     <<12%%' 33F; 33F;"3!G
  88r  c                    U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       GH  nX5   nU R	                  US5      nU R	                  US5      nU R	                  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$ ))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
       symbolsr   symbol	baseAsset
quoteAssetr  isSpotTradingAllowedF1TisMarginTradingAllowedmakerCommissiontakerCommissionmaxQuoteAmountr7   /basequotesettleNbaseIdquoteIdsettleIdr=  rC   rD   rE   rF   rG   r6  r   r  baseAssetPrecisionquoteAssetPrecisionr:  pricer4  baseSizePrecisionquoteAmountPrecisionrc  r:  rq  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   rk  rl  rh  ri  r  ra  r6  rc  rd  re  rf  s                      r	  rS  mexc.fetch_spot_markets  s    11&9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 r  c                 2   U R                   nU R                  U SS5        U R                  U5      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$ )-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   r  r   r^  baseCoin	quoteCoin
settleCoinstater7   rg  :rh  ri  rj  rk  rl  rm  r=  rE   rC   FrD   TrF   rG   r6  0r   r  takerFeeRatemakerFeeRaterw  NvolUnit	priceUnitrp  minLeveragemaxLeverager4  minVolmaxVolrt  rv  )
r;   set_propertycontractPublicGetDetailr  r@  r  rA  rB  r~  rF  )r  r  	currentRlr!  r  rH  rI  r  r7   rk  rl  rm  rh  ri  rj  r  isLinears                    r	  rT  mexc.fetch_swap_markets  s    !NN	$R0//7$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 %| r  Nr^  rk  c                    U R                  5         U R                  U5      nSUS   0nUb  X%S'   SnUS   (       a[  U R                  U R                  XS5      5      nU R	                  US5      nU R                  XqU5      nU R	                  US5      US'   U$ US	   (       ak  U R                  U R                  XS5      5      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$ )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
r^  r7   Nrk  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	&>..t{{7/KLH !--hDM--hNI!%!2!28^!LIg2 1 F^88W9UVH& ??8V4D))$<I--dIFI!%!2!24!CIgr  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  countKeyrq  r:  counts	            r	  parse_bid_askmexc.parse_bid_ask  sP      2!!&4  25))r  sincec                 f   U R                  5         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      nOU	S:X  a!  U R                  U R                  Xd5      5      nO{U	S:X  a!  U R                  U R                  Xd5      5      nOT[        U R                  S-   5      eUS   (       a2  U R                  U R                  Xd5      5      n
U R                  U
S5      nU R                  XuX#5      $ )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>`
r^  r7   Nrk  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4T[[5QR::;;DKK<XY0011$++g2NO"477-U#UVV> F^88W9UVH" __Xv6F  >>r  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   arq  orderIdpositionModer  volsider7  feeCurrencyru  rJ  r   r   qtyqquoteQtyisBuyerisMakerisBuyerMakermbuysellcommissionAsset
commissionrI  T)r7   r   r  datetimer^  r=  r  takerOrMakerrq  r:  ru  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_trade7  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           	      P   U R                  5         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      $ 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      nUnGO1U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      nOfUS:X  a!  U R%                  U R                  X5      5      nO?US:X  a!  U R'                  U R                  X5      5      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      $ ) 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
rC   rp  rw  Fr   paginater   r=  r7   )r^  intervalNr  r  r  rk  rE   gMbP?startendrq  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::<X]jp{{//$,,bA__WVnbA
))*@''	2T9Tl&
 &>'')0DEE ',$=((5X*=>C++-C),S#GI& #(  6G95%*	"//G0LMH GF^^//)8LeTE #'#4#4UT\#B  6G95!&(()DIYYvw/FHI%<<T[[=YZg%FFt{{SZGcdf$EEdkkRYFbc"477-p#pqq  ??8V4D88vvvW\^eglmG  )EJJr  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         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      n
O9US	:X  a3  U R                  U R                  X95      5      nU R                  US
/ 5      n
U(       a  U
/n
U R                  X5      $ )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224;;w3NOG2 6!33DKK4OPH8 ooh;GiG!!'33r  c                 `   U R                  5         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      nO9US:X  a3  U R                  U R	                  Xu5      5      nU R                  US0 5      nU R                  Xc5      $ )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>`
r   Nr^  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
 11$++g2MNF. 6!33DKK4OPH4 __Xvr:F  00r  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  r/  r1  r0  r2  r7  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                 R   U R                  5         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      nO$US:X  a  [        U R                  S-   U-   S	-   5      eU(       a  U/nU R                  X5      $ )
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_
88?G 6!tww)QQT^^akklliG!!'33r  ru  c                     U R                  5         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      $ )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>`
rC   9 createMarketBuyOrderWithCost() supports spot orders onlyru  r  r  r   Nr  r  r-   r7   create_orderr  r  r^  ru  r  r  reqs         r	  !create_market_buy_order_with_cost&mexc.create_market_buy_order_with_costd  sl     	V$f~tww)ddeeD
   5!T4;;sC[\\r  c                     U R                  5         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      $ )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>`
rC   rE  ru  r  r  r   NrF  rH  s         r	  "create_market_sell_order_with_cost'mexc.create_market_sell_order_with_costx  sm     	V$f~tww)ddeeD
   61dDKKPSD\]]r  r=  r  r:  rq  c           	          U R                  5         U R                  U5      nU R                  SU5      u  pUS   (       a  U R                  XrX4XXU	5      $ U R	                  XrX4XXU	5      $ )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>`
       rU   rC   )r  r  handle_margin_mode_and_paramscreate_spot_ordercreate_swap_order)
r  r^  r=  r  r:  rq  r  r  rY  r   s
             r	  rG  mexc.create_order  sj    8 	V$ >>}fU
&>))&eY^__))&eY^__r  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  ru  quoteOrderQtyquantityrq  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   r8  price_to_precisionrA  r(   r7   handle_post_onlyr  )r  r  r=  r  r:  rq  rY  r  r^  	orderSider  ru  r  r  quoteAmountrW  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         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      n
OU R                  U	5      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$ )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>`
       testFNr  r=  rq  r:  )r  rE  r  ri  spotPrivatePostOrderTestspotPrivatePostOrderparse_orderrA  )r  r  r=  r  r:  rq  rY  r  rl  r  r!  r   s               r	  rQ  mexc.create_spot_order  s    " 	~~ffe466*00tU`fg44W=H009H(   2ffE7+3"'NE8,4$(Or  c                    U R                  5         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      nO U R%                  U R#                  X5      5      nU R'                  US'5      nU R)                  SU0U5      $ )(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>`
       r^  rH  Fz4 createSwapOrder() does not support yet self symbol:Ncrossr   rY  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=  rs  rq  rc  zK createSwapOrder() requires a leverage parameter for isolated margin orders
reduceOnlyra  r  r  r  r  rW  externalOidrZ  	stopPrice)rW  rv  rg  rw  rZ  ra  triggerTypeexecuteCycletrend	orderTyper  )r  r  r  rE  r-   r7   r'   r  r,   rd  floatra  rc  r  rC  r_  !contractPrivatePostPlanorderPlacer  contractPrivatePostOrderSubmitrA  
safe_order)r  r  r=  r  r:  rq  rY  r  r^  rH  isContractUnavaiablers  rg  r  rc  ru  ra  sideIntegerrW  rZ  r!  r  s                         r	  rR  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 ==dkk'>Z[H::4;;w;WXH &1d|V44r  ordersc           
         U R                  5         / 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      nU R                  U5      $ )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:  rq  r  rU   r   )r  r@  r  rA  r  r-   r7   r(   r  rP  ri  r~  r  spotPrivatePostBatchOrdersparse_orders)r  r  r  ordersRequestsr^  rI  rawOrderr  r  r=  r  r:  rq  orderParamsrY  orderRequestr  r!  s                     r	  create_ordersmexc.create_orders	  sj    	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
 227;*   **r  r7   c                    Uc  [        U R                  S-   5      eU R                  5         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bE  US
:w  a  [        U R                  S-   U-   S-   5      eU R                  U R                  XY5      5      nOaU R                  U R                  XY5      5      nO@US   (       a6  XS'   U R                  U R                  XS5      5      n
U R                  U
S5      nU R                  Xd5      $ )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   rW  origClientOrderIdr  r   rY  z* fetchOrder() does not support marginMode rZ  rE   order_idr  )r'   r7   r  r  rA  r  rP  r(   spotPrivateGetMarginOrderr  spotPrivateGetOrder!contractPrivateGetOrderGetOrderIdr  ro  )r  r7   r^  r  r  r  r  rW  rY  r   r!  s              r	  fetch_ordermexc.fetch_order	  sb    >#DGG.X$XYYV$fTl
 &> ,,V_EM(6?;/<+,%'	" $ B B<QW XJ%+$TWW/[%[^h%h  lF  &F  G  G55dkk'6QR//G0KLZ F^"$J==dkk'>Z[HB ??8V4D--r  c                 ,   U R                  5         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
bE  U
S:w  a  [        U R                  S-   U
-   S-   5      eU R                  U R                  X[5      5      nO U R                  U R                  X[5      5      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  a3  U R!                  U R                  XY5      5      nU R#                  US5      nO2U R%                  U R                  XY5      5      nU R#                  US5      nU R'                  UU5      nU R                  UXbX45      $ )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  rY  z+ fetchOrders() does not support marginMode rZ  
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   rP  r(   spotPrivateGetMarginAllOrdersr  spotPrivateGetAllOrdersr  r  r  rA  r  r  %contractPrivateGetPlanorderListOrdersrU  )r  r^  r  rk  r  r  r  r  r  r   rY  
queryInnerr!  r  r  ordersOfRegularordersOfTriggermergeds                     r	  fetch_ordersmexc.fetch_ordersC
  s     	[[(F &tGH!!&'267+ >>}f]
~'2m(mnn%)%G%GW]%^"J ',$ %*	" #( H%+$TWW/\%\_i%i  mG  &G  H  H==dkk'>^_77G8XY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HHU\IdeF #'//(F"C  EEdkkRYFab6 #'//(F"C&&HF$$VVEJJr  c                 z   U R                  5         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      nU R                  US5      n	U R                  X5      $ )	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 ==dkk'>YZHF >>(F3D$$T22r  c                    U R                  5         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bE  US:w  a  [	        U R
                  S-   U-   S-   5      eU R                  U R                  XY5      5      n
O U R                  U R                  XY5      5      n
U R                  XX#5      $ U R                  S	XX45      $ )
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^  rY  z/ fetchOpenOrders() does not support marginMode rZ  r   )r  r  r  rP  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*  s    	
[[(F!??@QSYb
!$*4L! $ B BCTV\ ]JH%+$TWW/`%`cm%m  qK  &K  L  L>>t{{7?Z[88W9TUb $$XuDD --aNNr  c                 (    U R                  SXX45      $ )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   r  r  r^  r  rk  r  s        r	  fetch_closed_ordersmexc.fetch_closed_orders       ))!VEJJr  c                 (    U R                  SXX45      $ )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  r  r  s        r	  fetch_canceled_ordersmexc.fetch_canceled_orders  r  r  c           	         U R                  5         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      $ )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$$VE;;w;WXXr  c                    U R                  5         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bE  US
:w  a  [        U R
                  S-   U-   S-   5      eU R                  U R                  X5      5      n	OU R                  U R                  X5      5      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      nO1US:X  a  U R                  U/5      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      $ )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 argumentrW  r  r  rY  z+ cancelOrder() does not support marginMode rZ  contractPrivatePostOrderCancelr  "contractPrivatePostPlanorderCancelz& cancelOrder() not support self methodr  r   errorMsg r  z! cancelOrder() the order with id z cannot be cancelled: )r  r  r  rP  r'   r7   rA  r  r(   spotPrivateDeleteMarginOrderr  spotPrivateDeleteOrderr  r  r  r-   r  r,   ro  )r  r7   r^  r  r  r  r  rY  r   r  requestInnerrW  r  r!  r   r  s                   r	  cancel_ordermexc.cancel_order  s?    	[[(F &tGH
!??v^
 >>}fU
~'2](]^^&,"L !,,V_EM(5/:4A01*,Y'%+$TWW/\%\_i%i  mG  &G  H  H88\9YZ224;;|3STJ %%dllMCcdF%%eXv>FH99>>tD??BBB4H"477-U#UVV ??8V4DOOD!,Euj"=H9$"477-P#PSU#UXp#ps{#{||--r  r  c                    U R                  5         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      nU R                  US5      nU R                  Xt5      $ )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[[\\::3?H >>(F3D$$T22r  c                 J   U R                  5         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bE  US:w  a  [        U R
                  S-   U-   S	-   5      eU R                  U R                  XG5      5      nO U R                  U R                  XG5      5      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      nO&U	S:X  a   U R                  U R                  XG5      5      nU R                  US/ 5      n
U R                  X5      $ )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^  rY  z/ cancelAllOrders() does not support marginMode rZ  !contractPrivatePostOrderCancelAllr  %contractPrivatePostPlanorderCancelAllr  )r  r  r  rP  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AA$++gB]^;;DKK<WXJ $$X66!$*4L! %%dll4EGjkF%%eXv>FH<<AA$++gB]^BBEEdkkRYFab >>(FB7D$$T22r  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<  rejectedrX  )r  r  rW  r  r7   r`  r=  r^  )r   
createTimetransactTimer  takerFeemakerFee)rJ  ru  rW  r  r  lastTradeTimestamplastUpdateTimestamp
updateTimer  r  r  rq  rZ  rw  r6  dealAvgPricer:  origQtyr  ru  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  r_  )r  r   r  r<  r7   r`  typeRawr  r  r7  r  r  r  feeSums                 r	  ro  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SELLrb  2rA  r  r  statusess      r	  r  mexc.parse_order_sides  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      $ US:X  a#  U R                  U5      nU R                  US5      $ g )NrC   rE   r  )spotPrivateGetAccountcontractPrivateGetAccountAssetsr  )r  r=  r  r!  s       r	  fetch_account_helpermexc.fetch_account_helper  sI    6>--f55: V^;;FCH& ??8V44r  c                    U R                  SSU5      u  p#U R                  5         U R                  X#5      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$ )
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\]
,,Z?xR8q#d)$AgG++GWjIJ**:6DMM&&w5((&9	 	 % r  c                 N   U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US0 5      nUUU R                  US5      U R                  US5      SSS	.$ )
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>`
rC   z- fetchTradingFee() supports spot markets onlyr^  r7   r  rd  re  N)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
 ..t{{7/KL ~~h3%%d,=>%%d,=>
 	
r  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^  r_  r`  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^  rh  ri  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   r3  r2  s        r	  r%  mexc.parse_balance_helper  s    ,,.**5(;**5&9++E<@z2##E:6!,,T<r  c                 :   U R                  5         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      nOfUS:X  a!  U R                  U R                  X15      5      nO?US:X  a!  U R                  U R                  X15      5      nO[        U R                  S-   5      eU R!                  Xb5      $ )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   r,  )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??G@\]H6!11$++g2NOH6!;;DKK<XYHtww)RRSSj ((>>r  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSnU R	                  SXT5      u  pdSUS   0nSnUS:X  aZ  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      nOvU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      nU R                  US5      nU R                  XX#5      $ )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  sg    >#DGG.[$[\\V$
!??QW`
fTl
  ',$ #( %%fg6E 673%*	"00W1MNF.  (-%''
;;*.((5,,GW:X*YGJ' ',$AA$++gB^_H0 __Xv6F  >>r  c                    U R                  5         0 nSnUb  U R                  U5      nU R                  SXu5      u  pSn
US:X  aH  Uc  [        U R                  S-   5      eUS   US'   XS'   U R                  U R                  Xi5      5      n
O6XS'   U R                  U R                  Xi5      5      nU R                  US	5      n
U R                  XX4U	5      $ )
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   r>  r  )contractPrivateGetOrderDealDetailsOrderIdr  r  )r  r7   r^  r  rk  r  r  r  r  r   r   r!  s               r	  fetch_order_tradesmexc.fetch_order_tradesn  s     	[[(F >>?QSYb
~'2b(bcc &tGH!#I00W1LMF. #%JEEdkkRYFabH0 __Xv6F  uEEr  c                     U R                  US5      nUc  [        U R                  S-   5      eU R                  5         UUUS.nU R	                  U R                  Xd5      5      nU$ )N
positionIdz5 modifyMarginHelper() requires a positionId parameter)rG  r:  r=  )r  r'   r7   r  'contractPrivatePostPositionChangeMarginr  )r  r^  r:  addOrReducer  rG  r  r!  s           r	  modify_margin_helpermexc.modify_margin_helper  sm    &&v|<
#DGG.e$eff$

 ??G@\] r  c                 (    U R                  XSU5      $ )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>`
SUBrJ  r  r^  r:  r  s       r	  reduce_marginmexc.reduce_margin       ((GGr  c                 (    U R                  XSU5      $ )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>`
ADDrN  rO  s       r	  
add_marginmexc.add_margin  rR  r  rc  c                 t   U R                  5         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      $ )	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
rc  rG  Nrs  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  rG  rs  rX  r  s	            r	  set_leveragemexc.set_leverage  s     	
 &&v|<
''
;H++FNCL-3-?T[[(dF l&:'  3V  )V  W  W&.
#$*4L!*6'$.L!==dkk'>Z[[r  c                    U R                  5         Sn0 nUb  U R                  U5      nUS   US'   Ub  X6S'   U R                  U R                  Xd5      5      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
$ )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  r]  rH  rI  r(  r  s                 r	  fetch_funding_historymexc.fetch_funding_history  s    	
 [[(F &tGH#(K @@WA]^B x4__T<<
q#j/*AME))%>IMM & LL3&&ud3**5)<  + r  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  rn  ro  r  r^  r  r  intervalStrings
             r	  parse_funding_ratemexc.parse_funding_rateP  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      $ )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>`
)fetch_funding_rate)r  r^  r  s      r	  fetch_funding_intervalmexc.fetch_funding_intervalz  s     &&v66r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )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>`
r^  r7   r  )r  r  "contractPublicGetFundingRateSymbolr  r  ru  )r  r^  r  r  r  r!  rH  s          r	  rx  mexc.fetch_funding_rate  sn     	V$fTl
 ::4;;w;WX  626&&v66r  c           
         Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X6S'   U R	                  U R                  Xd5      5      nU R                  US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      $ )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>`
z5 fetchFundingRateHistory() requires a symbol argumentr^  r7   r  r  r]  r   r^  rd  )r  r^  rd  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  sL    >#DGG.e$effV$fTl

 #(K ;;DKK<XY2 x0|R8q#f+&AIE''x8H**84K))%>ILL%#//}E& LL3  ' e[1009I5XXr  c                     U R                  5         U R                  USSS5      nU R                  U5      nU R                  US5      nU R	                  XAS5      $ )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
rE   Tr  r^  )r  market_symbolsr  r  parse_leverage_tiersr  r]  r  r!  r  s        r	  fetch_leverage_tiersmexc.fetch_leverage_tiers  s\     	%%gvtTB//7\ ~~h/((AAr  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  rb  )
rA  r$  rB  rF  r1   	string_ltr  r~  r  
string_div)r  r  r  r  r  r  r  r  r  r  floortiersrl  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_addressv  s     "">9=%%nf=
$$^Y?	7#"//
E..yE##NF;
 	
r  r<  c                     U R                  5         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      nU R                  USS5      nU R                  US5      $ )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
r+  r7   r.  NrM  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  s    	==&HTN
 &&vy9	"!44[GN~~h
B?H)..2F"oogvrB ,,[)D	 33KF	 !*I69-;;DKK<XY !884O}}.	::r  c                 (   U R                  5         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      nU R                  X5      $ )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>`
r+  r7   r.  Nz4 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-<<T[[=YZ ))(==r  c                    U R                  US5      nU R                  X5      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$ )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 CCDQ^^$57N7Nw7]^FnnT\\3DEG(,(8(8(G%(4(9U-2245&&tQ/(9?> +f!fim!mp!  CJ  "J  M\  "\  ]  ]r  c                 n   U R                  5         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      nU R                  XX#5      $ )
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::4;;w;WX( &&x5HHr  c                    U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X%S'   Ub  US:  a  [        S5      eX5S'   U R                  U R	                  XT5      5      nU R                  XvX#5      $ )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_withdrawals8  s     	
 }}T*H&tnGFO#(K t|#$TUU$G<<T[[=YZ0 &&x5HHr  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_transactionp  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  )rb  r  r  r  567r  )
rb  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         U R                  U5      nSUS   0nU R                  SU R                  XB5      5      nU R	                  US5      $ )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>`
r^  r7   Nr   )r  r  fetch_positionsr  r  )r  r^  r  r  r  r!  s         r	  fetch_positionmexc.fetch_position  s\     	V$fTl
 ''dkk'.JKx++r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XA5      $ )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>`
r  )r  'contractPrivateGetPositionOpenPositionsr  parse_positionsr  s        r	  r  mexc.fetch_positions  sE     	??G> ~~h3##D22r  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imrX  rb  longshortmargin_moderY  rr  rc  liquidatePricer  r  r7   	contractsrw  
entryPrice
collateralr  unrealizedPnlr   rY  notionalrh  r.  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  rs  
marginTyperc  r  r  s                 r	  parse_positionmexc.parse_position2  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         US:X  aH  SU0nU R                  U R                  Xe5      5      nU R	                  US0 5      nU R                  U5      $ US:X  a  [        U R                  S-   U-   5      eg)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 EEdkkRYFabH >>(FB7D&&t,,6!TWW'OOR\\]]r  c                 ,   SnU R                  SSU5      u  pTU R                  5         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  aS  Ub  X&S'   Ub  US:  a  [        S5      eX6S'   U R                  U R                  Xd5      5      nU R                  US/ 5      nOQUS:X  aK  Ub  X6S'   U R                  U R                  Xd5      5      nU R                  US5      nU R                  US5      nU R                  XX#5      $ )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  r]  )r  r  rJ  r  rA  r'   r7   r#   spotPrivateGetCapitalTransferr  r  'contractPrivateGetAccountTransferRecordr  parse_transfers)r  r<  r  rk  r  r  r  rJ  r  accountTypesr  r]  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"'99$++g:VWH& &"=J6! ',$CCDKKPWD`aH??8V4D|<J2 ##J%GGr  fromAccount	toAccountc                    U R                  5         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      nU R                  X5      nU R                  UUUUS.5      $ )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>`
r  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66t{{77ST ))(={{;&")
  	r  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	  r.  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	  r/  mexc.parse_transfer_status  s'    

 &99r  r  r  c                    U R                  5         U R                  U5      nU R                  XE5      u  pEU R                  USS5      nU(       ay  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      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      nU R                  X5      $ )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>`
r  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"&"M"MdkkZlNu"v ))*=HH>>$,,
B?$$VY	B""8g>))'F3CD7#TN

 ?!FO!(IYYv	9'=>F66t{{77ST %%h99r  ra  c                 `    SU(       a  SOS0nU R                  U R                  XC5      5      nU$ )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   )-contractPrivatePostPositionChangePositionModer  )r  ra  r^  r  r  r!  s         r	  set_position_modemexc.set_position_mode  s7     AQ
 EEdkkRYFbc r  c                 X    U R                  U5      nU R                  US5      nUUS:H  S.$ )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
r  r   )r  ra  )&contractPrivateGetPositionPositionModer  )r  r^  r  r!  r  s        r	  fetch_position_modemexc.fetch_position_mode  s=     >>vF ((6:#q(
 	
r  codesc                 f    U R                  5         U R                  U5      nU R                  X15      $ )\  
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>`
)r  r?  parse_transaction_feesr  rJ  r  r!  s       r	  fetch_transaction_feesmexc.fetch_transaction_fees   s3     	99&A< **8;;r  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!  rJ  withdrawFeesrI  r(  r  rJ  r<  s	            r	  rM  mexc.parse_transaction_feesK  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	  rT  mexc.parse_transaction_feeZ  s    6 ook="Eq#k*+A&>L((yAI**4<<
+CYZK""<?C"%; , r  c                 h    U R                  5         U R                  U5      nU R                  X1S5      $ )rL  r+  )r  r?  parse_deposit_withdraw_feesrN  s       r	  fetch_deposit_withdraw_fees mexc.fetch_deposit_withdraw_fees  s5     	99&A< //HHr  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  rX  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         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  Xc5      $ )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>`
r^  r7   r  )r  r  "contractPrivateGetPositionLeverager  r  parse_leverager  s          r	  fetch_leveragemexc.fetch_leverage  sn     	V$fTl
 ::4;;w;WX> ~~h3""400r  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   rs  rX  r   rc  r   rY  rr  r^  )r  r^  rY  longLeverageshortLeverage)r@  r  r  )
r  rc  r  rY  ri  rj  rI  r(  rs  rX  s
             r	  re  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   FNTrY  )rA  r  rE  r  r3   rP  )r  
methodNamer  defaultValuerJ  r9  rY  r  s          r	  rP  "mexc.handle_margin_mode_and_params  sf     &&t||]C>>&(E:
"4LZamn
8#T)9#J##r  c                 @   U R                  5         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      nU R                  US5      n	U R                  XU5      n
U R                  XU5      $ )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>`
       r   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 FFt{{SZGcdR ~~h/((?	)))EBBr  rY  c                 F   U R                  5         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      nU R                  X5      $ )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
rC   z/ setMarginMode() supports contract markets onlyrY  rr  z@ setMarginMode() marginMode argument should be isolated or crossrc  z. setMarginMode() requires a leverage parameterr0  rG  r   r   )rc  rs  r7   r^  r  rX  )r  r  r)   r7   lowerr(   r  r'   safe_string_lower_2r  rY  r  re  )	r  rY  r^  r  r  rc  r0  r  r!  s	            r	  set_margin_modemexc.set_margin_modes  s.    	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;/AA$++gB^_ ""844r  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   rg  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   rZ  rS  rT  r  r   r  r   r  r   r  dictr  r  r  r  r   r   r  r   r  r  rB  r|  rJ  rM  r   r   r   rG  ri  rQ  rR  r   r  r   r  r   r  r  r  r  r  r  r  r  r  ro  r  r  r  r  r  r  r   r  r   r  r   r,  r%  r;  r@  rD  rJ  r   rP  rU  intrZ  ra  r   ru  ry  rx  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   boolrD  rH  rO  rM  rT  r\  ra  r   rf  re  rP  ru  rz  r  r  r  __static_attributes____classcell__)r  s   @r	  r3   r3      sD
   @# @D #% #
J !# s 4 ') eZ eN $& 9$v, 9" )+ zx )+ zx :>b >s >3 >Y >@i 	 en  6:UW ]?3 ]?s ]?# ]?\`af\g ]?~H Hv H HT 9=4^bkm aK# aK# aKS aKX[ aKrvw{r| aKF
 
4 
 04B S4W S47 S4j 02 G13 G1f G1Ro4 o o6 ob 26b %4w %4N RT ] ]5 ]( SU ^ ^E ^( gksu "`3 "`i "`y "`RW "``c "`H KO[_hj -,^ CGSW`b 4l CGSW`b |5| @B 9+D$6 9+v 26b s.c s.3 s.j *.Dt\^ sK3 sKc sK sKcghmcn sKj 6:" 03s 03d /3TXac TO TO3 TOc TOhlmrhs TOl 154VZce K# KS KPS Kjnotju K  37TX\eg KC Ks KRU K  :>D_cln Y3 Yc YY\ Y 37r i.s i.C i.V ;?r  3c  3C  3D /32 V3 V3p_ _v _ _B:	:: : :@S @4l %' 4= 8 57 %
 %
;N %
Nf-H f-P $& }?( }?~ -1tRV_a X?c X? X?C X?t 9=4^bkm KFS KF# KFS KFX[ KFZ MO 3 $ @B HC H HFX H =? H He HCU H 9=R \S \# \< 37TX\eg IC Is IRU IV(
6 (
[ (
T :< 
7S 
7 
7 68  7  7K  7D 8<$]ajl @Y @YC @YWZ @YD 7;2 ;BG ;B- ;BzM M$|J\ M^
h 
R` 
* DF +;s +;$~J^ +;Z 8: '>3 '>n '>R 79 # ^ : *.Dt\^ 8I3 8Ic 8I 8Icghsct 8It -1tRV_a 6Ic 6I 6IC 6Ifjkvfw 6Ipf
T f
X f
Q\ f
P:6 24 ,S ,$ 26b +3w +3T(^ +3Zet eV eN 37r # #C #m #J +/TPT]_ dHC dHs dH# dHdhivdw dHL [] 5S 5% 5c 5c 5an 5nG
t G
x G
= G
R::C :C : KOWY ::S ::% ::# ::C ::^i ::x =A  c . 15R 
# 
0 7;2 )<G )<V
#8 #J <@ )I )IV+A +AZ 24 /1S /1 /1b
t 
V 
x 
* @BPT $  :>D_cln DCw DCc DCY\ DCsw  yA  tB DCL >B" %5# %5s %5NZ &eBSW >P@# s  c TX `c  r  r3   )8ccxt.base.exchanger   ccxt.abstract.mexcr   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    ( *  U  U  U  U  U  U  U  U  * 0 - - . ' & . + ) ) * ) 4 %W[8[ W[r  