
    ei                       d dl mZ d dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl&m(Z( d dl&m)Z) d d	l&m*Z* d d
l&m+Z+ d dl&m,Z, d dl&m-Z- d dl&m.Z. d dl&m/Z/ d dl&m0Z0 d dl&m1Z1 d dl&m2Z2 d dl&m3Z3 d dl4m5Z5 d dl6m7Z7  G d dee          Z8dS )    )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                       e Zd Zdef fdZi fdZi fdefdZi fdefdZ	i fde
e         fdZi fdZi fdZd	i fd
ededefdZddededefdZd	d	i fd
ededede
e         fdZddededefdZdd	d	i fd
edededede
e         f
dZddedefdZd	i fdedefdZi fd
edefdZdd ededefd!Z d	i fdefd"Z!i fd
ed#e"fd$Z#i fd
ed#e"fd%Z$d	i fd
ed&e%d'e&d(e"d)e'f
d*Z(d	d	i fd+Z)d	d	i fd,Z*d	d	i fd-Z+i fd.e
e,         fd/Z-d	i fd0ed
e.fd1Z/d	d	d	i fd
e.dedede
e0         fd2Z1d	i fd
e.fd3Z2d	d	d	i fd
e.dedede
e0         fd4Z3d	d	d	i fd
e.dedede
e0         fd5Z4d	d	d	i fd
e.dedefd6Z5d	d	d	i fd
e.dedefd7Z6d	i fd0ed
e.fd8Z7d	i fd9e
e         d
e.fd:Z8d	i fd
e.fd;Z9dd<edede0fd=Z:d> Z;d? Z<d@e.fdAZ=dB Z>ddCe.fdDZ?dE Z@i fde
eA         fdFZBi fd
edeCfdGZDdeEfdHZFdI ZGi fdeEfdJZHd	d	d	i fd
e.dedefdKZId	d	d	i fd0ed
e.dedefdLZJi fd
efdMZKi fd
ed(e"deLfdNZMi fd
ed(e"deLfdOZNd	i fdPeOd
e.fdQZPd	d	d	i fd
e.dedefdRZQddedeRfdSZSi fd
edeRfdTZTi fd
edeRfdUZUd	d	d	i fd
e.dedefdVZVd	i fdedeWfdWZXddede
eY         fdXZZddYe[de\fdZZ]i fd[ede
e\         fd\Z^i fd[ede\fd]Z_i fd[ede\fd^Z`d	d	d	i fd[e.dedede
ea         fd_Zbd	d	d	i fd[e.dedede
ea         fd`ZcddaedYe[deafdbZdddcZei fd
efddZfd	i fdede
eg         fdeZhddfedefdgZid	i fd0ed[e.dejfdhZkd	d	d	i fd[e.dedede
ej         fdiZli fd[ed(e"djedkedejf
dlZmddmedYe[dejfdnZndo Zod@e.de.fdpZpd	i fd[ed(e"dqedre.deaf
dsZqd	i fdterd
e.fduZsd	i fd
e.fdvZtd	i fdwefdxZuddyZvddYe[fdzZwd	i fdwefd{ZxddYe[fd|Zyi fd
edezfd}Z{ddPededezfd~Z|i d	f fd	Z}d	d	d	i fdededede
eg         fdZ~d	i fded
e.fdZd Zddi d	d	fdZd[eOdededededefdZ xZS )mexcreturnc                    |                      t          t          |                                           i ddddddgddd	d
dddddi dd dddddddddddddddddddddddd ddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+d d,d d-dd.dd/dd0dd1di d2dd3dd4dd5dd6dd7d d8dd9dd:dd;dd<d d=dd>d d?dd@ddAdBdCdi dDddEddFddGddHddIddJddKddLddMddNddOd dPd dQddRddSddTdi dUddVdBdWddXddYddZdd[dd\dd]d d^dd_dd`ddad dbddcddddBdedBi dfddgddhddid djddkddlddmddnddoddpddqddrd dsdBdtddud dvddd dddddddd d ddwdxdydzdzd{d|d|d{d}d~d{ddidddgdgdddddddddddddddddddii ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddddddidddddddddd{di ddddddddddddddddddddddddddddddddii ddddddddddddddddddddddddۓddddddddddddddi dddddddddddddddddddddddddddddddddd{ddddddddddd	iddddddddddddddddddddddddddd{dddddddddddddddddididdt          dddd dddddddd
d	d
dd|                     d          |                     d          didddddddddddddidddd ddddddd	ddddddddddd
ddd d d!d!d"d#d$i d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d!d d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKd<d<d<d!dLdMdNdOdPdQddddddddRddd dddddSddddddddTdUdidddVd ddWdddddXdd ddddYddZd[d[dddd\ddZd[d[d[dddd]d^dZid_	d`ddidad`dddddRdddddddbd dddcdcdddedidddddfdddcdcdddgdddcd dcdddhd^diidj	dkdlidkdlidd d ddmdni dodpdqdrdsdtdudvdwdxdydzd{d{d|d}d~ddd~ddddddddddddddddddddi dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          i dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          t          t          t          t          t          t          t          t          t          dt          t          t          t          t          t          t          t          t          t          t          dd          S (  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://api.mexc.com/api/v1/contractz#https://api.mexc.com/api/v1/privater   z"https://api.mexc.com/api/v3/broker)rB   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defaultSymbolsexchangeInfodepthtradeshistoricalTrades	aggTradesklinesavgPricezticker/24hrzticker/pricezticker/bookTickerzetf/infoz
kyc/statusuidorder   
openOrders   	allOrdersaccountmyTradeszstrategy/group   zstrategy/group/uidtradeFeesub-account/listsub-account/apiKeyzsub-account/assetz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/repay)zmargin/isolated/pairzmargin/forceLiquidationReczmargin/isolatedMarginDatazmargin/isolatedMarginTierzrebate/taxQueryz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   )rB   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)rB   rD   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   )r[  limitdaysBack	untilDayssymbolRequired)r[  triggerrd  ro  )r[  rl  rp  rd  ro       )r[  rl  rm  rn  rp  rd  ro  )r[  rl  rm  daysBackCanceledrn  rp  rd  ro  rl  )	sandboxrT   rU   r   r   r   r   ri   r   default)extendsrl   )r\  r^  r]  r_  r`  rc  re  rf  Z   )r[  rl  rm  rn  r[  )r[  rl  rp  rd  )r[  rl  rm  rn  rp  rd  )r[  rl  rm  rs  rn  rp  rd    )	rv  rT   rU   r   r   r   r   ri   r   rv  	forDerivs)ru  rB   ry  rD   rE   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    U/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/mexc.pyr  zmexc.describe   s   dD 1 1 : : < < F?
&F?
MF?
 $F?
 	F?

 tF?
 F?
 4F?
  sss $s 	s
 %s %s Ts $Us 's s "4s ts s $Us  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 s 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 s 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 s 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 s 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 sN #'#'$( $$)',#!%#'  es s sF?
x ~ #9#9 
 #E#E 
 #I#H! !
 "#G " /< / U5 yF?
p  $%$%./,.%&&'01)*&'()+,,-12()   &2 (!2 !12  $Q2  )!	2 
 (2  &r2  '2  -b2  1"2  '2  /2  1!2  02  4R2  5a2   7!2 " 7#2  2 $ 6r%2 & /'2 ( 6q)2 * 8+2 , DQ-2 . .q/2 0 3A12 2 *132 4 /52 6 .q72 8 092 : 5a;2 < 0=2 > +A?2 @ 6qA2 B 3AC2 D +AE2  2 F 56:;9:9:/0-.6701;<9:BC/0./+,>@c2  2  2 f!#Q!(!! <Q! 1!	!
 21! 1!! *2! -b! 5a! /! /! 8! 6q! DQ! .r!  .q!!" -a#!( -a  &'*+23,-12./01# #US  S 'g gT   "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!##   mm mqF?
L YMF?
N  OF?
f !&"&!..w77!..w77	 gF?
v +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 JwF?
L $&*(-,1$)$)%*- -
 */+06:#'#'"&#(	( ( #'$)$(+/27/4#(1$ $6 r% ',!$$&%)*.& & ',#($)*.	# # '+!%#($)*.( ( '+!%$%%&#($)*.$ $ '+!%$%,-%&#($)*.	* 	*  #MI IV  )!4(   )(,$($(%)- -
 -1).+0"&$(+0$ $ %)&+!$$&%'	& & %e# ',!$#'$)	( ( ',!$$&%'#'$)$ $ ',!$$&,0%'#'$)* *  #c4 4n "; "; 	  ## ]R RMF?
r  ! (!! z! 	!
 |! y! u! ~! ! ! ! x! %! z! !  
!!" #!$ &%"+! ! !sF?
` 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. ./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 f 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 f 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 f 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 fp )((((((((((((1Kf f fP DNBL4>7C 1->->?K'0$.#0 Qu uaF?
 F F F	    c                   K   |                      dd|          \  }}d}d}d}|dk    re|                     |           d{V }t          |                                          }t	          |          }|r|                     |          nd}nd|dk    r^|                     |           d{V }|                     |d          rdn|                     |          }|                     |d          }||dd|d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   NrB   okrD   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_statuszmexc.fetch_status  s1      !>>}dTZ[[
E!33E::::::::H ((DYYF,2<TYYx(((FF6!!!77>>>>>>>>H "__XyAAZTTtyyQYGZGZF''&99G
 
 	
r  c                   K   |                      dd|          \  }}d}|dk    r1|                     |           d{V }|                     |d          S |dk    r1|                     |           d{V }|                     |d          S dS )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   NrB   
serverTimerD   r  )r  spotPublicGetTimer  r  )r  r  r  r   r!  s        r
  
fetch_timezmexc.fetch_time  s       !>>{DRXYY
E!33E::::::::H $$X|<<<6!!!77>>>>>>>>H $$Xv666tr  c                   K   |                      d          si S |                     |           d{V }i }t          dt          |                    D ]p}||         }|                     |d          }|                     |          }i }|                     |dg           }	t          dt          |	                    D ]}
|	|
         }|                     |dd          }|                     |          }|||d| 	                    |dd          | 	                    |d	d          | 
                    |d
          dd|                     |d          |                     |d          di|                     |d          d
||<   |                     ||||                     |d          dddddddddid|d          ||<   r|S )a0  
        fetches all available currencies on an exchange

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        FNr   coinnetworkListnetWorknetworkdepositEnablewithdrawEnablewithdrawFeer   withdrawMinwithdrawMaxminrj  r   )
r  r6   r,  activer\   r   fee	precisionlimitsr   r7   amountcrypto)r  r6   coder7   r4  r\   r   r5  r6  r7  typerO  )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currencyr6   r:  rO  chainsjchain	networkIdr,  s                 r
  fetch_currencieszmexc.fetch_currencies'  s/      ..u55 	I??GGGGGGGGN q#h--(( -	 -	A{H!!(F33B**2..DH__X}bAAF1c&kk**  q	 ..uiKK	11)<<!#&"#~~e_eLL $u6F N N++E=AA!%"#'#3#3E=#I#I#'#3#3E=#I#I% % !% 0 0
 C C% %!!"  77 ((6:: !##  !$#9 9  F4LL& r  c                   K   | j         d         r|                                  d{V  |                     |          }|                     |          }t	          j        ||g  d{V \  }}|                     ||          S )a  
        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
        rH  N)r  load_time_differencefetch_spot_marketsfetch_swap_marketsasynciogatherarray_concat)r  r  spotMarketPromiseswapMarketPromise
spotMarket
swapMarkets         r
  fetch_marketszmexc.fetch_markets  s       <12 	.++--------- 33F;; 33F;;'.~8IK\7]'^!^!^!^!^!^!^
J  Z888r  c                   K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|                     |d          }|                     |d          }d	}|d
k    r|rd}|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                    i d|d|
dz   |z   d|
d|ddd|d|	ddddddd|dd	dd	dd	d|dd	d dd||ddddd|                     | 	                    |                     |d!                              |                     | 	                    |                     |d"                              d#ddd$|                     |d%          dd$ddd$|                     |d&          |d$d'd|d(           |S ))a2  
 @ignore
        retrieves data on all spot markets for mexc

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nsymbolsr   symbol	baseAsset
quoteAssetr  isSpotTradingAllowedF1TisMarginTradingAllowedmakerCommissiontakerCommissionmaxQuoteAmountr6   /basequotesettlebaseIdquoteIdsettleIdr;  rB   rC   rD   rE   rF   r4  r   r  baseAssetPrecisionquoteAssetPrecisionr8  pricer2  baseSizePrecisionquoteAmountPrecisionre  r8  ro  costr  r  r  contractSizeexpiryexpiryDatetimestrike
optionTyper6  r7  createdr  )
spotPublicGetExchangeInfor  r>  r  r?  r@  rD  appendr  parse_precision)r  r  r!  r  rF  rG  marketr6   ri  rj  rf  rg  r  r_  r4  ra  rb  rc  rd  s                      r
  rP  zmexc.fetch_spot_markets  s~      77????????V xB77q#d))$$ B	 B	A!WF!!&(33B%%fk::F&&v|<<G**622D++G44E%%fh77F#'??6;Q#R#R F#$8%)__V=U%V%V""..v7HIIO"..v7HIIO!--f6FG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\^rEsEs0t0tuu!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  $//8KLL# 
  $# 
  $//8NOO-  $  c2 2 2 2 2 2 2f r  c                   K   | j         }|                     | dd           |                     |           d{V }|                     | d|           |                     |dg           }g }t	          dt          |                    D ]}||         }|                     |d          }|                     |d          }	|                     |d          }
|                     |d	          }|                     |	          }|                     |
          }|                     |          }|                     |d
          }||k    }|                    i d|d|dz   |z   dz   |z   d|d|d|d|	d|
d|ddddddddddddd|dk    ddd|| | 	                    |d           | 	                    |d!          | 	                    |d"          dddd| 	                    |d#          | 	                    |d$          d%| 	                    |d&          | 	                    |d'          d(| 	                    |d)          | 	                    |d*          d(ddd(ddd(d+d|d,           |S )-a>  
 @ignore
        retrieves data on all swap markets for mexc

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r:   r   Nr  r   r\  baseCoin	quoteCoin
settleCoinstater6   re  :rf  rg  rh  ri  rj  rk  r;  rD   rB   FrC   TrE   rF   r4  0r   r  takerFeeRatemakerFeeRateru  volUnit	priceUnitrn  minLeveragemaxLeverager2  minVolmaxVolrr  rt  )
r:   set_propertycontractPublicGetDetailr  r>  r  r?  r@  r|  rD  )r  r  	currentRlr!  r  rF  rG  r~  r6   ri  rj  rk  rf  rg  rh  r  isLinears                    r
  rQ  zmexc.fetch_swap_markets  s      !N	$R00055f========$Y777Z x44q#d))$$ =	 =	A!WF!!&(33B%%fj99F&&v{;;G''==H**622D++G44E,,X66F$$VW5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))&.AA $ 0 0 H H"&""..vyAA!--fkBB   $//FF#//FF! !
  $//AA#//AA 
  $# 
  $#  $  c2 2 2 2 2 2 2f r  Nr\  rl  c                   K   |                                   d{V  |                     |          }d|d         i}|||d<   d}|d         rv|                     |                     ||                     d{V }|                     |d          }|                     |||          }|                     |d          |d<   n|d	         r|                     |                     ||                     d{V }|                     |d
          }	|                     |	d          }
|                     |	||
          }|                     |	d          |d<   |S )a  

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

        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr\  r6   rl  rB   	timestamplastUpdateIdnoncerD   r  r<   )load_marketsr~  spotPublicGetDepthextendr  parse_order_bookcontractPublicGetDepthSymbolr  )r  r\  rl  r  r~  request	orderbookr!  spotTimestampr  r  s              r
  fetch_order_bookzmexc.fetch_order_book  s      !!!!!!!!!V$$fTl
 $GG	&> )	D!44T[[&5Q5QRRRRRRRRH !--hDDM--hNNI!%!2!28^!L!LIgF^ 	D!>>t{{7TZ?[?[\\\\\\\\H& ??8V44D))$<<I--dFIFFI!%!2!24!C!CIgr  r   r   r   priceKey	amountKeycountOrIdKeyc                     d}|                      ||          }|                      ||          }|                      ||          }||||gS ||gS )Nr   )rD  )	r  bidaskr  r  r  countKeyro  r8  counts	            r
  parse_bid_askzmexc.parse_bid_ask  sc      22!!&)44  2265))vr  sincec                   K   |                                   d{V  |                     |          }d|d         i}|||d<   d}|d         r[|                     |ddg          }|||d<   |t          | j        d	z             ||t          | j        d
z             ||d<   |                     | j        dd          }	|                     |d|	          }	|                     |dg          }|	dk    r0|                     | 	                    ||                     d{V }n|	dk    r0| 
                    | 	                    ||                     d{V }n|	dk    r0|                     | 	                    ||                     d{V }ndt          | j        dz             |d         rE|                     | 	                    ||                     d{V }
|                     |
d          }|                     ||||          S )aS  

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

        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: *spot only* *since must be defined* the latest time in ms to fetch entries for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nr\  r6   rl  rB   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 methodrD   r  )r  r~  safe_integer_nr'   r6   r?  r  omitr  r  r  r  r-   contractPublicGetDealsSymbolr  parse_trades)r  r\  r  rl  r  r~  r  r   r  r  r!  s              r
  fetch_tradeszmexc.fetch_trades  st      !!!!!!!!!V$$fTl
 $GG&> E	7''G0DEEE ',$=+DG6y,yzzz =+DG6x,xyyy%*	"%%dl4GIabbF%%fh??FYYvz22F111#::4;;wPV;W;WXXXXXXXX:::#AA$++gW]B^B^________000#77GV8T8TUUUUUUUU"47-U#UVVV> F^ 	7!>>t{{7TZ?[?[\\\\\\\\H" __Xv66F  >>>r  trader~  c                 N   d }d }d }d }d }d }d }	d }
d }d }d }d|v r|                      |d          }|                     d |          }|d         }|                     |d          }|                     |d          }|                     |                     |d                    }	d}
n|                     |d          }|                     ||          }|d         }|                     |dd          }|                     |d	d          }|                     |d
          }d|v r|                      |d          }|                     |d          }|                     |                     |d                    }	|                     |d          |                     |                     |d                    d}|                     |d          rdnd}
n|                     |dd          }|                     |dd          }|                     |d          }|                     |d          }|                     |d          }|                     |dd          }||rdnd}
||rdnd}	||rdnd}	d}
|                     |d          }|,|                     |d          |                     |          d}|5| 	                    | j
        dd           r|                     ||	|||
          }|                     ||||                     |          |||	|
|||||d!|          S )"Nvtr\  pTr  r6   aro  orderIdpositionModer  volsider5  feeCurrencyrs  rH  r  r   qtyqquoteQtyisBuyerisMakerisBuyerMakermbuysellcommissionAsset
commissionrK  T)r6   r   r  datetimer\  r;  r  takerOrMakerro  r8  rs  r5  r  )r  safe_marketr?  parse_order_siderA  r@  r  safe_integer_2safe_value_2rC  r  create_ccxt_trade_id
safe_tradeiso8601)r  r  r~  r6   r  r  r\  r5  r;  r  r  priceStringamountString
costStringmarketIdr  r  
buyerMakerfeeAssets                      r
  parse_tradezmexc.parse_trade?  s   	
%<< ))%55I%%dF33FH%F**5#66K++E377L(()9)9%)E)EFFD"LLh ''x88H%%h77FH%F##E455B,,UGSAAK&&ui88G&& --e[AA	#//u==,,T-=-=eV-L-LMM ,,UE:: $ 7 78H8HP]8^8^ _ _  +///%*I*IVwww //vsCC	#11%DD!--eZ@@
//%;;//%;;!..uncJJ
&.5#B777L&$+755D)%/:66UD#*L++E3DEE' $ 0 0 E E$($;$;H$E$E C :$..7GNN:**9dL+WcddB"Y//( " 
  
   	r  r   	timeframec           	        K   |                                   d{V  |                     |          }|d         rdnd}d}|                     |ddd          \  }}|r!|                     d||||||           d{V S |                     | j        di           }	|                     |	|d	         i           }
|                     |
|          }|                     |          d
z  }|d         |d}d}|                     |ddg          }|}|'|%| 	                    |dg          }|r|n|}|||z  z
  }|d         r|G||d<   |@| 
                    |||z            }|                                 }t          ||          |d<   |||d<   ||dz   |d<   |                     |                     ||                     d{V }|}ny|d         rp||                     |d
z            |d<   |8|                     |d
z            |d<   ||                     |d
z            |d<   |                     |dd          }| 	                    |d          }d}|dk    r0|                     |                     ||                     d{V }n|dk    r0|                     |                     ||                     d{V }nM|dk    r0|                     |                     ||                     d{V }nt'          | j        dz             |                     |d          }|                     |dddddd           }|                     |||||          S )!aD  

        https://www.mexc.com/api-docs/spot-v3/market-data-endpoints#klinecandlestick-data
        https://www.mexc.com/api-docs/futures/market-endpoints#get-candlestick-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
        NrB   i  rx  Fr   paginater   r;  rq  r6   )r\  intervalr  r  r  rl  r   rD   startendro  ru  rV  rU  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  r?  parse_timeframer  r  summillisecondsr3  spotPublicGetKlinesr  parse_to_intcontractPublicGetKlineSymbol&contractPublicGetKlineIndexPriceSymbol%contractPublicGetKlineFairPriceSymbolr-   r6   convert_trading_view_to_ohlcvparse_ohlcvs)r  r\  r  r  rl  r  r~  maxLimitr  r  r   timeframeValuedurationr  candlesr  r  	usedLimitr  nowr!  	priceTyper  s                          r
  fetch_ohlcvzmexc.fetch_ohlcv  s2       !!!!!!!!!V$$!&>43388z[`aa& 	B@@vW\^cenpv  yA  B  B  B  B  B  B  B  B  B//$,bAA__WfVnbAA
))*i@@''	22T9Tl&
 
 ##FWi,@AAEMYYvy11F!&4HIY12E&> >	n ',$=((5(X*=>>C++--C),S#GI& #(  %*QY	"!55dkk'66R6RSSSSSSSSH GGF^ "	n #'#4#4UT\#B#B  !%!2!254<!@!@='+'8'8'F'FGG$(()DDIYYvw//FHI%%!%!B!B4;;wX^C_C_!`!```````g%%!%!L!LT[[Y`bhMiMi!j!jjjjjjjf$$!%!K!KDKKX_agLhLh!i!iiiiiii"47-p#pqqq  ??8V44D88vvvW\^eglmmG  &)UEJJJr  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r   r      r   )r  rD  )r  ohlcvr~  s      r
  parse_ohlcvzmexc.parse_ohlcv0  s~    eQ''UA&&UA&&UA&&UA&&UA&&
 	
r  r[  c                 V  K   |                                   d{V  i }d}d}|@t          |          }|dk    }|                     |d          }|                     |          }|                     d||          \  }}	d}
|r|d         |d<   |dk    r0|                     |                     ||	                     d{V }
nL|d	k    rF|                     |                     ||	                     d{V }|                     |d
g           }
|r|
g}
| 	                    |
|          S )a  
        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   r6   r\  rB   rD   r  )
r  r  r?  r~  r  spotPublicGetTicker24hrr  contractPublicGetTickerr  parse_tickers)r  r[  r  r  r~  isSingularMarketr"  firstSymbolr  r   tickersr!  s               r
  fetch_tickerszmexc.fetch_tickers:  sq      !!!!!!!!! \\F%{**7A66K[[--F >>~vW]^^
E 	- &tGH 88We9T9TUUUUUUUUGG2 6!!!99$++gu:U:UVVVVVVVVH8 ooh;;G 	 iG!!'7333r  c                   K   |                                   d{V  |                     |          }|                     d||          \  }}d}d|d         i}|dk    r0|                     |                     ||                     d{V }nL|dk    rF|                     |                     ||                     d{V }|                     |di           }|                     ||          S )aD  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nr   r\  r6   rB   rD   r  )r  r~  r  r  r  r  r  parse_ticker)	r  r\  r  r~  r  r   r   r  r!  s	            r
  fetch_tickerzmexc.fetch_ticker  s      !!!!!!!!!V$$ >>}fV\]]
EfTl
 77GU8S8STTTTTTTTFF. 6!!!99$++gu:U:UVVVVVVVVH4 __Xvr::F  000r  r   c                 8   |                      |d          }|                     ||          }d }d }d }d }d }d }	d }
d }d }d }d }d }d }|                     |d          }|sd|v r|                     |d          }|                      |d          }|                      |d          }|                      |d          }	|                      |d          }
|                      |d          }|                      |d	          }|                      |d
          }|                      |d          }t	          j        |d          }na|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }t	          j        |d          rd }t	          j        |d          rd }|                      |d          }	|                      |d          }
|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }t	          j        |d          }|                     i d|d         d|d|                     |          d|d|d|d|                      |d           d!|d"|d#|d$|d%d d&|d'|d(|d)d d*|	|
|d+|          S ),Nr\  rD   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  )	r?  r  r  r  r1   
string_mul	string_eqsafe_tickerr  )r  r   r~  r  r  r#  r%  r$  r&  r+  r  r  r  r  
changePcntchangeValue	prevCloseisSwaps                     r
  r	  zmexc.parse_ticker  s   ##FH55!!(F33			

	00 H	?kV++, ))&+>>I""6622C""6622C))&*==J**6:>>K##FM::D""6>::C**6?CCK))&.AAJ +J>>JJ0 ))&+>>I""6:66C""6:66C((::I((::I C00 ! 	 C00 ! 	))&(;;J**6=AAK##FK88D##FK88D""6:66C((1ABBI**6=AAK))&2FGGJ +J>>J !
fX&!
!
 Y//!
 D	!

 D!
 3!
 T%%fk::!
 3!
 !
 3!
 !
 D!
 Y!
 k!
 *!
  t!!
" *#!
$ ''!
 !
 !
( )  	r  c                   K   |                                   d{V  d}d}|0t          |          }|dk    }|                     |d                   }|                     d||          \  }}d}|dk    r|                     |           d{V }n#|dk    rt          | j        dz   |z   d	z             |r|g}|                     ||          S )
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   r`   rB   rD   z& fetchBidsAsks() is not available for z markets)r  r  r~  r  spotPublicGetTickerBookTickerr-   r6   r  )	r  r[  r  r~  r  r"  r  r   r  s	            r
  fetch_bids_askszmexc.fetch_bids_asksI  s      !!!!!!!!! \\F%{[[,,F >>PVX^__
E >>uEEEEEEEEGG 6!!tw)QQT^^akklll 	 iG!!'7333r  rs  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|i}|                     |dddd|                     ||                     d{V S )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>`
        NrB   9 createMarketBuyOrderWithCost() supports spot orders onlyrs  r~  r  r   r  r~  r-   r6   create_orderr  r  r\  rs  r  r~  reqs         r
  !create_market_buy_order_with_costz&mexc.create_market_buy_order_with_costp  s       !!!!!!!!!V$$f~ 	ftw)ddeeeD
 &&vx4UXZ`IaIabbbbbbbbbr  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|i}|                     |dddd|                     ||                     d{V S )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>`
        NrB   r7  rs  r~  r  r   r8  r:  s         r
  "create_market_sell_order_with_costz'mexc.create_market_sell_order_with_cost  s       !!!!!!!!!V$$f~ 	ftw)ddeeeD
 &&vxD$++VY[aJbJbcccccccccr  r;  r  r8  ro  c           	      *  K   |                                   d{V  |                     |          }|                     d|          \  }}	|d         r!|                     |||||||	           d{V S |                     |||||||	           d{V S )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>`
        NrT   rB   )r  r~  handle_margin_mode_and_paramscreate_spot_ordercreate_swap_order)
r  r\  r;  r  r8  ro  r  r~  r[  r   s
             r
  r9  zmexc.create_order  s      8 !!!!!!!!!V$$ >>}fUU
E&> 	f//dFES]_deeeeeeeee//dFES]_deeeeeeeeer  c                 .   |d         }|                                 }	|d         |	|                                 d}
|dk    r|                     |dd          }|                     |d          }||}|                     ||          |
d<   n||                     ||          |
d<   nt|                     |          }|                     |          }t          j        ||          }|}|                     ||          |
d<   n|                     ||          |
d<   ||                     ||          |
d<   | 	                    |d	          }|||
d
<   |                     |dd	g          }|#|dk    rt          | j        dz   |z   dz             d }|                     |dk    |dk    |          \  }}|rd|
d<   | 	                    |d          }|-|                     |d          }|dk    rd|
d<   n|dk    rd|
d<   |                     |
|          S )Nr\  r6   )r\  r  r;  r~  rs  quoteOrderQtyquantityro  clientOrderIdnewClientOrderIdr;  isolatedz+ createOrder() does not support marginMode  for spot-margin tradingLIMIT_MAKERrb  rW  IMMEDIATE_OR_CANCELrX  FILL_OR_KILL)uppersafe_number_2r  cost_to_precisionamount_to_precisionnumber_to_stringr1   r,  price_to_precisionr?  r(   r6   handle_post_onlyr  )r  r~  r;  r  r8  ro  r[  r  r\  	orderSider  rs  r  r  quoteAmountrF  postOnlytifs                     r
  create_spot_order_requestzmexc.create_spot_order_request  st   !JJLL	TlJJLL
 

 8%%ffoFFDYYvv..F+/+A+A&&+Q+Q((=*.*B*B66*R*RGJ''#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK(F/3/E/Eff/U/UGO,,"&":":66"J"JGJ#66vuEEGG((AA$*7G&'YYv'@AAF!Z'' +X!X[e!e  iC  "C  D  D  D001A4=CXZ`aa& 	,+GFOv}55?YYv}55Fe||"7"0{{7F+++r  c           	        K   |                                   d{V  |                     |dd          }|                     |d          }|                     |||||||          }	d}
|r|                     |	           d{V }
n|                     |	           d{V }
|                     |
|          }||d<   ||d<   |                     |d          ||d<   |                     |d          ||d<   |S )al  
 @ignore
        create a trade order

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

        :param str market: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param str [marginMode]: only 'isolated' is supported for spot-margin trading
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NtestFr  r;  ro  r8  )r  rC  r  rX  spotPrivatePostOrderTestspotPrivatePostOrderparse_orderr?  )r  r~  r;  r  r8  ro  r[  r  rZ  r  r!  r   s               r
  rA  zmexc.create_spot_order  s;     " !!!!!!!!!~~ffe4466**00tVUT^`fgg 	@!::7CCCCCCCCHH!66w????????H(   622ffE7++3"E'NE8,,4$E(Or  c                 f  K   |                                   d{V  |d         }|                     | j        di           }	|                     |	|d          }
|
rt	          | j        dz   |z             d}|)|dk    rd}n7|dk    rd	}n.t          | j        d
z             |                     |dd          }|dk    rA|dk    r;|d	k    r5|dk    r/|dk    r)|dk    r#|dk    r|dk    rt          | j        dz             d}| 	                    |dk    |dk    |          \  }}|rd}n|dk    rd	}n|dk    rd}|d         t          |                     ||                    ||d}|dk    r2|dk    r,|dk    r&t          |                     ||                    |d<   |d	k    r/|                     |d          }|t          | j        dz             |                     |dd          }|                     |dd          }d}|r2|r |                     |d          }|dk    rdnd}|dk    rd	nd}d	|d<   n|r|dk    rdnd}n
|dk    rd	nd}||d<   |                     |dd          }|||d<   |                     |d d!          }|                     |g d"          }d}|r|                     ||          |d <   |                     |d#d	          |d#<   |                     |d$d	          |d$<   |                     |d%d	          |d%<   |                     |d&d	          |d&<   |                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d'          }|                     d|i|          S )(a  
 @ignore
        create a trade order

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

        :param str market: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param str [marginMode]: only 'isolated' is supported for spot-margin trading
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
        :param bool [params.reduceOnly]: indicates if self order is to reduce the size of a position
        :param bool [params.hedged]: *swap only* True for hedged mode, False for one way mode, default is False

 EXCHANGE SPECIFIC PARAMETERS
        :param int [params.leverage]: leverage is necessary on isolated margin
        :param long [params.positionId]: it is recommended to hasattr(self, fill) parameter when closing a position
        :param str [params.externalOid]: external order ID
        :param int [params.positionMode]: 1:hedge, 2:one-way, default: the user's current config
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr\  rJ  Fz4 createSwapOrder() does not support yet self symbol:crossr   rH  r   zN createSwapOrder() marginMode parameter should be either "cross" or "isolated"openTyperl  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 pricer6   )r\  r  r;  r`  ro  re  zK createSwapOrder() requires a leverage parameter for isolated margin orders
reduceOnlyrc  r  r  r  r  rF  externalOidr\  	stopPrice)rF  rc  rV  rd  r\  rc  triggerTypeexecuteCycletrend	orderTyper  )r  r  r  rC  r-   r6   r'   r  r,   rS  floatrP  rR  r  rA  rN  !contractPrivatePostPlanorderPlacer  contractPrivatePostOrderSubmitr?  
safe_order)r  r~  r;  r  r8  ro  r[  r  r\  rJ  isContractUnavaiabler`  rV  r  re  rb  rc  sideIntegerrF  r\  r!  r  s                         r
  rB  zmexc.create_swap_order!	  s     8 !!!!!!!!!!#t|=SUWXX#~~.BFERR 	jtw)__bhhiii!W$$z))'  3C  )C  D  D  D((Q??HGOO$("2"2QRY]abYbYbimqririry}  BC  zC  zC  JN  RS  JS  JStw  *y   y  z  z  z001A419fUU& 	DDW__DDXDTl11&&AABB  #
 
4 AIIDAIIDH,<,<$T%<%<VU%K%KLLGGq==((<<H'2(  A  A  A^^FL%@@
%88 
	: <6<88"&%--vve $!!AK&'GN## :$(EMMaa$(EMMaa%**6?MRR$%2GM"))&.+NN6#v#v#vww 	_&*&=&=fl&S&SGN#%)%6%6v}a%P%PGM"&*&7&7PQ&R&RGN##00!DDGG#'#4#4V[!#L#LGK !CCDKKPWY_D`D`aaaaaaaaHH!@@WV\A]A]^^^^^^^^H &11d|V444r  ordersc           
      p  K   |                                   d{V  g }d}t          dt          |                    D ]1}||         }|                     |d          }|                     |          }|d         st          | j        dz             ||}n||k    rt          | j        dz             |                     |d          }	|                     |d          }
|                     |d	          }|                     |d
          }|                     |di           }d}| 	                    d|          \  }}| 
                    ||	|
||||          }|                    |           3d|                     |          i}|                     |           d{V }|                     |          S )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\  rB   z2 createOrders() is only supported for spot marketsz; createOrders() requires all orders to have the same symbolr;  r  r8  ro  r  rT   r   )r  r>  r  r?  r~  r-   r6   r(   r  r@  rX  r|  r  spotPrivatePostBatchOrdersparse_orders)r  ro  r  ordersRequestsr\  rG  rawOrderr  r~  r;  r  r8  ro  orderParamsr[  orderRequestr  r!  s                     r
  create_orderszmexc.create_orders	  s      !!!!!!!!!q#f++&& 	0 	0AayH''(;;H[[**F&> c"47-a#abbb~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAKJ!%!C!CMSY!Z!ZJ99&$fV[]gituuL!!,////499^44
 88AAAAAAAA*   ***r  r6   c                 <  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}d}|d         r|                     |d          }||                     |d          }||d<   n||d<   |                     d	|          \  }}	|S|d
k    rt          | j        dz   |z   dz             |                     | 	                    ||	                     d{V }n| 
                    | 	                    ||	                     d{V }nR|d         rJ||d<   |                     | 	                    ||                     d{V }
|                     |
d          }|                     ||          S )ak  
        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\  r6   rB   rF  origClientOrderIdr  r   rH  z* fetchOrder() does not support marginMode rI  rD   order_idr  )r'   r6   r  r~  r?  r  r@  r(   spotPrivateGetMarginOrderr  spotPrivateGetOrder!contractPrivateGetOrderGetOrderIdr  r]  )r  r6   r\  r  r~  r  r  rF  r[  r   r!  s              r
  fetch_orderzmexc.fetch_order	  s      >#DG.X$XYYY!!!!!!!!!V$$fTl
 &> ]	5 ,,V_EEM(6?;;/<+,,%'	" $ B B<QW X XJ%++$TW/[%[^h%h  lF  &F  G  G  G!;;DKKQV<W<WXXXXXXXX!55dkk'56Q6QRRRRRRRRZ F^ #	5"$GJ!CCDKKPWY_D`D`aaaaaaaaHB ??8V44Df---r  c                 ,  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |                     |d          }|                     |d          }|                     d||          \  }}	|dk    r|t          | j        dz             |                     d|          \  }
}|||d<   |||d	<   |||d
<   d}|
S|
dk    rt          | j        dz   |
z   dz             | 	                    | 
                    ||                     d{V }n/|                     | 
                    ||                     d{V }|                     ||||          S |t||d<   |                     |d|          }|%|                     || j        d                   |d<   n_||z
  | j        d         k    rt          | j        dz             ||d<   n.|,|                     || j        d         dz            |d<   ||d<   |||d<   |                     | j        dd          }|                     |	d|          }g }g }|dk    rF|                     | 
                    ||	                     d{V }|                     |d          }nE|                     | 
                    ||	                     d{V }|                     |d          }|                     ||          }|                     |||||          S )a  
        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>`
        Nr6   r\  r  r   rB   z9 fetchOrders() requires a symbol argument for spot marketr  r  rl  rH  z+ fetchOrders() does not support marginMode rI  
start_timeend_timerR  z. end is invalid, i.e. exceeds allowed 90 days.	page_size(contractPrivateGetOrderListHistoryOrdersr  r  )r  r~  r  r  r  r'   r6   r@  r(   spotPrivateGetMarginAllOrdersr  spotPrivateGetAllOrdersrr  r  r  r?  r  r  %contractPrivateGetPlanorderListOrdersrT  )r  r\  r  rl  r  r  r~  r  r  r   r[  
queryInnerr!  r  r  ordersOfRegularordersOfTriggermergeds                     r
  fetch_orderszmexc.fetch_ordersO
  s       !!!!!!!!![[((F &tGH!!&'2267++ >>}fV\]]
E~'2m(mnnn%)%G%GW]%^%^"J
 ',$ %*	" #( H%++$TW/\%\_i%i  mG  &G  H  H  H!%!C!CDKKPWYcDdDd!e!eeeeeee!%!=!=dkk'S]>^>^!_!_______b $$XvueDDD (-%''
EBB;*.((5$,GW:X*Y*YGJ''et|4D'EEE(3c)cddd.3
++"(,EU8VY[8[(\(\%&+
# ',$%%dlMCmnnF%%eXv>>F O OCCC!%!N!Nt{{[bdiOjOj!k!kkkkkkkF #'//(F"C"C "&!K!KDKKX_afLgLg!h!hhhhhhh6 #'//(F"C"C&&HHF$$VVUE6JJJr  c                   K   |                                   d {V  i }d }| |                     |          }|d         |d<   |                     d||          \  }}|dk    rt          | j        dz   |z             d                    |          |d<   |                     |                     ||                     d {V }|                     |d          }	| 	                    |	|          S )	Nr6   r\  fetchOrdersByIdsrB   z) fetchOrdersByIds() is not supported for ,	order_idsr  )
r  r~  r  r(   r6   join!contractPrivateGetOrderBatchQueryr  	safe_listrr  )
r  idsr\  r  r  r~  r  r   r!  r  s
             r
  fetch_orders_by_idszmexc.fetch_orders_by_ids  s     !!!!!!!!![[((F &tGH >>?QSY[abb
ETW'RRU__```#&88C==GK !CCDKKPWY^D_D_````````HF >>(F33D$$T6222r  c                 z  K   |                                   d{V  i }d}d}||                     |          }|                     d||          \  }}|dk    r||d         |d<   |                     d|          \  }}	d}
|S|dk    rt	          | j        dz   |z   dz             |                     |                     ||	                     d{V }
n/|                     |                     ||	                     d{V }
| 	                    |
|||          S | 
                    d	||||           d{V S )
a7  
        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   rB   r6   r\  rH  z/ fetchOpenOrders() does not support marginMode rI  r   )r  r~  r  r@  r(   r6   spotPrivateGetMarginOpenOrdersr  spotPrivateGetOpenOrdersrr  fetch_orders_by_state)r  r\  r  rl  r  r  r~  r  r[  r   r!  s              r
  fetch_open_orderszmexc.fetch_open_orders6  s      !!!!!!!!!
[[((F!??@QSY[abb
F!$*4L! $ B BCTV\ ] ]JH%++$TW/`%`cm%m  qK  &K  L  L  L!%!D!DT[[QXZ_E`E`!a!aaaaaaa!%!>!>t{{7TY?Z?Z![![[[[[[[b $$XvueDDD 33AvueVTTTTTTTTTr  c                 D   K   |                      d||||           d{V S )a  
        fetches information on multiple closed orders made by the user

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

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r   Nr  r  r\  r  rl  r  s        r
  fetch_closed_orderszmexc.fetch_closed_orders  6       //65%PPPPPPPPPr  c                 D   K   |                      d||||           d{V S )a  
        fetches information on multiple canceled orders made by the user

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

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        r  Nr  r  s        r
  fetch_canceled_orderszmexc.fetch_canceled_orders  r  r  c           	      L  K   |                                   d {V  i }d }||                     |          }|                     d||          }|dk    rt          | j        dz   |z             ||d<   |                     ||||                     ||                     d {V S )NfetchOrdersByStaterB   z+ fetchOrdersByState() is not supported for states)r  r~  r  r-   r6   r  r  )	r  r  r\  r  rl  r  r  r~  r  s	            r
  r  zmexc.fetch_orders_by_state  s      !!!!!!!!![[((F778LfV\]]
tw)VVYccddd %GH**65%WV\A]A]^^^^^^^^^r  c                   K   |                                   d{V  i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|                     d|          \  }}d}	|dk    r|t	          | j        dz             d|d         i}
|                     |d          }||                     |d          }||
d<   n||
d	<   |T|d
k    rt          | j        dz   |z   dz             | 	                    | 
                    |
|                     d{V }	n+|                     | 
                    |
|                     d{V }	n|                     | j        dd          }|                     |d|          }d}|dk    r|                     |g           d{V }n:|dk    r|                     |g           d{V }nt          | j        dz             |                     |d          }	|                     |	d          }|                     |dd          }|dk    r t#          | j        dz   |z   dz   |z             |                     |	|          S )a  
        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>`
        Nr6   r\  rL   rB   z) cancelOrder() requires a symbol argumentrF  ry  r  rH  z+ cancelOrder() does not support marginMode rI  contractPrivatePostOrderCancelr  "contractPrivatePostPlanorderCancelz& cancelOrder() not support self methodr  r   errorMsg r  z! cancelOrder() the order with id z cannot be cancelled: )r  r~  r  r@  r'   r6   r?  r  r(   spotPrivateDeleteMarginOrderr  spotPrivateDeleteOrderr  r  r  r-   r  r,   r]  )r  r6   r\  r  r  r~  r  r[  r   r  requestInnerrF  r  r!  r   r  s                   r
  cancel_orderzmexc.cancel_order  s      !!!!!!!!![[((F &tGH
!??vW]^^
F >>}fUU
E~'2](]^^^&,"L !,,V_EEM(5/::4A011*,Y'%++$TW/\%\_i%i  mG  &G  H  H  H!>>t{{<Y^?_?_````````!88\SX9Y9YZZZZZZZZJ %%dlMCcddF%%eXv>>FH999!%!D!DbT!J!JJJJJJJ???!%!H!H"!N!NNNNNNN"47-U#UVVV ??8V44DOOD!,,Euj"==H9$$"47-P#PSU#UXp#ps{#{|||f---r  r  c                 h  K   |                                   d{V  ||                     |          nd}|                     d||          }|dk    rt          | j        dz   |z             |                     |           d{V }|                     |d          }|                     ||          S )a  
        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>`
        NrM   rB   z% cancelOrders() is not supported for r  )r  r~  r  r(   r6   r  r  rr  )r  r  r\  r  r~  r  r!  r  s           r
  cancel_orderszmexc.cancel_orders$  s       !!!!!!!!!)/);V$$$$77PVWW
TW'NNQ[[\\\!@@EEEEEEEEH >>(F33D$$T6222r  c                   K   |                                   d{V  ||                     |          nd}i }d}|                     d||          \  }}|                     d|          \  }}|dk    r|t	          | j        dz             |d         |d<   d}|S|dk    rt          | j        dz   |z   d	z             |                     |                     ||                     d{V }n/| 	                    |                     ||                     d{V }| 
                    ||          S ||d         |d<   |                     | j        dd
          }	|                     |d|	          }	d}|	d
k    r0|                     |                     ||                     d{V }n5|	dk    r/|                     |                     ||                     d{V }|                     |dg           }
| 
                    |
|          S )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>`
        NrK   rB   z5 cancelAllOrders() requires a symbol argument on spotr6   r\  rH  z/ cancelAllOrders() does not support marginMode rI  !contractPrivatePostOrderCancelAllr  %contractPrivatePostPlanorderCancelAllr  )r  r~  r  r@  r'   r6   r(   !spotPrivateDeleteMarginOpenOrdersr  spotPrivateDeleteOpenOrdersrr  r?  r  r  r  r  )r  r\  r  r~  r  r  r[  r   r!  r  r  s              r
  cancel_all_orderszmexc.cancel_all_ordersF  s      !!!!!!!!!)/);V$$$$
!??@QSY[abb
F >>?PRXYY
E~'2i(ijjj &tGHH%++$TW/`%`cm%m  qK  &K  L  L  L!%!G!GT[]bHcHc!d!ddddddd!%!A!A$++gW\B]B]!^!^^^^^^^J $$Xv666!$*4L! %%dl4EGjkkF%%eXv>>FH<<<!%!G!GT[]bHcHc!d!dddddddBBB!%!K!KDKKX_afLgLg!h!hhhhhhh >>(FB77D$$T6222r  r   c                    |                      |d          }|-|                     |d|                     |d          d          S d }t          |t                    r|}n|                     |dd          }|                     |                     |d                    }|                     |d          }||                     |          }|                     |d	          }|                     ||          }| 	                    |g d
          }d }	|                     |d          }
|
Y|                     |d          }|                     |d          }t          j        ||          }|
|                     |          d}	|                     i d|d|                     |d          d|d|                     |          dd d|                      |d          d|                     |                     |dd                    d	|d	         d|                     |          d|d|                     |                     |d                    d|                     |d          d|                     |dd          d|                     |d          d|                     |dd          d |                     |d!          d"|                     |d#d$          d |	d |d%|          S )&Nr:  rejectedrG  )r  r  rF  r  r6   rb  r;  r\  )r   
createTimetransactTimer  takerFeemakerFee)rH  rs  rF  r  r  lastTradeTimestamplastUpdateTimestamp
updateTimer  r  r  ro  r\  rd  r*  dealAvgPricer8  origQtyr  rs  cummulativeQuoteQtyfilledexecutedQtydealVol)	remainingr5  r   r  )r  rl  r?  
isinstancestrrA  parse_order_time_in_forceget_tif_from_raw_order_typer  r  r1   
string_addr  r  parse_order_statusparse_order_typer  rD  rN  )r  r   r~  r:  r6   rb  typeRawr  r  r5  r  r  r  feeSums                 r
  r]  zmexc.parse_order  s   V   //??$!%!1!1%9K!L!L$ $   
 eS!! 	<BB##E9d;;B44T5E5Ee]5[5[\\""5&11::7CCK##E844!!(F33''/U/U/UVV	&&um<<"''z::H''z::H'(;;F'))&11 C   
" 
T--e_EE 
  
 Y//	 

 !$ 
 "4#4#4UL#I#I 
 d--d.@.@RY.Z.Z[[ 
 fX& 
 D))'22 
 ; 
 D))$*:*:5&*I*IJJ 
 T%%eW55 
 D..uk>RR 
 t''~>> 
 d((	5AA 
  D$$U,ABB! 
" d((yII# 
$ + 
  
  
, -  	r  c                 >    ddddd}|                      |||          S )Nr  r  )BUYSELLr`  2r?  r  r  statusess      r
  r  zmexc.parse_order_side  s4    	
 
 &&999r  c                 @    dddddd}|                      |||          S )Nr~  rl  )MARKETLIMITrJ  rK  rL  r  r  s      r
  r  zmexc.parse_order_type  s7    "#*#
 
 &&999r  r  c           	      F    ddddddddd}|                      |||          S )Nr  closedcanceled)NEWFILLEDCANCELEDPARTIALLY_FILLEDPARTIALLY_CANCELEDr  34r  r  s      r
  r  zmexc.parse_order_status  sB    " &", 
 
 &&999r  c                 <    dddd}|                      |||          S )NGTCrX  rW  )r  rX  rW  r  r  s      r
  r  zmexc.parse_order_time_in_force  s1    
 

 &&999r  rh  c                 @    dddddd}|                      |||          S )Nr  	POST_ONLYrW  rX  )r  rJ  rK  rL  r  r  )r  rh  r  s      r
  r  z mexc.get_tif_from_raw_order_type  s7    &#(!
 
 )Y???r  c                    K   |dk    r|                      |           d {V S |dk    r1|                     |           d {V }|                     |d          S d S )NrB   rD   r  )spotPrivateGetAccountcontractPrivateGetAccountAssetsr  )r  r;  r  r!  s       r
  fetch_account_helperzmexc.fetch_account_helper  s      6>>33F;;;;;;;;;: V^^!AA&IIIIIIIIH& ??8V444tr  c                   K   |                      dd|          \  }}|                                  d{V  |                     ||           d{V }|                     |dg           }g }t	          dt          |                    D ]x}||         }|                     |dd          }	|                     |	          }
|                    | 	                    |d          | 	                    |d          |
|d	           y|S )
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   assetrH  r6   r;  )r6   r;  r:  r  )
r  r  r  r  r>  r  rA  r@  r|  r?  )r  r  r  r   r!  r  rF  rG  r   
currencyIdr:  s              r
  fetch_accountszmexc.fetch_accounts  s5      !>>PTV\]]
E!!!!!!!!!22:uEEEEEEEExR88q#d))$$ 		 		A1gG++GWjIIJ**:66DMM&&w55((&99	      r  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |di           }|||                     |d          |                     |d          ddd	S )
aa  
        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>`
        NrB   z- fetchTradingFee() supports spot markets onlyr\  r6   r  rb  rc  )r  r\  r  r  r  r   )r  r~  r(   r6   spotPrivateGetTradeFeer  	safe_dictrD  r  r\  r  r~  r  r!  r  s          r
  fetch_trading_feezmexc.fetch_trading_fee  s       !!!!!!!!!V$$f~ 	XTW'VVWWWfTl
 44T[[&5Q5QRRRRRRRR ~~h33%%d,=>>%%d,=>>
 
 	
r  c                    d }|dk    r|                      |dg           }n5|dk    r|                      |dg           }n|                      |dg           }d|i}|dk    r"t          dt          |                    D ]}||         }|                     |d          }|                     |d           }|                      |d	i           }	|                      |d
i           }
|                     |                     |	d                    }|                     |                     |
d                    }i }|                     |	          ||<   |                     |
          ||<   |                     |          ||<   |S |dk    rt          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )NrC   assetsrD   r  r  r  r   r\  r]  r^  r  rH  availableBalancefreefrozenBalanceusedlocked)	r  r>  r  r?  safe_symbolr@  parse_balance_helpersafe_balancer   )r  r!  r  walletrF  rG  entryr  r\  rf  rg  baseCode	quoteCode	subResultr  r:  r   s                    r
  custom_parse_balancezmexc.custom_parse_balance/  s   z !!__Xx<<FF6!!__Xvr::FF__Xz2>>F(#!!1c&kk** > >q	++E8<<))(D99uk2>>|R@@2243C3CD'3R3RSS 33D4D4DUG4T4TUU	"$	&*&?&?&E&E	(#'+'@'@'G'G	)$!%!2!29!=!=vM6!!1c&kk** ' 'q	!--eZ@@
..z::,,.."&"2"25:L"M"M"&"2"25/"J"J&t$$V,,,1c&kk** ' 'q	!--eW==
..z::,,.."&"2"25&"A"A"&"2"25("C"C&t$$V,,,r  c                 L   |                                  }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |                     |d          }|                     |d          }t          j        ||          |d<   |S )	Nr  r  r  
totalAssettotalborrowedinterestdebt)r   r?  r1   r  )r  r   r   r
  r	  s        r
  r  zmexc.parse_balance_helper  s    ,,..**5(;;**5&99++E<@@z22##E:66!,T8<<r  c                   K   |                                   d{V  d}i }|                     dd|          \  }}|                     |d          }|                     |dd          }|                     |ddg          }d}||s|dk    rd}|                     |d          }|A|                     |d          }	|	(d                    |                     |	                    }n|                     |          }
|
d	         }| 	                    d|d
           d}||d<   |                     |ddg          }| 
                    |                     ||                     d{V }n|dk    r0|                     |                     ||                     d{V }nM|dk    r0|                     |                     ||                     d{V }nt          | j        dz             |                     ||          S )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_   r[  rC   Fr\  r[  r  r6   zsymbol or symbolsrB   rD   z' fetchBalance() not support self method)r  r  r?  rC  r  r  r  
market_idsr~  check_required_argument#spotPrivateGetMarginIsolatedAccountr  r  r  r-   r6   r  )r  r  r  r  r[  isMarginr!  parsedSymbolsr\  r[  r~  s              r
  fetch_balancezmexc.fetch_balance  sG      !!!!!!!!!
!??PTV\]]
F%%fl;;
>>&(E::6Hl#;<<""jH6L6L M%%fh77F~//&)<<&$'HHT__W-E-E$F$FMV,, &t((H[\\\!J!.GIYYv)'<==F!EEdkkRY[aFbFbccccccccHH6!!!77GV8T8TUUUUUUUUHH6!!!AA$++gW]B^B^________HHtw)RRSSSj ((:>>>r  c                 "  K   |t          | j        dz             |                                  d{V  |                     |          }d}|                     d||          \  }}d|d         i}d}|dk    rq|||d<   |||d<   |                     |d	          }	|	|                     |d	          }|	|d
<   |                     |                     ||                     d{V }n|A||d<   |                     |d          }
|
$| 	                    || j
        d                   |d<   |||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||||          S )a  
        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\  r6   rB   r  rl  r  r  r  r  rR  r  r  )r'   r6   r  r~  r  r  r  spotPrivateGetMyTradesr  r  r  %contractPrivateGetOrderListOrderDealsr  r  )r  r\  r  rl  r  r~  r  r  r   r  r  r!  s               r
  fetch_my_tradeszmexc.fetch_my_trades   s      >#DG.[$[\\\!!!!!!!!!V$$
!??QWY_``
FfTl
  ',$ #( %%fg66E 6733%*	"66t{{7F7S7STTTTTTTTFF.  (-%''
;;;*.((5$,GW:X*Y*YGJ' ',$!GGT[]cHdHdeeeeeeeeH0 __Xv66F  >>>r  c                 ,  K   |                                   d{V  i }d}||                     |          }|                     d||          \  }}	d}
|dk    rY|t          | j        dz             |d         |d<   ||d<   |                     |                     ||	                     d{V }
nJ||d<   |                     |                     ||	                     d{V }|                     |d	          }
| 	                    |
||||	          S )
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   rB   z. fetchOrderTrades() requires a symbol argumentr6   r\  r  rz  r  )
r  r~  r  r'   r6   r  r  )contractPrivateGetOrderDealDetailsOrderIdr  r  )r  r6   r\  r  rl  r  r  r~  r  r   r   r!  s               r
  fetch_order_tradeszmexc.fetch_order_tradesz  sV      !!!!!!!!![[((F >>?QSY[abb
E~'2b(bccc &tGH!#GI66t{{7E7R7RSSSSSSSSFF. #%GJ!KKDKKX_afLgLghhhhhhhhH0 __Xv66F  uEEEr  c                   K   |                      |d          }|t          | j        dz             |                                  d {V  |||d}|                     |                     ||                     d {V }|S )N
positionIdz5 modifyMarginHelper() requires a positionId parameter)r  r8  r;  )r  r'   r6   r  'contractPrivatePostPositionChangeMarginr  )r  r\  r8  addOrReducer  r  r  r!  s           r
  modify_margin_helperzmexc.modify_margin_helper  s      &&v|<<
#DG.e$efff!!!!!!!!!$
 

 EEdkkRY[aFbFbcccccccc r  c                 B   K   |                      ||d|           d{V S )a  
        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=margin-structure>`
        SUBNr  r  r\  r8  r  s       r
  reduce_marginzmexc.reduce_margin  4       ..vvufMMMMMMMMMr  c                 B   K   |                      ||d|           d{V S )a  
        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=margin-structure>`
        ADDNr   r!  s       r
  
add_marginzmexc.add_margin  r#  r  re  c                   K   |                                   d{V  d|i}|                     |d          }|x|                     |d          }|                     |d          }||                     |          nd}|||t	          | j        dz             ||d<   |d         |d<   ||d<   n||d<   |                     |                     ||                     d{V S )	at  
        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
        Nre  r  r`  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 positionsr6   r\  )r  r  rD  r~  r'   r6   )contractPrivatePostPositionChangeLeverager  )	r  re  r\  r  r  r  r`  r(  r~  s	            r
  set_leveragezmexc.set_leverage  s3      !!!!!!!!!
 &&v|<<
''
;;H++FNCCL-3-?T[[(((dF l&:'  3V  )V  W  W  W&.
#$*4L!*6''$.GL!CCDKKPWY_D`D`aaaaaaaaar  c                   K   |                                   d{V  d}i }| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	g }
t          dt          |	                    D ]x}|	|         }|                     |d          }|
                    ||d|| 	                    |          | 
                    |d          | 
                    |d	          d
           y|
S )aW  
        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>`
        Nr6   r\  r  r  
resultListr   
settleTimefunding)r  r\  r:  r  r  r6   r8  )r  r~  (contractPrivateGetPositionFundingRecordsr  r  r>  r  r  r|  r  rD  )r  r\  r  rl  r  r~  r  r!  r  r,  rF  rG  r   r  s                 r
  fetch_funding_historyzmexc.fetch_funding_history  s      !!!!!!!!!
 [[((F &tGH#(GK FFt{{SZ\bGcGcddddddddB x44__T<<<
q#j//** 	 	AqME))%>>IMM & LL33&&ud33**5)<<      r  c                    |                      |dd          }|                     |d          }|                     |d          }|                     ||d d          }|                     |d          }|                     |d          }d }	||dz   }	i d	|d|d
d dd dd dd d|d|                     |          d|d|d|                     |          dd dd dd dd dd dd d|	iS )NfundingRateratenextSettleTimer\  r   r  collectCyclehr  	markPrice
indexPriceinterestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )rN  r  r?  r  r  )
r  r   r~  r=  r>  r  r\  r  r  intervalStrings
             r
  parse_funding_ratezmexc.parse_funding_rate\  s   ( ,,X}fMM#00;KLL##Hh77!!(FD*EE%%h<<	##Hn==%^N
H
f
 
 $	

 D
 #D
 
 Y//
 ?
  4
 t||,@AA
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 
 	
r  c                 >   K   |                      ||           d{V S )a~  
        fetch the current funding rate interval

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        N)fetch_funding_rate)r  r\  r  s      r
  fetch_funding_intervalzmexc.fetch_funding_interval  s0       ,,VV<<<<<<<<<r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )au  
        fetch the current funding rate

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        Nr\  r6   r  )r  r~  "contractPublicGetFundingRateSymbolr  r  rD  )r  r\  r  r~  r  r!  rF  s          r
  rF  zmexc.fetch_funding_rate  s       !!!!!!!!!V$$fTl
 @@WV\A]A]^^^^^^^^  6266&&vv666r  c           
      2  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |d          }|                     |dg           }	g }
t          dt          |	                    D ]}|	|         }| 	                    |d          }| 
                    |          }|                     |d	          }|
                    |||                     |d
          ||                     |          d           |                     |
d          }|                     ||d         ||          S )ab  
        fetches historical funding rate prices

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

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not used by mexc, but filtered internally by ccxt
        :param int [limit]: mexc limit is page_size default 20, maximum is 100
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr\  r6   r  r  r,  r   r-  r2  )r  r\  r2  r  r  r  )r'   r6   r  r~  #contractPublicGetFundingRateHistoryr  r  r>  r  r?  r  r  r|  rD  r  sort_byfilter_by_symbol_since_limit)r  r\  r  rl  r  r~  r  r!  r  rF  ratesrG  r   r  symbolInnerr  sorteds                    r
  fetch_funding_rate_historyzmexc.fetch_funding_rate_history  s      >#DG.e$efff!!!!!!!!!V$$fTl

 #(GK AA$++gW]B^B^________2 x00|R88q#f++&& 	 	A1IE''x88H**844K))%>>ILL%#//}EE& LL33      e[11009I5RWXXXr  c                    K   |                                   d{V  |                     |ddd          }|                     |           d{V }|                     |d          }|                     ||d          S )a^  
        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
        NrD   Tr  r\  )r  market_symbolsr  r  parse_leverage_tiersr  r[  r  r!  r  s        r
  fetch_leverage_tierszmexc.fetch_leverage_tiers  s       !!!!!!!!!%%gvtTBB55f========\ ~~h//((wAAAr  c                 ~   |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }	d}
g }|                      |d	          }|dk    rId
|                     ||d d          |                     |          d d d |                     |d          |dgS t	          j        |
|          r#t	          j        |
|          }|                    |                     t	          j	        ||                    |                     ||d d          |                     |          |                     |
          |                     |          |                     |          |                     t	          j	        d|                    |d           t	          j        ||	          }t	          j        ||          }|}
t	          j        |
|          #|S )Nr\  maintenanceMarginRateinitialMarginRater  riskIncrVolriskIncrMmrriskIncrImrr  r  r   r   r  )tierr\  rH  minNotionalmaxNotionalrX  r  r  r`  )
r?  r  r@  rD  r1   	string_ltr  r|  r  
string_div)r  r  r~  r  rX  rY  r  rZ  r[  r\  floortiersrj  caps                 r
  parse_market_leverage_tiersz mexc.parse_market_leverage_tiers;  sX   N ##D(33 $ 0 07N O O ,,T3FGG!!$11&&t];;&&t];;&&t];;""455# "..xzRR $ 7 7 @ @#'#'-1#'#3#3D-#H#H 	 	  v.. 	$UK88CLL))'*<S+*N*NOO**8VT:NN 33G<<#0077#0055)-):):;P)Q)Q#001CCIZ1[1[\\	 	 	 	 	 !( 23Dk R R$+$67Lk$Z$Z!E v.. 	 r  rH  c                    |                      |d          }|                      |d          }|                      |d          }||                     ||          |                     ||          ||                      |d          dS )Naddressr)  r+  memo)r  rH  r,  rg  tag)r?  r@  rB  )r  depositAddressrH  rg  r  rL  s         r
  parse_deposit_addresszmexc.parse_deposit_address  s     "">9==%%nf==
$$^Y??	"//
HEE..y*EE##NF;;
 
 	
r  r:  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |d          }d}||                     ||          }|                     |di           }||v rE|                     ||i           }	|                     |	di           }
|                     |
d          }n|                     ||          }|||d<   |                     |d          }|                     | 	                    ||                     d{V }| 
                    |dd          }|                     |d          S )a  
        fetch a dictionary of addresses for a currency, indexed by network

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

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `address structures <https://docs.ccxt.com/?id=address-structure>` indexed by the network
        Nr)  r6   r,  rO  r  F)r  rH  r?  rB  r  r  network_code_to_idr  #spotPrivateGetCapitalDepositAddressr  parse_deposit_addressesindex_by)r  r:  r  rH  r  networkCoderL  networkUnifiedrO  r,  networkInfor!  addressStructuress                r
  "fetch_deposit_addresses_by_networkz'mexc.fetch_deposit_addresses_by_network  s      !!!!!!!!!==&&HTN
 &&vy99	"!44[$GGN~~h
B??H))..>2FF"oogvrBB ,,[)DD		 33KFF	 !*GI69--AA$++gW]B^B^________ !884OO}}.	:::r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     |d          }|t          | j        dz             d}|                     ||          }|                     |di           }||v rE|                     ||i           }	|                     |	di           }
|                     |
d          }n|                     ||          }|||d<   | 	                    |d          }| 
                    |                     ||                     d{V }|                     ||          S )a  
        create a currency deposit address

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

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network name
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr)  r6   r,  z4 createDepositAddress requires a `network` parameterrO  r  )r  rH  r?  r'   r6   rB  r  r  rm  r  $spotPrivatePostCapitalDepositAddressr  rk  )r  r:  r  rH  r  rq  rL  rr  rO  r,  rs  r!  s               r
  create_deposit_addresszmexc.create_deposit_address  s      !!!!!!!!!==&&HTN
 &&vy99#DG.d$deee	00dCC>>(J;;X%%nnX~rBBG//'62>>K((i@@II//TBBI !*GI69--BB4;;wX^C_C_```````` ))(H===r  c                 D  K   |                      |d          }|                     ||           d{V }d}|+|                     ||                     ||                    }n|                     | j        d          }|                      ||          }||                     ||          }nMt          |                                          }|                      |d          }	|                     ||	          }|#t          | j        dz   |z   dz   |z   dz             |S )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,  NrN  r   z9 fetchDepositAddress() cannot find a deposit address for z, and networkzMconsider creating one using .createDepositAddress() method or in MEXC website)	r?  ru  r  rB  r  r  r  r+   r6   )
r  r:  r  r,  rt  rF  r  defaultNetworkForCurrencyr  keys
             r
  fetch_deposit_addresszmexc.fetch_deposit_address  sS      ""6955"&"I"I$PV"W"WWWWWWW^^$5t7N7NwX\7]7]^^FFnnT\3DEEG(,(8(8$(G(G%(4(9;TUU-224455&&tQ//(93??> +f!fim!mp!  CJ  "J  M\  "\  ]  ]  ]r  c                   K   |                                   d{V  i }d}|_|                     |          }|d         |d<   |                     |d          }|'|                     |d          }|d         dz   |z   |d<   |||d<   ||dk    rt	          d          ||d	<   |                     |                     ||                     d{V }|                     ||||          S )
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>`
        Nr6   r)  r,  -r  rq  .This exchange supports a maximum limit of 1000rl  )r  rH  r?  r  r#   "spotPrivateGetCapitalDepositHisrecr  parse_transactions)	r  r:  r  rl  r  r  rH  
rawNetworkr!  s	            r
  fetch_depositszmexc.fetch_deposits  s-      !!!!!!!!!
 }}T**H&tnGFO ))&)<<J%6955")&/C"7*"D#(GK t||#$TUUU$GG@@WV\A]A]^^^^^^^^( &&x5%HHHr  c                 Z  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   ||dk    rt          d          ||d<   |                     |                     ||                     d{V }|                     ||||          S )a0  
        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>`
        Nr6   r)  r  rq  r  rl  )r  rH  r#   $spotPrivateGetCapitalWithdrawHistoryr  r  )r  r:  r  rl  r  r  rH  r!  s           r
  fetch_withdrawalszmexc.fetch_withdrawalsK  s       !!!!!!!!!
 }}T**H&tnGFO#(GK t||#$TUUU$GGBB4;;wX^C_C_````````0 &&x5%HHHr  transactionc                    |                      |dd          }|dnd}|                     |dd          }|                     |d          }d }|                     |d          }||                    d	          d
         }d }	|                     |d          }
|
|                     |
          }	|                     ||          }|                     |                     |d          |          }|                     |d          }|                     |d          }|                      |dd          }d }|                     |d          }||                     |          |d}|dk    rt          j
        ||          }i d|d|d|d|d|                     |          d|	d|d|dd d|                     |d          dd dd d|d|                     |          d|d|d||                     |d           d |d!S )"Nr6   tranIdr\   
withdrawal
insertTime	applyTimer  r)  r~  r   r,  r  r8  rg  	transHashtxIdtransactionFeer  r  txidr  r  	addressToaddressFromri  rh  tagTotagFromr;  rH  r  remark)commentinternalr5  )rA  r  r  r?  splitrB  r@   parse_transaction_status_by_typer  r1   
string_subr  )r  r  rH  r6   r;  r  r  r  currencyWithNetworkr,  r  r:  r  r  rg  r  r5  feeCostStrings                     r
  parse_transactionzmexc.parse_transaction  s   l T8<<Zyyl''\;OO	##K>>
"..{FCC*,22377:J%%k9==
!--j99G&&z8<<66t7G7GU]7^7^`dee''X>>"";	::!!+{FCC((6FGG$))-88  C <"-lMJJL
K
"
 D
 	

 Y//
 w
 w
 
 4
 4##K88
 T
 t
 D
 d''55
 
  f!
" w#
$ ''X>>)
 
 
 	
r  c                     ddddddddddddddddddd
d}|                      ||i           }|                     |||          S )Nfailedpendingr  )r`  r  r  r  567r  )
r`  r  r  r  r  r  r  8910)r\   r  )r  r?  )r  r  r;  statusesByTyper  s        r
  r  z%mexc.parse_transaction_status_by_type  s         
  
. ??>4<<&&999r  c                   K   |                                   d{V  |                     |          }d|d         i}|                     d|                     ||                     d{V }|                     |d          S )a  
        fetch data on a single open contract trade position

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

        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr\  r6   r   )r  r~  fetch_positionsr  r  )r  r\  r  r~  r  r!  s         r
  fetch_positionzmexc.fetch_position  s       !!!!!!!!!V$$fTl
 --dDKK4P4PQQQQQQQQx+++r  c                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     ||          S )a  
        fetch all open positions

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

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr  )r  'contractPrivateGetPositionOpenPositionsr  parse_positionsrU  s        r
  r  zmexc.fetch_positions  s~       !!!!!!!!!EEfMMMMMMMM> ~~h33##D'222r  positionc                 4   |                      |                     |d          |d d          }|d         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|dk    rdnd	}|                     |d
          }	|	dk    rdnd}
|                     |d          }|                     |d          }|                     |d          }|                     i d|dd d|d|                     |          dd d|dd d|dd d|                     |          dd d|
dd dd dd d|d|                     |          d d d d ||                     |          d d d d d
          S ) Nr\  rD   holdVolopenAvgPriceimr(  r`  longshortmargin_moderH  r_  re  liquidatePricer  r  r6   	contractsru  
entryPrice
collateralr  unrealizedPnlr  r[  notionalr7  r"  liquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  r  rc  r_  r`  r  )r  r?  rD  r  safe_positionr  r  )r  r  r~  r\  r  r  r  rawSider  r`  
marginTypere  r  r  s                 r
  parse_positionzmexc.parse_positionE  sQ   z !!$"2"28X"F"FPTV\]]!$$Xy99	%%h??
((488""8^<<!S..vvw##Hm<<$,OOZZ'
##Hj99++H6FGG%%h==	!! #
H#
$#
 f#
 **955	#

 D#
 *#
 $#
 D#
 T#
 ))(33#
 $#
 *#
 #
 #
 #
   0!#
" T..}==##
$ (,!%+/"Y//!##'7#
 #
 #
   	r  c                 |  K   |                      dd|          \  }}|                                  d{V  |dk    r_d|i}|                     |                     ||                     d{V }|                     |di           }|                     |          S |dk    rt          | j        dz   |z             dS )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   NrB   transact_idr  rD   z& fetchTransfer() is not supported for )r  r  )spotPrivateGetAssetInternalTransferRecordr  r  parse_transferr(   r6   )	r  r6   r:  r  r  r   r  r!  r  s	            r
  fetch_transferzmexc.fetch_transfer  s       !>>PTV\]]
E!!!!!!!!!rG "KKDKKX_afLgLghhhhhhhhH >>(FB77D&&t,,,6!!TW'OOR\\]]]tr  c                   K   d}|                      dd|          \  }}|                                  d{V  i }d}||                     |          }d}|                     |dd          \  }}dddddd}	||                     |	||          |d<   nt          | j        dz             d}
|                     |dd          \  }
}|
|                     |	|
|
          |d<   nt          | j        d	z             g }|d
k    rj|||d<   ||dk    rt          d          ||d<   |                     | 	                    ||                     d{V }| 
                    |dg           }nh|dk    rb|||d<   |                     | 	                    ||                     d{V }|                     |d          }|                     |d          }|                     ||||          S )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)rB   rD   futuresrE   rC   zP fetchTransfers() requires a fromAccountType parameter, one of "SPOT", "FUTURES"toAccountTypezN fetchTransfers() requires a toAccountType parameter, one of "SPOT", "FUTURES"rB   r  r   z,This exchange supports a maximum limit of 50sizerowsrD   r  r  r,  )r  r  rH  r  r?  r'   r6   r#   spotPrivateGetCapitalTransferr  r  'contractPrivateGetAccountTransferRecordr  parse_transfers)r  r:  r  rl  r  r  r  rH  r  accountTypesr  r,  r!  r  s                 r
  fetch_transferszmexc.fetch_transfers  s       
!??@PRVX^__
F!!!!!!!!!}}T**H"&"?"?HXZk"l"l 
 
 &)-)9)9,Yh)i)iG%&&#DG  /A  %A  B  B  B $ = =fFVXg h hv$'+'7'7mUb'c'cGO$$#DG.~$~
 ',$ 3;;'(VWWW"'!??GU[@\@\]]]]]]]]H& &"==JJ6!! ',$!II$++V]_eJfJfggggggggH??8V44D|<<J2 ##J%GGGr  fromAccount	toAccountc                   K   |                                   d{V  |                     |          }dddd}|                     |||          }|                     |||          }	|Nt          |                                          }
t          | j        dz   d                    |
          z             |	Nt          |                                          }
t          | j        dz   d                    |
          z             |d         |||	d	}|d
k    s|	d
k    re|                     |d          }|                     |d          }|t          | j        dz             | 
                    |          }|d         |d<   |                     |                     ||                     d{V }|                     ||          }|                     ||||d          S )a  
        transfer currency internally between wallets on the same account

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

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.symbol]: market symbol required for margin account transfers eg:BTCUSDT
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        Nr  r  )rB   rD   rE   z fromAccount must be one of z, z toAccount must be one of r6   )r  r8  r  r  ISOLATED_MARGINr\  z: transfer() requires a symbol argument for isolated margin)r8  r  r  )r  rH  r?  r  r  r#   r6   r  r  r'   r~  spotPrivatePostCapitalTransferr  r  )r  r:  r8  r  r  r  rH  accountsfromIdtoIdr  r  r\  r~  r!  r  s                   r
  r   zmexc.transfer7  s      !!!!!!!!!==&&
 

 !!(KEE)Y??>((D*H H499UY?? Z[[[<((D*F FSW XYYYd^%!	
 
 '''T5F-F-F%%fh77FYYvx00F~'2n(nooo[[((F &tGH<<T[[RX=Y=YZZZZZZZZ ))(H=={{;&")
 )
   	r  r   c                    |                      |dd          }|                     |g d          }|                     |dd          }||                     |          nd }|                     |d          }d }d }	|                     |d          }
|                     |d          }|
||
}|}	nC||d	k    rd
nd}|d	k    rdnd
}	n,|                     |d          }|                     |d          }	|||||                     ||          |                     |d          |                     |          |                     |	          |                     |                     |g d                    d	S )NrH  r  )r  r  r  r  r  r;  r  r  INMAINCONTRACTfromtor8  )transact_stater  r  )	r  r6   r  r  rH  r8  r  r  r  )	rA  safe_string_nr  r  r?  r@  rD  parse_account_idparse_transfer_status)r  r   rH  r  r6   r  r  	directionaccountFrom	accountTor  r  s               r
  r  zmexc.parse_transfern  s   V ''*gFF
*K*K*KLL'',LL	/8/D4<<	***4$$Xv66		**85FGG((?CC'm.G)K%II"%.$%6%6&&ZK'0D'8'8

vII**8V<<K((488I" //
HEE&&x::00==..y99001C1CHNsNsNs1t1tuu

 

 
	
r  c                 >    ddddd}|                      |||          S )NrB   rD   )r  r  r  r  r  r  s      r
  r  zmexc.parse_account_id  s4    	
 
 &&999r  c                 <    dddd}|                      |||          S )Nr  r  r  )SUCCESSFAILEDWAITr  r  s      r
  r  zmexc.parse_transfer_status  s1    
 

 &&999r  rg  ri  c                   K   |                                   d{V  |                     |          }|                     ||          \  }}|                     |dd          }|r|                     |d          }|d         ||d}|                     |d          }	|	t          | j        dz             |                     | 	                    ||                     d{V }
| 
                    |
|          S |                     | j        di           }|                     |d	d
          }|                     |||          }|                     ||d                   }|                     |           |d         ||d}|||d<   |||d
<   |                     |d	d
g          }|                     | 	                    ||                     d{V }| 
                    ||          S )a  
        make a withdrawal

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

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.internal]: False by default, set to True for an "internal transfer"
        :param dict [params.toAccountType]: skipped by default, set to 'EMAIL|UID|MOBILE' when making an "internal transfer"
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        Nr  Fr6   )r  r8  r  r  zc withdraw() requires a toAccountType parameter for internal transfer to be of: EMAIL | UID | MOBILErO  r,  r+  r:  )r)  rg  r8  rh  )r  rH  handle_withdraw_tag_and_paramsrC  r  r?  r'   r6   &spotPrivatePostCapitalTransferInternalr  r  r  r  rA  rm  check_addressspotPrivatePostCapitalWithdraw)r  r:  r8  rg  ri  r  rH  r  requestForInternalr  responseForInternalrO  r,  r  r!  s                  r
  r   zmexc.withdraw  sE       !!!!!!!!!==&&99#vFFV>>&*e<< 	IYYvz22F!$ $" "
 !,,V_EEM$'  3X  )X  Y  Y  Y(,(S(STXT_T_`rtzT{T{(|(|"|"|"|"|"|"| ))*=xHHH>>$,
B??$$VY	BB""8Wg>>))'8F3CDD7###TN
 

 ?!GFO!(GIYYv	9'=>>F<<T[[RX=Y=YZZZZZZZZ %%h999r  rc  c                 x   K   d|rdndi}|                      |                     ||                     d{V }|S )a  
        set hedged to True or False for a market

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

        :param bool hedged: set to True to use dualSidePosition
        :param str symbol: not used by mexc setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        r  r   r   N)-contractPrivatePostPositionChangePositionModer  )r  rc  r\  r  r  r!  s         r
  set_position_modezmexc.set_position_mode  s[       .AAQ
 KKDKKX_agLhLhiiiiiiii r  c                 z   K   |                      |           d{V }|                     |d          }||dk    d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
        Nr  r   )r  rc  )&contractPrivateGetPositionPositionModer  )r  r\  r  r!  r  s        r
  fetch_position_modezmexc.fetch_position_mode  s^       DDVLLLLLLLL ((6::#q(
 
 	
r  codesc                    K   |                                   d{V  |                     |           d{V }|                     ||          S )  
        fetch deposit and withdrawal fees

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

        :param str[]|None codes: returns fees for all currencies if None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `fee structures <https://docs.ccxt.com/?id=fee-structure>`
        N)r  r=  parse_transaction_feesr  r  r  r!  s       r
  fetch_transaction_feeszmexc.fetch_transaction_fees3  si       !!!!!!!!!??GGGGGGGG< **8U;;;r  c                 F   i }t          dt          |                    D ]|}||         }|                     |d          }|                     |          }|                     |d          }||                     ||          r|                     ||          ||<   }|i |dS )Nr   r)  r:  )r   r\   r  )r>  r  r?  safe_currencyin_arrayparse_transaction_fee)	r  r!  r  withdrawFeesrG  r   r  rH  r:  s	            r
  r  zmexc.parse_transaction_fees^  s    q#h--(( 	Q 	QAQKE))%88J))*55H##Hf55D4==u#=#=%)%?%?x%P%PT"$
 
 	
r  c                 .   |                      |dg           }i }t          dt          |                    D ]]}||         }|                     |d          }|                     | j        d         ||          }|                     |d          }	|	||<   ^|S )Nr*  r   r,  rO  r/  )r  r>  r  r?  r  rD  )
r  r  rH  r*  rF  rJ  networkEntryrL  rq  r5  s
             r
  r  zmexc.parse_transaction_feem  s    6 ook="EEq#k**++ 	& 	&A&q>L((yAAI**4<
+CYPYZZK""<??C"%F;r  c                    K   |                                   d{V  |                     |           d{V }|                     ||d          S )r  Nr)  )r  r=  parse_deposit_withdraw_feesr  s       r
  fetch_deposit_withdraw_feesz mexc.fetch_deposit_withdraw_fees  sk       !!!!!!!!!??GGGGGGGG< //%HHHr  c                    |                      |dg           }|                     |          }t          dt          |                    D ]r}||         }|                     |d          }|                     ||                     |d                    }|                     |d          d dd d dd|d         |<   s|                     |          S )	Nr*  r   r,  r:  r/  )r5  r  )r   r\   rO  )r  deposit_withdraw_feer>  r  r?  rB  rD  $assign_default_deposit_withdraw_fees)	r  r5  rH  r*  rF  rJ  r  rL  rq  s	            r
  parse_deposit_withdraw_feezmexc.parse_deposit_withdraw_fee  s    6 ooc="==**3//q#k**++ 	 	A&q>L((yAAI11)T=M=MhX^=_=_``K  ++L-HH"& 
  "& 	/ 	/F:{++ 88@@@r  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     ||          S )ae  
        fetch the set leverage for a market

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

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        Nr\  r6   r  )r  r~  "contractPrivateGetPositionLeverager  r  parse_leverager  s          r
  fetch_leveragezmexc.fetch_leverage  s       !!!!!!!!!V$$fTl
 @@WV\A]A]^^^^^^^^> ~~h33""4000r  c                 X   d }d }d }t          dt          |                    D ]y}||         }|                     |d          }|                     |d          }	|	dk    r|                     |d          }n|	dk    r|                     |d          }|dk    rdnd}z||d	         |||d
S )Nr   r`  r(  r   re  r   rH  r_  r\  )r  r\  r[  longLeverageshortLeverage)r>  r  r  )
r  re  r~  r[  r  r  rG  r   r`  r(  s
             r
  r  zmexc.parse_leverage  s    
q#h--(( 	D 	DAQKE((
;;H,,UNCCLq  #00
CC"" $ 1 1% D D(0AGJJX&$(*
 
 	
r  c                     |                      | j        d          }|                     |dd          }d}t          t          |                               |||          \  }}|dk    s|du rd}||gS )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
        rL  rC   FNTrH  )r?  r  rC  r  r3   r@  )r  
methodNamer  defaultValuerL  r  r[  r	  s          r
  r@  z"mexc.handle_margin_mode_and_params0  s     &&t|]CC>>&(E::
"4..LLZY_amnn
F8##T)9)9#JF##r  c                   K   |                                   d{V  i }|;t          |          }|dk    r&|                     |d                   }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |d          }	|                     |	||          }
|                     |
||          S )u  
        fetches historical positions

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

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

 EXCHANGE SPECIFIC PARAMETERS
        :param int [params.type]: position type，1: long, 2: short
        :param int [params.page_num]: current page number, default is 1
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/?id=position-structure>`
        Nr   r   r6   r\  r  r  )r  r  r~  .contractPrivateGetPositionListHistoryPositionsr  r  r  filter_by_since_limit)r  r[  r  rl  r  r  symbolsLengthr~  r!  r  	positionss              r
  fetch_positions_historyzmexc.fetch_positions_history@  s        !!!!!!!!!LLM!!WQZ00$*4L!#(GK LLT[[Y`bhMiMijjjjjjjjR ~~h//((w??	)))UEBBBr  r[  c                   K   |                                   d{V  |                     |          }|d         rt          | j        dz             |                                }|dk    r|dk    rt          | j        dz             |                     |d          }|t          | j        dz             |                     |d	d
          }||dk    rdndd}||d         |d<   ||dk    rdnd|d<   | 	                    |d	          }| 
                    |                     ||                     d{V }|                     ||          S )aM  
        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
        NrB   z/ setMarginMode() supports contract markets onlyrH  r_  z@ setMarginMode() marginMode argument should be isolated or crossre  z. setMarginMode() requires a leverage parameterr  r  r   r   )re  r`  r6   r\  r  r(  )r  r~  r)   r6   lowerr(   r  r'   safe_string_lower_2r  r)  r  r  )	r  r[  r\  r  r~  re  r  r  r!  s	            r
  set_margin_modezmexc.set_margin_mode  s      !!!!!!!!!V$$&> 	YDG&WWXXX%%''
##
g(=(=TW'iijjj$$VZ88#DG.^$^___,,V[,OO	 (J66Q
 
  &tGH ,5,@,@aaqGN#6;//GGT[]cHdHdeeeeeeee ""8V444r  c                 d    |                                  |                     | j        dd          z
  S )NrI  r   )r  r  r  )r  s    r
  r  z
mexc.nonce  s/      ""T%6%6t|EUWX%Y%YYYr  r   GETc                 f   |                      |d          }|                      |d          }|                     ||          \  }}d }	|dk    s|dk    r|dk    r | j        d         |         |         dz   |z   }	n*| j        d         |         |         dz   | j        z   dz   |z   }	|}
|dk    r|dk    rY|d	k    s|d
k    s|dk    rG|                                 |                     | j        dd          d}
|                     |          }n6|                                 |
d<   |                     | j        dd          |
d<   d}|
r|                     |
          }|	d|z   z  }	|dk    r| 	                                 | 
                    |                     |          |                     | j                  t          j                  }|	d|z   z  }	| j        |                      | j        dd          d}|d	k    s|d
k    s|dk    rd|d<   n|dk    s|dk    r| j        d         |         |         dz   |                     ||          z   }	|                     ||                     |                    }|dk    r|r|	d|                     |          z   z  }	n| 	                                 t'          |                                           }d}| j        |d|                      | j        dd          d}|d	k    r|                     |          }|}n7|                     |          }|r ||                     |          z  }|	d|z   z  }	| j        |z   |z   }| 
                    |                     |          |                     | j                  t          j                  }||d<   |	|||dS )Nr   r   rB   r   r   re  z/api/r   POSTPUTDELETErQ  rF  )r  rQ  r  r  ?z&signature=rG  )zX-MEXC-APIKEYsourcezapplication/jsonContent-Typer   r   r   )ApiKeyzRequest-Timer/  r.  	Signature)r  r  bodyheaders)r?  resolve_pathr   r<   r  r  r  r  	urlencoder<  hmacencodesecrethashlibsha256apiKeyimplode_paramsr  extract_paramsr  keysort)r  pathr   r  r  r3  r2  sectionaccessr  	urlParamsparamsEncoded	signaturer  auths                  r
  signz	mexc.sign  s   ""3**!!#q))((v66ff8 3 3(""i&w/7#=Di&w/7'ADLPSVVY]]I""h&&Vv-=-=6U??X^bjXjXj%)ZZ\\&*&7&7lTX&Y&Y! !I  99V,,DD-1ZZ\\Ik*.2.?.?l\`.a.aIl+M + $y 9 9s]**""//111 IIdkk-&@&@$++dkBZBZ\c\jkk	)I55%)["..t|XvNN  &  foo6X;M;M*<'
""g&8&8)E"7+F3c9D<O<OPTV\<]<]]CYYvt':':4'@'@AAF!! 83!7!777C//111

--	"k$-$6"..t|XvNN	  V##99V,,DDD!\\&11F *v 6 66sTz){Y.5 IIdkk$&7&7T[9Q9QSZSabb	'0$fdwOOOr  reasonr  r  r3  r2  c
                 R   |d S |                      |dd          }
|
du rd S |                     |dd           }|l|dk    rf|dk    r`| j        dz   |z   }|                     | j        d         ||           |                     | j        d	         ||           t          |          d S )
Nr  FTr:  200r   r  r  )rC  r?  r6   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr#   )r  r:  rG  r  r  r3  r2  r!  requestHeadersrequestBodyr  responseCodefeedbacks                r
  handle_errorszmexc.handle_errors  s    4 ..9e<<d??4''&$??$<5+@+@|WZGZGZw}t+H001I4QYZZZ001I<Yabbb)))tr  )r   r   r   )N)__name__
__module____qualname__r   r  r#  r   r'  r   rM  r"   r   rY  rP  rQ  r  r   r  r   r  r   r  dictr  r  r  r  r   r   r  r   r
  r	  r5  ri  r<  r>  r   r   r   r9  rX  rA  rB  r   rw  r   r~  r   r  r  r  r  r  r  r  r  r  r]  r  r  r  r  r  r  r   r  r   r  r   r  r  r  r  r  r  r   r"  r&  intr*  r0  r   rD  rG  rF  rQ  r   rV  r   re  r	   r
   rk  ru  rx  r|  r    r  r  r  r  r  r   r  r  r!   r  r  r   r  r  r  r   boolr  r  r  r  r  r  r  r   r  r  r@  r"  r&  r  rF  rQ  __classcell__)r	  s   @r
  r3   r3      s       G# G G G G G GR )+ #
 #
 #
 #
J ')  S    4 -/ e e: e e e eN *, 9 9V 9 9 9 9" /1 z z z zx /1 z z z zx @DB > >S > >S\ > > > >@ i 	 en     <@d[] ]? ]? ]?S ]? ]?bfglbm ]? ]? ]? ]?~H H Hv H H H H HT ?CQUdhqs eK eK eK eK3 eK^a eKx|  ~B  yC eK eK eK eKN
 
 
4 
 
 
 
 6:" S4 S47 S4 S4 S4 S4 S4j 68 G1 G1 G1F G1 G1 G1 G1Ro o4 o o6 o o o ob 8<B %4 %4W %4 %4 %4 %4N XZ c cc c c c c c( Y[ d ds d% d d d d( mqy{ "f "f "fI "fY "fX] "ffi "f "f "f "fH KO[_hj -, -, -, -,^ IMY]fh 4 4 4 4l IMY]fh |5 |5 |5 |5| FH 9+ 9+$|*< 9+ 9+ 9+ 9+v 8<B s. s.C s. s. s. s. s.j 04$UYbd sK sK sKC sKs sKimnsit sK sK sK sKj <@ 03 03S 03 03 03 03d 59tZ^gi TU TUc TU TUTW TUnrsxny TU TU TU TUl 7;\`ik Q Q Q3 QVY Qptuzp{ Q Q Q Q  9=4^bkm Q Q# QS QX[ Q Q Q Q  @DRVeirt _ _ _C __b _ _ _ _ 9=R i. i.S i.# i. i. i. i.V AER  3  3tCy  3#  3  3  3  3D 59 V3 V3c V3 V3 V3 V3p_ _ _v _ _ _ _ _B: : :	: 	: 	:: : : : : : : :@ @S @ @ @ @4 4 4l +-  g    8 ;= %
 %
c %
AT %
 %
 %
 %
Nf-H f- f- f- f-P   *, }? }? }? }? }? }?~ 37TX\eg X? X?C X?s X?RU X? X? X? X?t ?CQUdhqs KF KF3 KF KF3 KF^a KF KF KF KFZ SU      $ FH N N# Nu NL^ N N N N CE N Ns NE NI[ N N N N ?C2 b b3 b b b b b< 9=4^bkm I I# IS IX[ I I I IV0
 0
6 0
[ 0
 0
 0
 0
d @B 
= 
=3 
=k 
= 
= 
= 
= <>  7  7s  7+  7  7  7  7D >BPTcgpr @Y @Ys @Y# @Y]` @Y @Y @Y @YD =A ;B ;B' ;BP] ;B ;B ;B ;BzM M M$|J\ M M M M^
 
h 
R` 
 
 
 
( JL +; +;S +;PTUcPd +; +; +; +;Z >@ '> '> '>N '> '> '> '>R =?   >    : 04$UYbd 8I 8I 8IC 8Is 8Iimnyiz 8I 8I 8I 8It 37TX\eg 6I 6IC 6Is 6IRU 6Ilpq|l} 6I 6I 6I 6Ipf
 f
T f
X f
Q\ f
 f
 f
 f
P: : : :6 8: , ,3 , , , ,$ 8<B +3 +3W +34PX> +3 +3 +3 +3Ze et eV e e e eN 9=R # #s ## #M # # # #J 154VZce dH dH# dHS dHPS dHjno|j} dH dH dH dHL ac 5 53 5 5C 5TW 5gt 5 5 5 5nG
 G
t G
x G
= G
 G
 G
 G
R: : ::C :C : : : : QU]_ :: ::3 :: :: ::# ::do :: :: :: ::x CGr  d C    . 7;2 
 
 
 
 
 
0 =A )< )<' )< )< )< )<V
 
 
 
# #8 # # # #J BFb )I )Iw )I )I )I )IV+A +A +A +A +A +AZ 8: /1 /13 /1h /1 /1 /1 /1b
 
t 
V 
x 
 
 
 
* @BPT $ $ $ $ $ $  @DRVeirt DC DCW DCC DC_b DCy}  G  zH DC DC DC DCL DHPR %5 %5 %5S %5 %5 %5 %5NZ Z Z &eBSW >P >P >P >P@# s  c TX `c        r  r3   )9 ccxt.async_support.base.exchanger   ccxt.abstract.mexcr   rR  r9  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
  <module>ra     s   6 5 5 5 5 5 * * * * * *   U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U  U       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %i[ i[ i[ i[ i[8[ i[ i[ i[ i[ i[r  