
    !:h^                    x   d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl%m'Z' d dl%m(Z( d d	l%m)Z) d d
l%m*Z* d dl%m+Z+ d dl%m,Z, d dl%m-Z- d dl%m.Z. d dl%m/Z/ d dl%m0Z0 d dl%m1Z1 d dl%m2Z2 d dl3m4Z4 d dl5m6Z6  G d dee      Z7y)    )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ddZdd	d	i f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d-ed
e/fd.Z0d	d	d	i fd
e/dedede
e1   fd/Z2d	i fd
e/fd0Z3d	d	d	i fd
e/dedede
e1   fd1Z4d	d	d	i fd
e/dedede
e1   fd2Z5d	d	d	i fd
e/dedefd3Z6d	d	d	i fd
e/dedefd4Z7d	i fd-ed
e/fd5Z8d	i fd
e/fd6Z9d	i fd
e/fd7Z:dd8edede1fd9Z;d: Z<d; Z=d<e/fd=Z>d> Z?dd?e/fd@Z@dA ZAi fde
eB   fdBZCi fd
edeDfdCZEdeFfdDZGdE ZHi fdeFfdFZId	d	d	i fd
e/dedefdGZJd	d	d	i fd-ed
e/dedefdHZKi fd
efdIZLi fd
ed%e#deMfdJZNi fd
ed%e#deMfdKZOd	i fdLed
e/fdMZPd	d	d	i fd
e/dedefdNZQddedeRfdOZSi fd
edeRfdPZTi fd
edeRfdQZUd	d	d	i fd
e/dedefdRZVd	i fdedeWfdSZXddede
eY   fdTZZddUe[de\fdVZ]i fdWede
e\   fdXZ^i fdWede\fdYZ_i fdWede\fdZZ`d	d	d	i fdWe/dedede
ea   fd[Zbd	d	d	i fdWe/dedede
ea   fd\Zcdd]edUe[deafd^Zddd_Zei fd
efd`Zfd	i fdede
eg   fdaZhddbedefdcZid	i fd-edWe/dejfddZkd	d	d	i fdWe/dedede
ej   fdeZli fdWed%e#dfedgedejf
dhZmddiedUe[dejfdjZndk Zod<e/de/fdlZpd	i fdWed%e#dmedeafdnZqd	i fdoerd
e/fdpZsd	i fd
e/fdqZtd	i fdrefdsZuddtZvddUe[fduZwd	i fdrefdvZxddUe[fdwZyi fd
edezfdxZ{ddLededezfdyZ|i d	f fdz	Z}d	d	d	i fdededede
eg   fd{Z~d	i fd|ed
e/fd}Zd~ Zddi d	d	fdZdWedededededefdZ xZS )mexcreturnc                 b   | j                  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dddddddddddddddd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dddddddddd	i 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        ddddd ddddddd
dd	dd| j                  d
      | j                  d
      didddddddddddddiddd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/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAd/d/d/dBdCdDdEdFdGddddddddHddd dddddIddddddddJdKdLidddMd ddNdddddOdd ddddPddQdRdRddddSddQdRdRdRddddTdUdQidV	dWdXidXdddddHdddddddYd dddZdZd[d\diddddd]dddZdZddd^dddZd dZddd_dUd`ida	dWdbidWdbidd d ddcddi dedfdgdhdidjdkdldmdndodpdqdqdrdsdtdududtdvdwdxdydzdx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        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://contract.mexc.com/api/v1/contractz(https://contract.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exchangeInfodepthtradeshistoricalTrades	aggTradesklinesavgPricezticker/24hrzticker/pricezticker/bookTickerzetf/infoorder   
openOrders   	allOrdersaccountmyTradestradeFeesub-account/listsub-account/apiKeyzcapital/config/getallzcapital/deposit/hisreczcapital/withdraw/historyzcapital/withdraw/addresszcapital/deposit/addresszcapital/transferzcapital/transfer/tranIdzcapital/transfer/internalz%capital/sub-account/universalTransferzcapital/convertzcapital/convert/listzmargin/loanzmargin/allOrderszmargin/myTradesmargin/openOrderszmargin/maxTransferablezmargin/priceIndexmargin/orderzmargin/isolated/accountzmargin/maxBorrowablezmargin/repayzmargin/isolated/pairzmargin/forceLiquidationReczmargin/isolatedMarginDatazmargin/isolatedMarginTierzrebate/taxQuery)	zrebate/detailzrebate/detail/kickbackzrebate/referCodezrebate/affiliate/commissionzrebate/affiliate/withdrawz"rebate/affiliate/commission/detailmxDeduct/enableuserDataStreamselfSymbolsz
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/listzasset/internal/transfer/recordz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AVAXCAVAX_CCHAINACAACALABEP20BSCOPTIMISMOPASTRASTARBTMBTM2CRC20CRONOSETHFETFHRC20HECOOASISROSEOKCOKTRSKRBTC)zBNB Smart Chain(BEP20-RACAV1)zBNB Smart Chain(BEP20-RACAV2)zBNB Smart Chain(BEP20)  l   W CCXT)adjustForTimeDifferencetimeDifferenceunavailableContractsr   r   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      )rH  limitdaysBack	untilDayssymbolRequired)rH  triggerrQ  r]  )rH  rZ  r^  rQ  r]       )rH  rZ  r[  r\  r^  rQ  r]  )rH  rZ  r[  daysBackCanceledr\  r^  rQ  r]  rZ  )	sandboxrT   rU   r   r   r   r   ri   r   extendsdefault)rI  rK  rJ  rL  rM  rP  rR  rS  Z   )rH  rZ  r[  r\  rH  )rH  rZ  r^  rQ  )rH  rZ  r[  r\  r^  rQ  )rH  rZ  r[  ra  r\  r^  rQ    )	rc  rT   rU   r   r   r   r   ri   r   	forDerivs)rd  rB   rg  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)PROSSINSOUL
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60005700001700002700004700005700006700007700008700013730001730002730000730003730100730600)730601730602730700730701730702730703730704730705730706730707730101140001140002)z+Order quantity error, please try to modify.z*Combination of optional parameters invalidzapi market order is disabledzContract not allow place order!OversoldzInsufficient positionzInsufficient balance!z'Bid price is great than max allow pricezInvalid symbol.zParam error!maintenance)exactbroad)deep_extendsuperr3   describer0   parse_numberr(   r)   r*   r,   r%   r#   r/   r$   r&   r.   )self	__class__s    C/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/mexc.pyr  zmexc.describe   sj   dD : < p?
&p?
Mp?
 $p?
 	p?

 tp?
 p?
 4p?
  sss $s 	s
 %s %s Ts $Us 's s "4s ts s $Us  s  '!s" /#s$ ,T%s& 0's( t)s* +s, &t-s. (/s0 '1s2 (3s4 "45s6 %d7s8 49s: T;s<  =s> ?s@  AsB &uCsD "5EsF +EGsH )%IsJ #EKsL ,UMsN &tOsP #DQsR $TSsT 'UsV (WsX "4YsZ [s\ &t]s^ (_s` 1$asb  csd *:esf +Dgsh &tisj 'ksl (msn #Dosp *4qsr $Usst "4usv *5wsx +Eysz )%{s| #D}s~ ts@ #DAsB  CsD !%EsF %dGsH /IsJ "5KsL +JMsN OsP !$QsR  SsT dUsV $UWsX +EYsZ !$[s\ "4]s^ d_s` !$asb "4csd tesf #Dgsh  isj '
ksl $Tmsn !$osp (qsr %dsst )%usv twsx tysz {s| T}s~ ts@ "4AsB #ECsD %dEsF &zGsH 'IsJ $TKsL  MsN #'#'$( $$)',#!%#'  esp?
x ~ #9#9
 #E#E
 #N#M!
 "#G" /< / U5yp?
p  $%$%,.%&&'01)*&'()+,,-12() $, #Q, (!,  (,  &r	, 
 ',  ',  /,  1!,  4R,  5a,  7,  7,  6r,  /,  6q,   8!, " DQ#, $ .q%, & 3A', ( *1), * /+, , .q-, . 0/, 0 5a1, 2 03, 4 +A5, 6 6q7, 8 3A9, : +A;, < 3A=, > 9!?, @ 8A, B 8C, D .qE, F ./6701;<9:BC/0./+,W, Z!#Q!(!! <Q! 1!	!
 21! 1!! *2! 5a! /! /! 8! 6q! DQ! .r! .q!  -a!!& -a  &'*+23,-12./01#GL %_D   "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!## ]eqp?
| Y}p?
~ p?
V !&"&!..w7!..w7	Wp?
f +0"#%)%)%))  $&*',!! #"$$#""""
 %$&&%%%$%&2  &"' ##  $ykyUy 9y ]	y
 Uy 7y Uy y Gy0 61y8 X9yD EEyF VGyJ VKyL 5MyN 6Oyv 6;5:.3!" '"7 AAgp?
j $&*(-,1$)$)%*-
 */+06:#'#'"&#(	( #'$)$(+/27/4#(1$6 r% ',!$$&%)*.& ',#($)*.	# '+!%#($)*.( '+!%$%%&#($)*.$ '+!%$%,-%&#($)*.	*  #MIV y  )(,$($(%)-
 -1).+0"&$(+0$ %)&+!$$&%'	& %e# ',!$#'$)	( ',!$$&%'#'$)$ ',!$$&,0%'#'$)*  #c4n "; "; 	 ##WOkp?
J  ! (!! z! 	!
 |! y! u! ~! ! ! ! x! %! z! !  
!!" #!$ &%")!Kp?
v eZe Ze Y	e
 .e Le Je .e Ze Ze Le Ze \e Le -e  :!e$ :%e& -'e( .)e* ]+e, \-e. ./e0 l1e2 -3e4 .5e6 07e8 Y9e: Z;e< Z=e> Z?e@ \AeB \CeD \EeF \GeH ZIeJ ZKeL \MeN ]OeP ZQeR ZSeT ZUeV ZWeX ZYeZ Z[e\ ]]e^ ]_e` Zaeb Zced ]eef ]geh Ziej ]kel ]men Zoep ]qer \set \uev \wex \yez \{e| \}e~ -e@ 0AeB ZCeD \EeF ZGeH \IeJ \KeL \MeN \OeP \QeR ]SeT 1UeV 1WeX jYeZ l[e\ j]e^ 1_e` jaeb 1ced jeef jgeh miej mkel mmen joep )(((((((((((1IeN DNBL4>7C 1->->?K'0$.#0Otwp?
 p p	    c                    | j                  dd|      \  }}d}d}d}|dk(  rK| j                  |      }t        |j                               }t	        |      }|r| j                  |      nd}nM|dk(  rH| j                  |      }| j                  |d      rdn| j                  |      }| j                  |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  s     !>>}dTZ[
E--e4H (DYF,2TYYx(F6!11%8H "__XyATtyyQYGZF''&9G
 	
r  c                     | j                  dd|      \  }}d}|dk(  r#| j                  |      }| j                  |d      S |dk(  r#| j                  |      }| j                  |d      S y)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
E--e4H $$X|<<6!11%8H $$Xv66r  c                    | j                  d      sy| j                  |      }i }t        dt        |            D ]0  }||   }| j	                  |d      }| j                  |      }i }| j                  |dg       }	t        dt        |	            D ]  }
|	|
   }| j                  |dd      }| j                  |      }|||d| j                  |dd      | j                  |d	d      | j                  |d
      dd| j	                  |d      | j	                  |d      di| j	                  |d      d
||<    | j                  |||| j	                  |d      dddddddddid|d      ||<   3 |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minrW  r   )
r   r6   r  activer\   r   fee	precisionlimitsr   r7   amountcrypto)r   r6   coder7   r   r\   r   r!  r"  r#  typer<  )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&  r<  chainsjchain	networkIdr  s                 r  fetch_currencieszmexc.fetch_currencies  s    ..u599&AN q#h-( -	A{H!!(F3B**2.DH__X}bAF1c&k* q	 ..uiK	11)<!#&"#~~e_eL $u6F N++E=A!%"#'#3#3E=#I#'#3#3E=#I% !% 0 0
 C%!	*  77 ((6: !## !$#9 F4L7-	\ r  c                     | j                   d   r| j                          | j                  |      }| j                  |      }||g\  }}| j	                  ||      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
        r6  )r   load_time_differencefetch_spot_marketsfetch_swap_marketsarray_concat)r  r
  spotMarketPromiseswapMarketPromise
spotMarket
swapMarkets         r  fetch_marketszmexc.fetch_marketsw  sb     <<12%%' 33F; 33F;"35F!G
J  Z88r  c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }| j	                  |d      }| j                  |d      }d}|d	k(  r|rd
}| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|j                  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| j                  | j                  | j	                  |d!                  | j                  | j                  | j	                  |d"                  d#ddd$| j                  |d%      dd$ddd$| j                  |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
        symbolsr   symbol	baseAsset
quoteAssetr  isSpotTradingAllowedF1TisMarginTradingAllowedmakerCommissiontakerCommissionmaxQuoteAmountr6   /basequotesettleNbaseIdquoteIdsettleIdr'  rB   rC   rD   rE   rF   r   r   r  baseAssetPrecisionquoteAssetPrecisionr$  pricer  baseSizePrecisionquoteAmountPrecisionrR  r$  rY  costr  r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper"  r#  createdr   )
spotPublicGetExchangeInfor  r*  r  r+  r,  r0  appendr  parse_precision)r  r
  r  r  r2  r3  marketr6   rS  rT  rP  rQ  r  rI  r   rK  rL  rM  rN  s                      r  r<  zmexc.fetch_spot_markets  s    11&9V xB7q#d)$ B	A!WF!!&(3B%%fk:F&&v|<G**62D++G4E%%fh7F#'??6;Q#R F#$8%)__V=U%V""..v7HIO"..v7HIO!--f6FGNMM 2b2$*u,2 2 	2
 $2 &2 72 D2 2 2 02 2 %2 %2 &2  E!2" $#2$  (( $"&""//0D0DTEUEUV\^rEs0tu!..t/C/CDDTDTU[]rDs/tu  $#!
  $//8KL#
  $#
  $//8NO-$  c2 2!B	F r  c                 *   | j                   }| j                  | dd       | j                  |      }| j                  | d|       | j                  |dg       }g }t	        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |	      }| j                  |
      }| j                  |      }| j                  |d	      }||k(  }|j                  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|| | j                  |d      | j                  |d       | j                  |d!      d"d"d"d"| j                  |d#      | j                  |d$      d%| j                  |d&      | j                  |d'      d(| j                  |d)      | j                  |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   r  r   rF  baseCoin	quoteCoin
settleCoinstater6   rO  :rP  rQ  rR  rS  rT  rU  r'  rD   rB   FrC   TrE   rF   r   0r   r  takerFeeRatemakerFeeRater_  NvolUnit	priceUnitrX  minLeveragemaxLeverager  minVolmaxVolr\  r^  )
r:   set_propertycontractPublicGetDetailr  r*  r  r+  r,  rf  r0  )r  r
  	currentRlr  r  r2  r3  rh  r6   rS  rT  rU  rP  rQ  rR  rm  isLinears                    r  r=  zmexc.fetch_swap_markets  s    !NN	$R0//7$Y7Z x4q#d)$ =	A!WF!!&(3B%%fj9F&&v{;G''=H**62D++G4E,,X6F$$VW5EHMM 2b2$*u,s2V;2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 5C<2  D!2" (#2$  (<))&.A))&.A $ 0 0 H"&""..vyA!--fkB  $//F#//F!
  $//A#//A
  $#
  $#$  c2 2=	| r  NrF  rZ  c                    | j                          | j                  |      }d|d   i}|||d<   d}|d   r]| j                  | j                  ||            }| j	                  |d      }| j                  |||      }| j	                  |d      |d<   |S |d	   rm| j                  | j                  ||            }| j                  |d
      }	| j	                  |	d      }
| j                  |	||
      }| j	                  |	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
        rF  r6   NrZ  rB   	timestamplastUpdateIdnoncerD   r  r<   )load_marketsrh  spotPublicGetDepthextendr	  parse_order_bookcontractPublicGetDepthSymbolr  )r  rF  rZ  r
  rh  request	orderbookr  spotTimestampr  r}  s              r  fetch_order_bookzmexc.fetch_order_book  s'    	V$fTl
 $GG	&>..t{{7F/KLH !--hDM--hNI!%!2!28^!LIg2 1 F^88Wf9UVH& ??8V4D))$<I--dFIFI!%!2!24!CIgr  priceKey	amountKeycountOrIdKeyc                     d}| j                  ||      }| j                  ||      }| j                  ||      }||||gS ||gS )Nr   )r0  )	r  bidaskr  r  r  countKeyrY  r$  counts	            r  parse_bid_askzmexc.parse_bid_ask  sZ      2!!&)4  265))vr  sincec                 T   | j                          | j                  |      }d|d   i}|||d<   d}|d   r&| j                  |ddg      }|||d<   |t        | j                  d	z         ||t        | j                  d
z         ||d<   | j                  | j                  dd      }	| j                  |d|	      }	| j                  |dg      }|	dk(  r"| j                  | j                  ||            }n|	dk(  r"| j                  | j                  ||            }nw|	dk(  r"| j                  | j                  ||            }nPt        | j                  dz         |d   r3| j                  | j                  ||            }
| j                  |
d      }| j                  ||||      S )aU  

        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>`
        rF  r6   NrZ  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  rh  safe_integer_nr'   r6   r+  r   omitr  r  r  r  r-   contractPublicGetDealsSymbolr  parse_trades)r  rF  r  rZ  r
  rh  r  r   r  r  r  s              r  fetch_tradeszmexc.fetch_trades  s    	V$fTl
 $GG&>''G0DEE ',$=+DGG6y,yzz =+DGG6x,xyy%*	"%%dll4GIabF%%fh?FYYvz2F1144T[[&5QR::;;DKKQW<XY0011$++gv2NO"477-U#UVV> F^88Wf9UVH" __Xv6F  >>r  traderh  c                    d }d }d }d }d }d }d }	d }
d }d }d }d|v rr| j                  |d      }| j                  d |      }|d   }| j                  |d      }| j                  |d      }| j                  | j                  |d            }	d}
n| j                  |d      }| j                  ||      }|d   }| j	                  |dd      }| j	                  |d	d      }| j                  |d
      }d|v r| j                  |d      }| j                  |d      }| j                  | j                  |d            }	| j                  |d      | j                  | j                  |d            d}| j                  |d      rdnd}
n| j                  |dd      }| j	                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }||rdnd}
||rdnd}	||rdnd}	d}
| j                  |d      }|$| j                  |d      | j                  |      d}|| j                  |||	||||
      }| j                  |||| j                  |      |||	|
|||||d|      S ) NvtrF  pTr   r6   arY  orderIdpositionModer}  volsider!  feeCurrencyr]  r4  r   r   qtyqquoteQtyisBuyerisMakerisBuyerMakermbuysellcommissionAsset
commission)r6   r   r}  datetimerF  r'  r  takerOrMakerrY  r$  r]  r!  r   )r	  safe_marketr+  parse_order_sider-  r,  r  safe_integer_2safe_value_2synthetic_trade_id
safe_tradeiso8601)r  r  rh  r6   r}  r  rF  r!  r'  r  r  priceStringamountString
costStringmarketIdr  r  
buyerMakerfeeAssets                      r  parse_tradezmexc.parse_trade(  s   	
%< ))%5I%%dF3FH%F**5#6K++E37L(()9)9%)EFD"Lh ''x8H%%h7FH%F##E45B,,UGSAK&&ui8G& --e[A	#//u=,,T-=-=eV-LM ,,UE: $ 7 78H8HP]8^ _ +///%*Iww //vsC	#11%D!--eZ@
//%;//%;!..uncJ
&.577L&$+5D)%/6UD#*L++E3DE' $ 0 0 E$($;$;H$EC :((D,P[]acopB"Y/( " 
  	r  c                     d}|x| j                  |      dz   | j                  |dd      z   }||d|z   z  }||d| j                  |      z   z  }||d| j                  |      z   z  }||d|z   z  }||d|z   z  }|S )N -r6   _)number_to_stringr+  )	r  rh  r}  r  r$  rY  	orderTyper  r6   s	            r  r  zmexc.synthetic_trade_id  s     &&y1C7$:J:J6SWY\:]]BcDj !cD11&999 cD11%888'cL(($cIo%	r  r   c           	      8   | j                          | j                  |      }|d   rdnd}d}| j                  |ddd      \  }}|r| j                  d||||||      S | j	                  | j
                  di       }	| j	                  |	|d   i       }
| j                  |
|      }| j                  |      dz  }|d	   |d
}d}|d   r| j                  |ddg      }|;||d<   |4| j                  |||z        }| j                         }t        ||      |d<   |||d<   || j                  |dg      }||d<   | j                  | j                  ||            }|}n+|d   r%| j                  |ddgd      }|| j!                  |dz        |d<   || j                  |dg      }||d<   | j                  |dd      }| j                  |d      }d}|dk(  r"| j#                  | j                  ||            }nf|dk(  r"| j%                  | j                  ||            }n?|dk(  r"| j'                  | j                  ||            }nt)        | j*                  dz         | j	                  |d      }| j-                  |dddddd      }| j/                  |||||      S ) a1  

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

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        rB   r_  rf  Fr   paginater   r'  r6   )rF  intervalNr  r  r  rZ  rD   gMbP?startendrY  rd  rC  rB  zA fetchOHLCV() not support self price type, [default, index, mark]r  r   openhighlowcloser  )r  rh  handle_option_and_params"fetch_paginated_call_deterministicr  r   r+  parse_timeframer  summillisecondsr  r  spotPublicGetKlinesr  safe_integer_product_nparse_to_intcontractPublicGetKlineSymbol&contractPublicGetKlineIndexPriceSymbol%contractPublicGetKlineFairPriceSymbolr-   r6   convert_trading_view_to_ohlcvparse_ohlcvs)r  rF  	timeframer  rZ  r
  rh  maxLimitr  r   r   timeframeValuedurationr  candlesr  r  nowr  	priceTyper  s                        r  fetch_ohlcvzmexc.fetch_ohlcv  s     	V$"6N488z[`a&::<QVX]_hjprz{{//$,,bA__WfVnbA
))*i@''	2T9Tl&
 &>'')0DEE ',$=((5(X*=>C++-C),S#GI& #(  6G95%*	"//GV0LMH GF^//)8LeTE #'#4#4UT\#B  6G95!&(()DIYYvw/FHI%<<T[[RX=YZg%FFt{{SZ\bGcdf$EEdkkRY[aFbc"477-p#pqq  ??8V4D88vvvW\^eglmG  &)UEJJr  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r   r      r   )r	  r0  )r  ohlcvrh  s      r  parse_ohlcvzmexc.parse_ohlcv&  sl    eQ'UA&UA&UA&UA&UA&
 	
r  rE  c                    | j                          i }d}d}|3t        |      }|dk(  }| j                  |d      }| j                  |      }| j	                  d||      \  }}	d}
|r|d   |d<   |dk(  r"| j                  | j                  ||	            }
n9|d	k(  r4| j                  | j                  ||	            }| j                  |d
g       }
|r|
g}
| j                  |
|      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   rF  rB   rD   r  )
r  r  r+  rh  r  spotPublicGetTicker24hrr  contractPublicGetTickerr  parse_tickers)r  rE  r
  r  rh  isSingularMarketr  firstSymbolr  r  tickersr  s               r  fetch_tickerszmexc.fetch_tickers0  s    	 \F%{**7A6K[[-F >>~vW]^
E &tGH224;;w3NOG2 6!33DKK4OPH8 ooh;GiG!!'733r  c                 f   | j                          | j                  |      }| j                  d||      \  }}d}d|d   i}|dk(  r"| j                  | j	                  ||            }n9|dk(  r4| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )aF  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

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

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   NrF  r6   rB   rD   r  )r  rh  r  r  r  r  r  parse_ticker)	r  rF  r
  rh  r  r  r   r  r  s	            r  fetch_tickerzmexc.fetch_ticker  s     	V$ >>}fV\]
EfTl
 11$++gu2MNF. 6!33DKK4OPH4 __Xvr:F  00r  r   c                 Z   | j                  |d      }| j                  ||      }d }d }d }d }d }d }	d }
d }d }d }d }d }d }| j                  |d      }|sd|v r| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d	      }| j                  |d
      }| j                  |d      }t	        j
                  |d      }n0| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t	        j                  |d      rd }t	        j                  |d      rd }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }t	        j
                  |d      }| j                  i d|d   d|d| j                  |      d|d|d|d| j                  |d       d!|d"|d#|d$|d%d d&|d'|d(|d)d d*|	|
|d+|      S ),NrF  rD   r}  bid1ask1volume24amount24high24Pricelower24PriceriseFallValueriseFallRate100	closeTimebidPriceaskPricebidQtyaskQtyro  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   rh  r  r}  r  r  r  r  r  r  r  r  r  
changePcntchangeValue	prevCloseisSwaps                     r  r  zmexc.parse_ticker  sn   ##FH5!!(F3			

	0kV+, ))&+>I""662C""662C))&*=J**6:>K##FM:D""6>:C**6?CK))&.AJ ++J>J0 ))&+>I""6:6C""6:6C((:I((:I  C0 	  C0 	))&(;J**6=AK##FK8D##FK8D""6:6C((1ABI**6=AK))&2FGJ ++J>J !
fX&!
!
 Y/!
 D	!

 D!
 3!
 T%%fk:!
 3!
 !
 3!
 !
 D!
 Y!
 k!
 *!
  t!!
" *#!
$ ''!
( ) 	r  c                 H   | j                          d}d}|$t        |      }|dk(  }| j                  |d         }| j                  d||      \  }}d}|dk(  r| j	                  |      }n#|dk(  rt        | j                  dz   |z   d	z         |r|g}| j                  ||      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  rh  r  spotPublicGetTickerBookTickerr-   r6   r  )	r  rE  r
  rh  r  r  r  r  r  s	            r  fetch_bids_askszmexc.fetch_bids_asks?  s     	 \F%{[[,F >>PVX^_
E88?G 6!tww)QQT^^akklliG!!'733r  r]  c                     | j                          | j                  |      }|d   st        | j                  dz         d|i}| j	                  |dddd| j                  ||            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>`
        rB   9 createMarketBuyOrderWithCost() supports spot orders onlyr]  rh  r  r   Nr  rh  r-   r6   create_orderr  r  rF  r]  r
  rh  reqs         r  !create_market_buy_order_with_costz&mexc.create_market_buy_order_with_costf  so     	V$f~tww)ddeeD
   5!T4;;sTZC[\\r  c                     | j                          | j                  |      }|d   st        | j                  dz         d|i}| j	                  |dddd| j                  ||            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>`
        rB   r'  r]  rh  r  r   Nr(  r*  s         r  "create_market_sell_order_with_costz'mexc.create_market_sell_order_with_costz  sp     	V$f~tww)ddeeD
   61dDKKPSU[D\]]r  r'  r  r$  rY  c           	          | j                          | j                  |      }| j                  d|      \  }}	|d   r| j                  |||||||	      S | j	                  |||||||	      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>`
        rT   rB   )r  rh  handle_margin_mode_and_paramscreate_spot_ordercreate_swap_order)
r  rF  r'  r  r$  rY  r
  rh  rH  r  s
             r  r)  zmexc.create_order  sx    8 	V$ >>}fU
E&>))&$feZY^__))&$feZY^__r  c                    |d   }|j                         }	|d   |	|j                         d}
|dk(  r| j                  |dd      }| j                  |d      }||}| j                  ||      |
d<   n}|| j	                  ||      |
d<   ne| j                  |      }| j                  |      }t        j                  ||      }|}| j                  ||      |
d<   n| j	                  ||      |
d<   || j                  ||      |
d<   | j                  |d	      }|||
d
<   | j                  |dd	g      }|#|dk7  rt        | j                  dz   |z   dz         d }| j                  |dk(  |dk(  |      \  }}|rd|
d<   | j                  |d      }|'| j                  |d      }|dk(  rd|
d<   n
|dk(  rd|
d<   | j                  |
|      S )NrF  r6   )rF  r  r'  rh  r]  quoteOrderQtyquantityrY  clientOrderIdnewClientOrderIdr'  isolatedz+ createOrder() does not support marginMode  for spot-margin tradingLIMIT_MAKERrO  rD  IMMEDIATE_OR_CANCELrE  FILL_OR_KILL)uppersafe_number_2r  cost_to_precisionamount_to_precisionr  r1   r  price_to_precisionr+  r(   r6   handle_post_onlyr  )r  rh  r'  r  r$  rY  rH  r
  rF  	orderSider  r]  r  r  quoteAmountr6  postOnlytifs                     r  create_spot_order_requestzmexc.create_spot_order_request  s    !JJL	TlJJL

 8%%ffoFDYYvv.F+/+A+A&&+Q(=*.*B*B66*RGJ'#'#8#8#@L"&"7"7">K")"4"4\;"OK(F/3/E/Eff/UGO,"&":":66"JGJ#66vuEGG((A$*7G&'YYv'@AF!Z' +X!X[e!e  iC  "C  D  D001A4=CXZ`a&+GFOv}5?YYv}5Fe|"7"0{{7F++r  c           	         | j                          | j                  |dd      }| j                  |d      }| j                  |||||||      }	d}
|r| j	                  |	      }
n| j                  |	      }
| j                  |
|      }||d<   ||d<   | j                  |d      ||d<   | j                  |d      ||d<   |S )an  
 @ignore
        create a trade order

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

        :param str market: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param str [marginMode]: only 'isolated' is supported for spot-margin trading
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        testFNr  r'  rY  r$  )r  r/  r  rG  spotPrivatePostOrderTestspotPrivatePostOrderparse_orderr+  )r  rh  r'  r  r$  rY  rH  r
  rI  r  r  r   s               r  r1  zmexc.create_spot_order  s    " 	~~ffe466*00tVUT^`fg44W=H009H(   62ffE7+3"E'NE8,4$E(Or  c                 @   | j                          |d   }| j                  | j                  di       }	| j                  |	|d      }
|
rt	        | j
                  dz   |z         d}|(|dk(  rd}n3|dk(  rd	}n+t        | j
                  d
z         | j                  |dd      }|dk7  r;|dk7  r6|d	k7  r1|dk7  r,|dk7  r'|dk7  r"|dk7  r|dk7  rt        | j
                  dz         d}| j                  |dk(  |dk(  |      \  }}|rd}n|dk(  rd	}n|dk(  rd}|d   t        | j                  ||            ||d}|dk7  r(|dk7  r#|dk7  rt        | j                  ||            |d<   |d	k(  r,| j                  |d      }|t        | j
                  dz         | j                  |dd      }| j                  |dd      }d}|r,|r| j                  |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<   | j                  |dd      }|||d<   | j                  |d d!      }| j                  |g d"      }d}|r| j                  ||      |d <   | j                  |d#d	      |d#<   | j                  |d$d	      |d$<   | j                  |d%d	      |d%<   | j                  |d&d	      |d&<   | j!                  | j#                  ||            }n!| j%                  | j#                  ||            }| j'                  |d'      }| j)                  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>`
        rF  r8  Fz4 createSwapOrder() does not support yet self symbol:Ncrossr   r8  r   zN createSwapOrder() marginMode parameter should be either "cross" or "isolated"openTyperZ  rh  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   )rF  r  r'  rO  rY  rR  zK createSwapOrder() requires a leverage parameter for isolated margin orders
reduceOnlyrP  r  r  r  r  r6  externalOidrI  	stopPrice)r6  rR  rE  rS  rI  rP  triggerTypeexecuteCycletrendr  r  )r  r  r   r/  r-   r6   r'   r	  r,   rB  floatr@  rA  r  r-  r>  !contractPrivatePostPlanorderPlacer  contractPrivatePostOrderSubmitr+  
safe_order)r  rh  r'  r  r$  rY  rH  r
  rF  r8  isContractUnavaiablerO  rE  r  rR  rQ  rP  sideIntegerr6  rI  r  r  s                         r  r2  zmexc.create_swap_order	  s   8 	!#t||=SUWX#~~.BFERtww)__bhhii!W$z)'  3C  )C  D  D((Q?HGO$("2QRY]abYbimqriry}  BC  zC  JN  RS  JStww  *y   y  z  z001A419fU&DW_DXDTl11&&AB  #
4 AIDAIDH,<$T%<%<VU%KLGGq=((<H'2(  A  A^^FL%@
%86<8"&%-ve $!AK&'GN#$(EMa$(EMa%**6?MR$%2GM"))&.+N6#vw&*&=&=fl&SGN#%)%6%6v}a%PGM"&*&7&7PQ&RGN##00!DGG#'#4#4V[!#LGK ==dkk'SY>Z[H::4;;wPV;WXH &1d|V44r  ordersc           
         | j                          g }d}t        dt        |            D ]  }||   }| j                  |d      }| j	                  |      }|d   st        | j                  dz         ||}n||k7  rt        | j                  dz         | j                  |d      }	| j                  |d      }
| j                  |d	      }| j                  |d
      }| j                  |di       }d}| j                  d|      \  }}| j                  ||	|
||||      }|j                  |        d| j                  |      i}| j                  |      }| j                  |      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   rF  rB   z2 createOrders() is only supported for spot marketsz; createOrders() requires all orders to have the same symbolr'  r  r$  rY  r
  rT   r   )r  r*  r  r+  rh  r-   r6   r(   r  r0  rG  rf  r  spotPrivatePostBatchOrdersparse_orders)r  r]  r
  ordersRequestsrF  r3  rawOrderr  rh  r'  r  r$  rY  orderParamsrH  orderRequestr  r  s                     r  create_orderszmexc.create_orders	  s|    	q#f+& 	0AayH''(;H[[*F&>"477-a#abb~!X%$TWW/l%lmm##Hf5D##Hf5D__Xx8FOOHg6E//(HbAKJ!%!C!CMSY!ZJ99&$fV[]gituL!!,/'	0* 499^4
 227;*   **r  r6   c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}d}|d   r| j	                  |d      }|| j                  |d      }||d<   n||d<   | j                  d	|      \  }}	|E|d
k7  rt        | j                  dz   |z   dz         | j                  | j                  ||	            }n_| j                  | j                  ||	            }n=|d   r8||d<   | j                  | j                  ||            }
| j                  |
d      }| j                  ||      S )am  
        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 argumentrF  r6   rB   r6  origClientOrderIdr  r   r8  z* fetchOrder() does not support marginMode r9  rD   order_idr  )r'   r6   r  rh  r+  r  r0  r(   spotPrivateGetMarginOrderr  spotPrivateGetOrder!contractPrivateGetOrderGetOrderIdr  rL  )r  r6   rF  r
  rh  r  r  r6  rH  r  r  s              r  fetch_orderzmexc.fetch_order	  ss    >#DGG.X$XYYV$fTl
 &> ,,V_EM(6?;/<+,%'	" $ B B<QW XJ%+$TWW/[%[^h%h  lF  &F  G  G55dkk'56QR//GU0KLZ F^"$GJ==dkk'SY>Z[HB ??8V4Df--r  c                 :   | j                          i }d}|| j                  |      }|d   |d<   | j                  |d      }| j                  |d      }| j	                  d||      \  }}	|dk(  r|t        | j                  dz         | j                  d|      \  }
}|||d<   |||d	<   |||d
<   d}|
E|
dk7  rt        | j                  dz   |
z   dz         | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||||      S |p||d<   | j                  |d|      }|#| j                  || j                  d         |d<   n_||z
  | j                  d   kD  rt        | j                  dz         ||d<   n,|*| j                  || j                  d   dz        |d<   ||d<   |||d<   | j                  | j                  dd      }| j                  |	d|      }g }g }|dk(  r4| j!                  | j                  ||	            }| j#                  |d      }n3| j%                  | j                  ||	            }| j#                  |d      }| j'                  ||      }| j                  |||||      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   rF  r  r   rB   z9 fetchOrders() requires a symbol argument for spot marketr  r  rZ  r8  z+ fetchOrders() does not support marginMode r9  
start_timeend_timer?  z. end is invalid, i.e. exceeds allowed 90 days.	page_size(contractPrivateGetOrderListHistoryOrdersr  r  )r  rh  r	  r  r  r'   r6   r0  r(   spotPrivateGetMarginAllOrdersr  spotPrivateGetAllOrdersr`  r  r   r+  rr  r  %contractPrivateGetPlanorderListOrdersr>  )r  rF  r  rZ  r
  r  rh  r  r  r  rH  
queryInnerr  r  r  ordersOfRegularordersOfTriggermergeds                     r  fetch_orderszmexc.fetch_ordersE
  s     	[[(F &tGH!!&'267+ >>}fV\]
E~'2m(mnn%)%G%GW]%^"J
 ',$ %*	" #( H%+$TWW/\%\_i%i  mG  &G  H  H==dkk'S]>^_77GZ8XYb $$XvueDD (-%''
EB;*.((5$,,GW:X*YGJ'et||4D'EE(3c)cdd.3
+"(,EU8VY[8[(\%&+
# ',$%%dllMCmnF%%eXv>F O OCCHHU\^cIdeF #'//(F"C  EEdkkRY[`Fab6 #'//(F"C&&HF$$VVUE6JJr  c                 ~   | j                          i }d }|| j                  |      }|d   |d<   | j                  d||      \  }}|dk(  rt        | j                  dz   |z         dj                  |      |d<   | j                  | j                  ||            }| j                  |d      }	| j                  |	|      S )	Nr6   rF  fetchOrdersByIdsrB   z) fetchOrdersByIds() is not supported for ,	order_idsr  )
r  rh  r  r(   r6   join!contractPrivateGetOrderBatchQueryr  	safe_listr`  )
r  idsrF  r
  r  rh  r  r  r  r  s
             r  fetch_orders_by_idszmexc.fetch_orders_by_ids
  s    [[(F &tGH >>?QSY[ab
ETWW'RRU__``#&88C=GK ==dkk'SX>YZHF >>(F3D$$T622r  c                    | j                          i }d}d}|| j                  |      }| j                  d||      \  }}|dk(  r|t        | j                  dz         |d   |d<   | j                  d|      \  }}	d}
|E|dk7  rt        | j                  dz   |z   d	z         | j                  | j                  ||	            }
n!| j                  | j                  ||	            }
| j                  |
|||      S | j                  d
||||      S )a9  
        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   z= fetchOpenOrders() requires a symbol argument for spot marketr6   rF  r8  z/ fetchOpenOrders() does not support marginMode r9  r   )r  rh  r  r'   r6   r0  r(   spotPrivateGetMarginOpenOrdersr  spotPrivateGetOpenOrdersr`  fetch_orders_by_state)r  rF  r  rZ  r
  r  rh  r  rH  r  r  s              r  fetch_open_orderszmexc.fetch_open_orders,  sE    	
[[(F!??@QSY[ab
F~'2q(qrr &tGH $ B BCTV\ ]JH%+$TWW/`%`cm%m  qK  &K  L  L>>t{{7TY?Z[88We9TUb $$XvueDD --avNNr  c                 ,    | j                  d||||      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   r  r  rF  r  rZ  r
  s        r  fetch_closed_orderszmexc.fetch_closed_orders       ))!VUE6JJr  c                 ,    | j                  d||||      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  r  r  s        r  fetch_canceled_orderszmexc.fetch_canceled_orders  r  r  c           	         | j                          i }d }|| j                  |      }| j                  d||      }|dk(  rt        | j                  dz   |z         ||d<   | j                  |||| j                  ||            S )NfetchOrdersByStaterB   z+ fetchOrdersByState() is not supported for states)r  rh  r  r-   r6   rz  r  )	r  rm  rF  r  rZ  r
  r  rh  r  s	            r  r  zmexc.fetch_orders_by_state  s    [[(F778LfV\]
tww)VVYccdd %GH$$VUE4;;wPV;WXXr  c                    | j                          i }d}|| j                  |      }|d   |d<   d}| j                  d||      \  }}| j                  d|      \  }}d}	|dk(  r|t	        | j
                  dz         d|d   i}
| j                  |d      }|| j                  |d      }||
d<   n||
d	<   |E|d
k7  rt        | j
                  dz   |z   dz         | j                  | j                  |
|            }	n| j                  | j                  |
|            }	n| j                  | j                  dd      }| j                  |d|      }d}|dk(  r| j                  |g      }n0|dk(  r| j                  |g      }nt        | j
                  dz         | j!                  |d      }	| j!                  |	d      }| j!                  |dd      }|dk7  r!t#        | j
                  dz   |z   dz   |z         | j%                  |	|      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   rF  rL   rB   z) cancelOrder() requires a symbol argumentr6  rg  r  r8  z+ cancelOrder() does not support marginMode r9  contractPrivatePostOrderCancelr  "contractPrivatePostPlanorderCancelz& cancelOrder() not support self methodr  r   errorMsgr  r  z! cancelOrder() the order with id z cannot be cancelled: )r  rh  r  r0  r'   r6   r+  r  r(   spotPrivateDeleteMarginOrderr  spotPrivateDeleteOrderr   r  r  r-   r  r,   rL  )r  r6   rF  r
  r  rh  r  rH  r  r  requestInnerr6  r  r  r   r  s                   r  cancel_orderzmexc.cancel_order  sQ    	[[(F &tGH
!??vW]^
F >>}fU
E~'2](]^^&,"L !,,V_EM(5/:4A01*,Y'%+$TWW/\%\_i%i  mG  &G  H  H88\SX9YZ224;;|U3STJ %%dllMCcdF%%eXv>FH99>>tD??BBB4H"477-U#UVV ??8V4DOOD!,Euj"=H9$"477-P#PSU#UXp#ps{#{||f--r  c                    | j                          || j                  |      nd}| j                  d||      }|dk(  rt        | j                  dz   |z         | j                  |      }| j                  |d      }| j                  ||      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  rh  r  r(   r6   r  r  r`  )r  r  rF  r
  rh  r  r  r  s           r  cancel_orderszmexc.cancel_orders  s     	)/);V$$77PVW
TWW'NNQ[[\\::3?H >>(F3D$$T622r  c                 L   | j                          || j                  |      nd}i }d}| j                  d||      \  }}| j                  d|      \  }}|dk(  r|t	        | j
                  dz         |d   |d<   d}|E|dk7  rt        | j
                  dz   |z   d	z         | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||      S ||d   |d<   | j                  | j                  dd
      }	| j                  |d|	      }	d}|	d
k(  r"| j                  | j                  ||            }n&|	dk(  r!| j                  | j                  ||            }| j                  |dg       }
| j                  |
|      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   rF  r8  z/ cancelAllOrders() does not support marginMode r9  !contractPrivatePostOrderCancelAllr  %contractPrivatePostPlanorderCancelAllr  )r  rh  r  r0  r'   r6   r(   !spotPrivateDeleteMarginOpenOrdersr  spotPrivateDeleteOpenOrdersr`  r+  r   r  r  r  )r  rF  r
  rh  r  r  rH  r  r  r  r  s              r  cancel_all_orderszmexc.cancel_all_orders=  s    	)/);V$$
!??@QSY[ab
F >>?PRXY
E~'2i(ijj &tGHH%+$TWW/`%`cm%m  qK  &K  L  LAA$++gW\B]^;;DKKQV<WXJ $$Xv66!$*4L! %%dll4EGjkF%%eXv>FH<<AA$++gW\B]^BBEEdkkRY[`Fab >>(FB7D$$T622r  r   c                    | j                  |d      }|%| j                  |d| j                  |d      d      S d }t        |t              r|}n| j                  |dd      }| j                  | j                  |d            }| j                  |d      }|| j                  |      }| j                  |d	      }| j                  ||      }| j                  |g d
      }d }	| j                  |d      }
|
N| j                  |d      }| j                  |d      }t        j                  ||      }|
| j                  |      d}	| j                  i d|d| j                  |d      d|d| j                  |      dd d| j                  | j                  |dd            d	|d	   d| j                  |      d|d| j!                  | j                  |d            d| j#                  |d      d| j%                  |dd      d| j#                  |d      d| j%                  |dd      d| j#                  |d      d | j%                  |d!d"      d#d |	d |d$|      S )%Nr&  rejectedr7  )r   r  r6  r  r6   rO  r'  rF  )r   
createTimetransactTimer  takerFeemakerFee)r4  r]  r6  r}  r  lastTradeTimestampr  rm  r  rY  rI  rS  r  dealAvgPricer$  origQtyr  r]  cummulativeQuoteQtyfilledexecutedQtydealVol	remaining)r!  r   r   )r	  rZ  r+  
isinstancestrr-  parse_order_time_in_forceget_tif_from_raw_order_typer  r  r1   
string_addr  r  parse_order_statusparse_order_typer  r0  r>  )r  r   rh  r&  r6   rO  typeRawr  r}  r!  r  r  r  feeSums                 r  rL  zmexc.parse_order  s   V   /??$!%!1!1%9K!L$  
 eS!B##E9d;B44T5E5Ee]5[\""5&1::7CK##E84!!(F3''/UV	&&um<"''z:H''z:H''(;F'))&1C   
" 
T--e_E 
  
 Y/	 

 !$ 
 d--d.@.@RY.Z[ 
 fX& 
 D))'2 
 ; 
 D))$*:*:5&*IJ 
 T%%eW5 
 D..uk>R 
 t''~> 
 d((	5A 
 D$$U,AB 
  d((yI! 
" # 
$ ) 
* + 	r  c                 6    ddddd}| j                  |||      S )Nr  r  )BUYSELLrJ  2r+  r  r  statusess      r  r  zmexc.parse_order_sideu  s,    	
 &&99r  c                 8    dddddd}| j                  |||      S )Nrh  rZ  )MARKETLIMITr:  r;  r<  r  r  s      r  r  zmexc.parse_order_type  s/    "#*#
 &&99r  r  c           	      >    ddddddddd}| j                  |||      S )Nr  closedcanceled)NEWFILLEDCANCELEDPARTIALLY_FILLEDPARTIALLY_CANCELEDr  34r  r  s      r  r  zmexc.parse_order_status  s:    " &", 
 &&99r  c                 4    dddd}| j                  |||      S )NGTCrE  rD  )r  rE  rD  r  r  s      r  r  zmexc.parse_order_time_in_force  s)    

 &&99r  r  c                 8    dddddd}| j                  |||      S )Nr  	POST_ONLYrD  rE  )r  r:  r;  r<  r  r  )r  r  r  s      r  r  z mexc.get_tif_from_raw_order_type  s/    &#(!
 )Y??r  c                     |dk(  r| j                  |      S |dk(  r#| j                  |      }| j                  |d      S y )NrB   rD   r  )spotPrivateGetAccountcontractPrivateGetAccountAssetsr  )r  r'  r
  r  s       r  fetch_account_helperzmexc.fetch_account_helper  sI    6>--f55: V^;;FCH& ??8V44r  c                    | j                  dd|      \  }}| j                          | j                  ||      }| j                  |dg       }g }t	        dt        |            D ]a  }||   }| j                  |dd      }	| j                  |	      }
|j                  | j                  |d      | j                  |d      |
|d	       c |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   assetr4  r6   r'  )r6   r'  r&  r   )
r  r  r  r  r*  r  r-  r,  rf  r+  )r  r
  r  r  r  r  r2  r3  r   
currencyIdr&  s              r  fetch_accountszmexc.fetch_accounts  s     !>>PTV\]
E,,Z?xR8q#d)$ 		A1gG++GWjIJ**:6DMM&&w5((&9	 			 r  c                 F   | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |di       }||| j                  |d      | j                  |d      ddd	S )
ac  
        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>`
        rB   z- fetchTradingFee() supports spot markets onlyrF  r6   r  rL  rM  N)r   rF  r   r   r   r   )r  rh  r(   r6   spotPrivateGetTradeFeer  	safe_dictr0  r  rF  r
  rh  r  r  r  s          r  fetch_trading_feezmexc.fetch_trading_fee  s     	V$f~TWW'VVWWfTl
 ..t{{7F/KL ~~h3%%d,=>%%d,=>
 	
r  c                    d }|dk(  r| j                  |dg       }n,|dk(  r| j                  |dg       }n| j                  |dg       }d|i}|dk(  rt        dt        |            D ]  }||   }| j                  |d      }| j	                  |d       }| j                  |d	i       }	| j                  |d
i       }
| j                  | j                  |	d            }| j                  | j                  |
d            }i }| j                  |	      ||<   | j                  |
      ||<   | j                  |      ||<    |S |dk(  rt        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )NrC   assetsrD   r  r  r   r   rF  rG  rH  r  r4  availableBalancefreefrozenBalanceusedlocked)	r  r*  r  r+  safe_symbolr,  parse_balance_helpersafe_balancer   )r  r  r  walletr2  r3  entryr  rF  rP  rQ  baseCode	quoteCode	subResultr  r&  r   s                    r  custom_parse_balancezmexc.custom_parse_balance%  s   z !__Xx<F6!__Xvr:F__Xz2>F(#!1c&k* >q	++E8<))(D9uk2>|R@2243C3CD'3RS 33D4D4DUG4TU	"$	&*&?&?&E	(#'+'@'@'G	)$!%!2!29!=v> M6!1c&k* 'q	!--eZ@
..z:,,."&"2"25:L"M"&"2"25/"J&t' $$V,,1c&k* 'q	!--eW=
..z:,,."&"2"25&"A"&"2"25("C&t' $$V,,r  c                    | j                         }| j                  |d      |d<   | j                  |d      |d<   | j                  |d      |d<   | j                  |d      }| j                  |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++E<@z2##E:6!,,T8<r  c                 0   | j                          d}i }| j                  dd|      \  }}| j                  |d      }| j                  |dd      }| j	                  |ddg      }d}||s|dk(  rd}| j                  |d      }|5| j                  |d      }	|	7dj                  | j                  |	            }n| j                  |      }
|
d	   }| j                  d|d
       d}||d<   | j	                  |ddg      }| j                  | j                  ||            }nf|dk(  r"| j                  | j                  ||            }n?|dk(  r"| j                  | j                  ||            }nt        | j                  dz         | j!                  ||      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_   rH  rC   FrF  rE  r}  r6   zsymbol or symbolsrB   rD   z' fetchBalance() not support self method)r  r  r+  r/  r  r  r  
market_idsrh  check_required_argument#spotPrivateGetMarginIsolatedAccountr  r  r  r-   r6   r  )r  r
  r  r  rH  isMarginr  parsedSymbolsrF  rE  rh  s              r  fetch_balancezmexc.fetch_balance  s    	
!??PTV\]
F%%fl;
>>&(E:6Hl#;<"jH6L M%%fh7F~//&)<&$'HHT__W-E$FMV, &t((H[\!J!.GIYYv)'<=F??GU[@\]H6!11$++gv2NOH6!;;DKKQW<XYHtww)RRSSj ((:>>r  c                    |t        | j                  dz         | j                          | j                  |      }d}| j	                  d||      \  }}d|d   i}d}|dk(  r[|||d<   |||d<   | j                  |d	      }	|	| j                  |d	      }|	|d
<   | j                  | j                  ||            }nw|;||d<   | j                  |d      }
|
"| j                  || j                  d         |d<   |||d<   | j                  | j                  ||            }| j                  |d      }| j                  ||||      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   rF  r6   rB   r  rZ  r  r  rn  ro  r?  rq  r  )r'   r6   r  rh  r  r	  r  spotPrivateGetMyTradesr  r  r   %contractPrivateGetOrderListOrderDealsr  r  )r  rF  r  rZ  r
  rh  r  r  r   r  r  r  s               r  fetch_my_tradeszmexc.fetch_my_trades  s    >#DGG.[$[\\V$
!??QWY_`
FfTl
  ',$ #( %%fg6E 673%*	"00Wf1MNF.  (-%''
;;*.((5$,,GW:X*YGJ' ',$AA$++gW]B^_H0 __Xv6F  >>r  c                    | j                          i }d}|| j                  |      }| j                  d||      \  }}	d}
|dk(  rI|t        | j                  dz         |d   |d<   ||d<   | j                  | j                  ||	            }
n8||d<   | j                  | j                  ||	            }| j                  |d	      }
| j                  |
||||	      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   rF  r  rh  r  )
r  rh  r  r'   r6   r  r  )contractPrivateGetOrderDealDetailsOrderIdr  r  )r  r6   rF  r  rZ  r
  r  rh  r  r  r   r  s               r  fetch_order_tradeszmexc.fetch_order_tradesp  s     	[[(F >>?QSY[ab
E~'2b(bcc &tGH!#GI00We1LMF. #%GJEEdkkRY[`FabH0 __Xv6F  uEEr  c                     | j                  |d      }|t        | j                  dz         | j                          |||d}| j	                  | j                  ||            }|S )N
positionIdz5 modifyMarginHelper() requires a positionId parameter)r  r$  r'  )r	  r'   r6   r  'contractPrivatePostPositionChangeMarginr  )r  rF  r$  addOrReducer
  r  r  r  s           r  modify_margin_helperzmexc.modify_margin_helper  sp    &&v|<
#DGG.e$eff$

 ??GU[@\] r  c                 *    | j                  ||d|      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=reduce-margin-structure>`
        SUBr  r  rF  r$  r
  s       r  reduce_marginzmexc.reduce_margin       ((GGr  c                 *    | j                  ||d|      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=add-margin-structure>`
        ADDr  r  s       r  
add_marginzmexc.add_margin  r  r  rR  c                 r   | j                          d|i}| j                  |d      }|j| j                  |d      }| j                  |d      }|| j                  |      nd}|||t	        | j
                  dz         ||d<   |d   |d<   ||d<   n||d<   | j                  | j                  ||            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
        rR  r  NrO  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   rF  )r  r	  r0  rh  r'   r6   )contractPrivatePostPositionChangeLeverager  )	r  rR  rF  r
  r  r  rO  r  rh  s	            r  set_leveragezmexc.set_leverage  s     	
 &&v|<
''
;H++FNCL-3-?T[[(dF l&:'  3V  )V  W  W&.
#$*4L!*6'$.GL!==dkk'SY>Z[[r  c                    | j                          d}i }|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j	                  |dg       }	g }
t        dt        |	            D ]a  }|	|   }| j                  |d      }|
j                  ||d|| j                  |      | j                  |d      | j                  |d	      d
       c |
S )aY  
        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   rF  rq  r  
resultListr   
settleTimefunding)r   rF  r&  r}  r  r6   r$  )r  rh  (contractPrivateGetPositionFundingRecordsr  r  r*  r  r	  rf  r  r0  )r  rF  r  rZ  r
  rh  r  r  r  r  r2  r3  r  r}  s                 r  fetch_funding_historyzmexc.fetch_funding_history  s    	
 [[(F &tGH#(GK @@WV\A]^B x4__T<<
q#j/* 	AqME))%>IMM & LL3&&ud3**5)< 	 r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |d      }d }	||dz   }	i d|d|d	d d
d dd dd d|d| j	                  |      d|d|d| j	                  |      dd dd dd dd dd dd d|	iS )NfundingRatenextSettleTimerF  r   r}  collectCyclehr   	markPrice
indexPriceinterestRateestimatedSettlePricer  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  )r0  r	  r+  r  r  )
r  r   rh  r'  r(  r  rF  r}  r  intervalStrings
             r  parse_funding_ratezmexc.parse_funding_rateR  s|    **8]C#00;KL##Hh7!!(FD*E%%h<	##Hn=%^N
H
f
 
 $	

 D
 #D
 
 Y/
 ?
  4
 t||,@A
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                 &    | j                  ||      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>`
        )fetch_funding_rate)r  rF  r
  s      r  fetch_funding_intervalzmexc.fetch_funding_interval|  s     &&vv66r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )aw  
        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>`
        rF  r6   r  )r  rh  "contractPublicGetFundingRateSymbolr  r  r.  )r  rF  r
  rh  r  r  r2  s          r  r0  zmexc.fetch_funding_rate  ss     	V$fTl
 ::4;;wPV;WX  626&&vv66r  c           
         |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   | j	                  | j                  ||            }| j                  |d      }| j                  |dg       }	g }
t        dt        |	            D ]r  }|	|   }| j                  |d      }| j                  |      }| j                  |d      }|
j                  ||| j                  |d	      || j                  |      d
       t | j                  |
d      }| j!                  ||d   ||      S )ad  
        fetches historical funding rate prices

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

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not used by mexc, but filtered internally by ccxt
        :param int [limit]: mexc limit is page_size default 20, maximum is 100
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        z5 fetchFundingRateHistory() requires a symbol argumentrF  r6   rq  r  r  r   r  r  )r   rF  r  r}  r  r}  )r'   r6   r  rh  #contractPublicGetFundingRateHistoryr  r  r*  r  r+  r  r	  rf  r0  r  sort_byfilter_by_symbol_since_limit)r  rF  r  rZ  r
  rh  r  r  r  r2  ratesr3  r  r  symbolInnerr}  sorteds                    r  fetch_funding_rate_historyzmexc.fetch_funding_rate_history  s[    >#DGG.e$effV$fTl

 #(GK ;;DKKQW<XY2 x0|R8q#f+& 	A1IE''x8H**84K))%>ILL%#//}E& LL3 	 e[1009I5RWXXr  c                     | j                          | j                  |ddd      }| j                  |      }| j                  |d      }| j	                  ||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
        rD   Tr  rF  )r  market_symbolsry  r  parse_leverage_tiersr  rE  r
  r  r  s        r  fetch_leverage_tierszmexc.fetch_leverage_tiers  s^     	%%gvtTB//7\ ~~h/((wAAr  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	d}
g }| j                  |d	      }|dk(  r=d
| j                  ||d d      | j                  |      d d d | j                  |d      |dgS t	        j
                  |
|      r
t	        j                  |
|      }|j                  | j                  t	        j                  ||            | j                  ||d d      | j                  |      | j                  |
      | j                  |      | j                  |      | j                  t	        j                  d|            |d       t	        j                  ||	      }t	        j                  ||      }|}
t	        j
                  |
|      r
|S )NrF  maintenanceMarginRateinitialMarginRaterw  riskIncrVolriskIncrMmrriskIncrImrro  rk  r   r   ru  )tierrF  r4  minNotionalmaxNotionalrB  ru  r   rJ  )
r+  r  r,  r0  r1   	string_ltr  rf  r  
string_div)r  r   rh  r  rB  rC  rw  rD  rE  rF  floortiersrT  caps                 r  parse_market_leverage_tiersz mexc.parse_market_leverage_tiers)  s   N ##D(3 $ 0 07N O ,,T3FG!!$1&&t];&&t];&&t];""45# "..xzR $ 7 7 @#'#'-1#'#3#3D-#H 	  v.$$UK8CLL))'*<*<S+*NO**8VT:N 33G<#007#005)-):):;P)Q#001C1CCIZ1[\	 	 !( 2 23Dk R$+$6$67Lk$Z!E v. r  r4  c                     | j                  |d      }| j                  |d      }| j                  |d      }| j                  |       || j                  ||      | j                  ||      || j                  |d      dS )Naddressr  r  memo)r   r4  r  rQ  tag)r+  check_addressr,  r.  )r  depositAddressr4  rQ  r  r8  s         r  parse_deposit_addresszmexc.parse_deposit_addressx  s     "">9=%%nf=
$$^Y?	7#"//
HE..y*E##NF;
 	
r  r&  c                 $   | j                          | j                  |      }d|d   i}| j                  |d      }d}|t| j                  ||      }| j	                  |di       }||v r9| j	                  ||i       }	| j                  |	di       }
| j                  |
d      }n| j                  ||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  |dd      }| j                  |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
        r  r6   r  Nr<  r   F)r  r4  r+  r.  r  r  network_code_to_idr  #spotPrivateGetCapitalDepositAddressr  parse_deposit_addressesindex_by)r  r&  r
  r4  r  networkCoder8  networkUnifiedr<  r  networkInfor  addressStructuress                r  "fetch_deposit_addresses_by_networkz'mexc.fetch_deposit_addresses_by_network  s&    	==&HTN
 &&vy9	"!44[$GN~~h
B?H)..>2F"oogvrB ,,[)D	 33KF	 !*GI69-;;DKKQW<XY !884O}}.	::r  c                 .   | j                          | j                  |      }d|d   i}| j                  |d      }|t        | j                  dz         d}| j                  ||      }| j                  |di       }||v r9| j                  ||i       }	| j                  |	di       }
| j                  |
d      }n| j                  ||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  ||      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>`
        r  r6   r  Nz4 createDepositAddress requires a `network` parameterr<  r   )r  r4  r+  r'   r6   r.  r  r  rX  r  $spotPrivatePostCapitalDepositAddressr  rV  )r  r&  r
  r4  r  r\  r8  r]  r<  r  r^  r  s               r  create_deposit_addresszmexc.create_deposit_address  s'    	==&HTN
 &&vy9#DGG.d$dee	00dC>>(J;X%nnX~rBG//'62>K((i@I//TBI !*GI69-<<T[[RX=YZ ))(H==r  c                    | j                  |d      }| j                  ||      }d}|#| j                  || j                  ||            }n| j                  | j                  d      }| j                  ||      }|| j                  ||      }n=t        |j                               }| j                  |d      }	| j                  ||	      }|$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  Nr;  r   z9 fetchDepositAddress() cannot find a deposit address for z, and networkzMconsider creating one using .createDepositAddress() method or in MEXC website)	r+  r`  r  r.  r   r  r  r+   r6   )
r  r&  r
  r  r_  r2  r   defaultNetworkForCurrencyr  keys
             r  fetch_deposit_addresszmexc.fetch_deposit_address  s    ""695 CCD&Q^^$5t7N7NwX\7]^FnnT\\3DEG(,(8(8$(G%(4(9;TU-2245&&tQ/(93?> +f!fim!mp!  CJ  "J  M\  "\  ]  ]r  c                 n   | j                          i }d}|M| j                  |      }|d   |d<   | j                  |d      }| | j                  |d      }|d   dz   |z   |d<   |||d<   ||dkD  rt	        d      ||d	<   | j                  | j                  ||            }| j                  ||||      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  r  r_  .This exchange supports a maximum limit of 1000rZ  )r  r4  r+  r  r#   "spotPrivateGetCapitalDepositHisrecr  parse_transactions)	r  r&  r  rZ  r
  r  r4  
rawNetworkr  s	            r  fetch_depositszmexc.fetch_deposits   s     	
 }}T*H&tnGFO ))&)<J%695")&/C"7*"D#(GK t|#$TUU$GG::4;;wPV;WX" &&x5%HHr  c                    | j                          i }d}|| j                  |      }|d   |d<   |||d<   ||dkD  rt        d      ||d<   | j                  | j	                  ||            }| j                  ||||      S )a2  
        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  r_  ri  rZ  )r  r4  r#   $spotPrivateGetCapitalWithdrawHistoryr  rk  )r  r&  r  rZ  r
  r  r4  r  s           r  fetch_withdrawalszmexc.fetch_withdrawals7  s     	
 }}T*H&tnGFO#(GK t|#$TUU$GG<<T[[RX=YZ( &&x5%HHr  transactionc                 *   | j                  |d      }|dnd}| j                  |dd      }d }| j                  |d      }||j                  d      d   }d }| j                  |d	      }	|	| j                  |	      }| j	                  ||      }
| j                  | j                  |d
      |      }| j                  |d      }| j                  |d      }| j                  |d      }d }| j                  |d      }|| j                  |      |
d}|dk(  rt        j                  ||      }i d|d|d|d|d| j                  |      d	|d|d|dd d| j                  |d      dd dd d|d| j                  |      d|
d
|dd d d |dS )Nr6   r\   
withdrawal
insertTime	applyTimer  r  r   r  r  r$  rQ  txIdtransactionFeer  r   txidr}  r  	addressToaddressFromrS  rR  tagTotagFromr'  r4  r  )commentinternalr!  )
r+  r  splitr.  r,   parse_transaction_status_by_typer  r1   
string_subr  )r  rq  r4  r6   r'  r}  r  currencyWithNetworkr  rl  r&  r  r  rQ  rx  r!  feeCostStrings                    r  parse_transactionzmexc.parse_transactionk  sT   R k40Zyl''\;O	
"..{FC*,2237:J%%k9=
!--j9G&&z8<66t7G7GU]7^`de''X>"";	:V4((6FG$))-8 C <"--lMJL
K
"
 D
 	

 Y/
 w
 w
 
 4
 4##K8
 T
 t
 D
 d''5
 
  f!
" t#
$ )
 	
r  c                 ~    ddddddddddddddddddd
d}| j                  ||i       }| j                  |||      S )Nfailedpendingr  )rJ  r  r  r  567r  )
rJ  r  r  r  r  r  r  8910)r\   rs  )r  r+  )r  r  r'  statusesByTyper  s        r  r  z%mexc.parse_transaction_status_by_type  ss       
. ??>4<&&99r  c                     | j                          | j                  |      }d|d   i}| j                  d| j                  ||            }| j	                  |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>`
        rF  r6   Nr   )r  rh  fetch_positionsr  r  )r  rF  r
  rh  r  r  s         r  fetch_positionzmexc.fetch_position  s^     	V$fTl
 ''dkk'6.JKx++r  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||      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>`
        r  )r  'contractPrivateGetPositionOpenPositionsr  parse_positionsr?  s        r  r  zmexc.fetch_positions  sG     	??G> ~~h3##D'22r  positionc                    | j                  | j                  |d      |      }|d   }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|dk(  rdnd}| j                  |d	      }	|	dk(  rd
nd}
| j                  |d      }| j                  |d      }| j                  |d      }| j	                  i d|dd d|d| j                  |      dd d|dd d|dd d| j                  |      dd d|
dd dd dd d|d| j                  |      d d d d || j                  |      d d d d d
      S )NrF  holdVolopenAvgPriceimr  rJ  longshortmargin_moder8  rN  rR  liquidatePrice
updateTimer   r6   	contractsr_  
entryPrice
collateralr  unrealizedPnlr   rH  notionalr!  r  liquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior}  r  rP  rL  rM  lastUpdateTimestamp)r  r+  r0  r	  safe_positionr  r  )r  r  rh  rF  r  r  r  rawSider  rO  
marginTyperR  r  r}  s                 r  parse_positionzmexc.parse_position  s
   z !!$"2"28X"FO!$$Xy9	%%h?
((48""8^<!S.vw##Hm<$,OZ'
##Hj9++H6FG%%h=	!! #
H#
$#
 f#
 **95	#

 D#
 *#
 $#
 D#
 T#
 ))(3#
 $#
 *#
 #
 #
 #
   0!#
" T..}=##
$ (,!%+/"Y/!##'7#
  	r  c                 ,   | j                  dd|      \  }}| j                          |dk(  rId|i}| j                  | j                  ||            }| j	                  |di       }| j                  |      S |dk(  rt        | j                  dz   |z         y)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  (spot2PrivateGetAssetInternalTransferInfor  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 DDT[[QXZ_E`aH >>(FB7D&&t,,6!TWW'OOR\\]]r  c                 0   | j                  dd|      \  }}| j                          i }d}d}	|| j                  |      }|d   |d<   |dk(  rf|||d<   ||dkD  rt        d      ||d	<   | j	                  | j                  ||            }
| j                  |
d
i       }| j                  |dg       }	nQ|dk(  rL|||d<   | j                  | j                  ||            }
| j                  |
d
      }| j                  |d      }	| j                  |	|||      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

        :param str code: unified currency code of the currency transferred
        :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
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        r   Nr6   r4  rB   rn  r;   z,This exchange supports a maximum limit of 50z	page-sizer  result_listrD   rq  r  )	r  r  r4  r#   *spot2PrivateGetAssetInternalTransferRecordr  r  'contractPrivateGetAccountTransferRecordparse_transfers)r  r&  r  rZ  r
  r  r  r  r4  r  r  r  s               r  fetch_transferszmexc.fetch_transfers  sI    !>>?OQUW]^
E
}}T*H"*4.GJ (-% 2:'(VWW',$FFt{{SZ\aGbcH( ??8VR8D}bAJ6! ',$CCDKKPWY^D_`H??8V4D|<J2 ##J%GGr  fromAccount	toAccountc                    | j                          | j                  |      }dddd}| j                  ||      }| j                  ||      }	|Ct        |j	                               }
t        | j                  dz   dj                  |
      z         |	Ct        |j	                               }
t        | j                  dz   dj                  |
      z         |d   |||	d	}|dk(  s|	dk(  rW| j                  |d
      }| j                  |d
      }|t        | j                  dz         | j                  |      }|d   |d
<   | j                  | j                  ||            }| j                  ||      }| j                  ||||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>`
        SPOTFUTURESISOLATED_MARGIN)rB   rD   rC   z fromAccount must be one of z, z toAccount must be one of r6   )r  r$  fromAccountTypetoAccountTyperF  z: transfer() requires a symbol argument for isolated margin)r$  r  r  )r  r4  r+  r  r  r#   r6   r  r  r'   rh  spotPrivatePostCapitalTransferr  r  )r  r&  r$  r  r  r
  r4  accountsfromIdtoIdr  r  rF  rh  r  rq  s                   r  r   zmexc.transfer  s    	==&'

 !!(K8)4>(D*H H499UY? Z[[<(D*F FSW XYYd^%!	
 ''T5F-F%%fh7FYYvx0F~'2n(noo[[(F &tGH66t{{7F7ST ))(H={{;&")
  	r  r   c                    | j                  |d      }| j                  |g d      }| j                  |d      }|| j                  |      nd }| j                  |d      }d }d }	||dk(  rdnd}|dk(  rdnd}	n$| j                  |d      }| j                  |d	      }	||||| j	                  ||      | j                  |d
      | j                  |      | j                  |	      | j                  | j                  |dd            d	S )Nr4  )r  rx  tranIdr  r'  INMAINCONTRACTfromtor$  transact_staterm  )	r   r6   r}  r  r4  r$  r  r  r  )	r+  safe_string_nr	  r  r,  r0  parse_account_idparse_transfer_statusr-  )
r  r   r4  r  r6   r}  r  	directionaccountFrom	accountTos
             r  r  zmexc.parse_transfer4  s$   @ %%h
;
*KL%%h=	/8/D4<<	*4$$Xv6		 %.$%6&ZK'0D'8
vI**8V<K((48I" //
HE&&x:00=..y9001C1CHN^`g1hi

 
	
r  c                 2    ddd}| j                  |||      S )NrB   rD   )r  r  r  r  s      r  r  zmexc.parse_account_idm  s&    
 &&99r  c                 4    dddd}| j                  |||      S )Nr  r  r  )SUCCESSFAILEDWAITr  r  s      r  r  zmexc.parse_transfer_statust  s)    

 &&99r  rQ  c                    | j                          | j                  |      }| j                  ||      \  }}| j                  | j                  di       }| j                  |dd      }| j                  |||      }| j                  ||d         }| j                  |       |d   ||d}	|||	d<   |||	d<   | j                  |ddg      }| j                  | j                  |	|            }
| j                  |
|      S )a  
        make a withdrawal

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

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r<  r  r  r&  r6   )r  rQ  r$  rR  )r  r4  handle_withdraw_tag_and_paramsr  r   r-  r+  rX  rT  r  spotPrivatePostCapitalWithdrawr  r  )r  r&  r$  rQ  rS  r
  r4  r<  r  r  r  s              r  r   zmexc.withdraw|  s    	==&99#vFV>>$,,
B?$$VY	B""8Wg>))'8F3CD7#TN

 ?!GFO!(GIYYv	9'=>F66t{{7F7ST %%h99r  rP  c                 X    d|rdndi}| j                  | j                  ||            }|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   )-contractPrivatePostPositionChangePositionModer  )r  rP  rF  r
  r  r  s         r  set_position_modezmexc.set_position_mode  s:     AQ
 EEdkkRY[aFbc r  c                 X    | j                  |      }| j                  |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
        r  r   )r   rP  )&contractPrivateGetPositionPositionModer	  )r  rF  r
  r  r  s        r  fetch_position_modezmexc.fetch_position_mode  s=     >>vF ((6:#q(
 	
r  codesc                 h    | j                          | j                  |      }| j                  ||      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>`
        )r  r)  parse_transaction_feesr  r  r
  r  s       r  fetch_transaction_feeszmexc.fetch_transaction_fees  s5     	99&A< **8U;;r  c                    i }t        dt        |            D ]f  }||   }| j                  |d      }| j                  |      }| j                  |d      }|| j	                  ||      sR| j                  ||      ||<   h |i |dS )Nr   r  r&  )r   r\   r   )r*  r  r+  safe_currencyin_arrayparse_transaction_fee)	r  r  r  withdrawFeesr3  r  r  r4  r&  s	            r  r  zmexc.parse_transaction_fees  s    q#h-( 	QAQKE))%8J))*5H##Hf5D4==u#=%)%?%?x%PT"	Q %
 	
r  c                     | j                  |dg       }i }t        dt        |            D ]P  }||   }| j                  |d      }| j                  | j                  d   ||      }| j                  |d      }	|	||<   R |S )Nr  r   r  r<  r  )r  r*  r  r+  r   r0  )
r  rq  r4  r  r2  r6  networkEntryr8  r\  r!  s
             r  r  zmexc.parse_transaction_fee  s    6 ook="Eq#k*+ 	&A&q>L((yAI**4<<
+CYPYZK""<?C"%F;	& r  c                 j    | j                          | j                  |      }| j                  ||d      S )r  r  )r  r)  parse_deposit_withdraw_feesr  s       r  fetch_deposit_withdraw_feesz mexc.fetch_deposit_withdraw_fees1  s7     	99&A< //%HHr  c                 T   | j                  |dg       }| j                  |      }t        dt        |            D ]\  }||   }| j	                  |d      }| j                  || j	                  |d            }| j                  |d      d dd d dd|d   |<   ^ | j                  |      S )	Nr  r   r  r&  r  )r!  r   )r   r\   r<  )r  deposit_withdraw_feer*  r  r+  r.  r0  $assign_default_deposit_withdraw_fees)	r  r!  r4  r  r2  r6  r  r8  r\  s	            r  parse_deposit_withdraw_feezmexc.parse_deposit_withdraw_fee\  s    6 ooc="=**3/q#k*+ 	A&q>L((yAI11)T=M=MhX^=_`K  ++L-H"&
  "&	/F:{+		 88@@r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||      S )ag  
        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>`
        rF  r6   r  )r  rh  "contractPrivateGetPositionLeverager  r  parse_leverager  s          r  fetch_leveragezmexc.fetch_leverage  ss     	V$fTl
 ::4;;wPV;WX> ~~h3""400r  c                    d }d }d }t        dt        |            D ]c  }||   }| j                  |d      }| j                  |d      }	|	dk(  r| j                  |d      }n|	dk(  r| j                  |d      }|dk(  rdnd}e ||d	   |||d
S )Nr   rO  r  r   rR  r   r8  rN  rF  )r   rF  rH  longLeverageshortLeverage)r*  r  r	  )
r  rR  rh  rH  r  r  r3  r  rO  r  s
             r  r  zmexc.parse_leverage  s    
q#h-( 	DAQKE((
;H,,UNCLq #00
C" $ 1 1% D(0AGJ	D X&$(*
 	
r  c                     | j                  | j                  d      }| j                  |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
        r9  rC   FNTr8  )r+  r   r/  r  r3   r0  )r  
methodNamer
  defaultValuer9  r  rH  r  s          r  r0  z"mexc.handle_margin_mode_and_params  sm     &&t||]C>>&(E:
"4LZY_amn
F8#T)9#JF##r  c                 B   | j                          i }|,t        |      }|dk(  r| j                  |d         }|d   |d<   |||d<   | j                  | j	                  ||            }| j                  |d      }	| j                  |	||      }
| j                  |
||      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>`
        r   r   r6   rF  rq  r  )r  r  rh  .contractPrivateGetPositionListHistoryPositionsr  r  r  filter_by_since_limit)r  rE  r  rZ  r
  r  symbolsLengthrh  r  r  	positionss              r  fetch_positions_historyzmexc.fetch_positions_history  s      	LM!WQZ0$*4L!#(GK FFt{{SZ\bGcdR ~~h/((w?	)))UEBBr  rH  c                 2   | j                          | j                  |      }|d   rt        | j                  dz         |j	                         }|dk7  r|dk7  rt        | j                  dz         | j                  |d      }|t        | j                  dz         | j                  |dd	      }||dk(  rd
ndd}||d   |d<   ||dk(  rdnd
|d<   | j                  |d      }| j                  | j                  ||            }| j                  ||      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
        rB   z/ setMarginMode() supports contract markets onlyr8  rN  z@ setMarginMode() marginMode argument should be isolated or crossrR  z. setMarginMode() requires a leverage parameterr  r  r   r   )rR  rO  r6   rF  r  r  )r  rh  r)   r6   lowerr(   r	  r'   safe_string_lower_2r  r  r  r  )	r  rH  rF  r
  rh  rR  r  r  r  s	            r  set_margin_modezmexc.set_margin_mode%  s3    	V$&>DGG&WWXX%%'
#
g(=TWW'iijj$$VZ8#DGG.^$^__,,V[,O	 (J6Q
  &tGH ,5,@aqGN#6;/AA$++gW]B^_ ""8V44r  c                 ^    | j                         | j                  | j                  dd      z
  S )Nr7  r   )r  r	  r   )r  s    r  r  z
mexc.nonceL  s+      "T%6%6t||EUWX%YYYr  r   GETc                    | j                  |d      }| j                  |d      }| j                  ||      \  }}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(  rO|d	k(  s
|d
k(  s|dk(  r@| j	                         | j                  | j                  dd      d}
| j                  |      }n3| j	                         |
d<   | j                  | j                  dd      |
d<   d}|
r| j                  |
      }|	d|z   z  }	|dk(  r| j                          | j                  | j                  |      | j                  | j                        t        j                        }|	d|z   z  }	| j                  | j                  | j                  dd      d}|d	k(  s|d
k(  s|dk(  r}d|d<   nv|dk(  s|dk(  rk| j                  d   |   |   dz   | j!                  ||      z   }	| j#                  || j%                  |            }|dk(  r|r|	d| j                  |      z   z  }	n| j                          t'        | j	                               }d}| j                  |d| j                  | j                  dd      d}|d	k(  r| j                  |      }|}n/| j)                  |      }|r|| j                  |      z  }|	d|z   z  }	| j                  |z   |z   }| j                  | j                  |      | j                  | j                        t        j                        }||d<   |	|||dS )Nr   r   rB   r   r   rO  z/api/r   POSTPUTDELETEr>  r4  )r}  r>  r}  r  ?z&signature=r5  )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
  r  r  sectionaccessr  	urlParamsparamsEncoded	signaturer}  auths                  r  signz	mexc.signO  sl   ""3*!!#q)((v6ff8 3("ii&w/7#=Dii&w/7'ADLLPSVVY]]I"h&Vv-=6U?X^bjXj%)ZZ\&*&7&7lTX&Y!I  99V,D-1ZZ\Ik*.2.?.?l\`.aIl+M $y 9s]**"//1 IIdkk-&@$++dkkBZ\c\j\jk	)I55%)[["..t||XvN & fo6X;M*<'
"g&8))E"7+F3c9D<O<OPTV\<]]CYYvt':':4'@AF!3!777C//1

-	"kk$-$6"..t||XvN	 V#99V,DD!\\&1Fv 66sTz){{Y.5 IIdkk$&7T[[9QSZSaSab	'0$fdwOOr  reasonr  r  r  r  c
                 2   |y | j                  |dd      }
|
du ry | j                  |dd       }|g|dk7  rb|dk7  r]| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d	   ||       t        |      y )
Nr  FTr&  200ro   r  r  )r/  r+  r6   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr#   )r  r&  r*  r  r  r  r  r  requestHeadersrequestBodyr  responseCodefeedbacks                r  handle_errorszmexc.handle_errors  s     ..9e<d?''&$?$<5+@|WZGZww}t+H001I4QYZ001I<Yab))r  )r   r   r   )N)NNNNNNN)__name__
__module____qualname__r   r  r  r   r  r   r9  r"   r   rC  r<  r=  r  r   r  r   r  r   r  dictr  r  r  r  r  r   r   r  r   r  r  r%  rW  r,  r.  r   r   r   r)  rG  r1  r2  r   re  r   rl  r   rz  r  r  r  r  r  r  r  r  rL  r  r  r  r  r  r  r   r  r   r  r   r  r  r  r   r  r  r   r  r  r  r  r   r.  r1  r0  r;  r   r@  r   rO  r	   r
   rV  r`  rc  rg  r    rm  rp  r  r  r  r   r  r  r!   r  r  r   r  r  r  r   boolr  r  r  r  r  r  r  r   r  r  r0  r  r	  r  r)  intr4  __classcell__)r  s   @r  r3   r3      s%
   q# qf #% #
J !# s 4 ') eZ eN $& 9$v, 9" )+ zx )+ zx :>b >s >3 >Y >@i 	 en  6:UW ]?3 ]?s ]?# ]?\`af\g ]?~H Hv H HT" 26DW[df aK# aKc aKQT aKkoptku aKF
 
4 
 04B S4W S47 S4j 02 G13 G1f G1Ro4 o o6 ob 26b %4w %4N RT ] ]5 ]( SU ^ ^E ^( gksu "`3 "`i "`y "`RW "``c "`H KO[_hj -,^ CGSW`b 4l CGSW`b |5| @B 9+D$6 9+v 26b s.c s.3 s.j *.Dt\^ sK3 sKc sK sKcghmcn sKj 6:" 03s 03d /3TXac UO UO3 UOc UOhlmrhs UOn 154VZce K# KS KPS Kjnotju K  37TX\eg KC Ks KRU K  :>D_cln Y3 Yc YY\ Y 37r i.s i.C i.V 04B  3  3D /32 V3 V3p^ ^v ^ ^@:	:: : :@S @4l %' 4= 8 57 %
 %
;N %
Nf-H f-P $& }?( }?~ -1tRV_a X?c X? X?C X?t 9=4^bkm KFS KF# KFS KFX[ KFZ MO 3 $ @B HC H HFX H =? H He HCU H 9=R \S \# \< 37TX\eg IC Is IRU IV(
6 (
[ (
T :< 
7S 
7 
7 68  7  7K  7D 8<$]ajl @Y @YC @YWZ @YD 7;2 ;BG ;B- ;BzM M$|J\ M^
h 
R` 
* DF +;s +;$~J^ +;Z 8: '>3 '>n '>R 79 # ^ : *.Dt\^ 5I3 5Ic 5I 5Icghsct 5In -1tRV_a 2Ic 2I 2IC 2Ifjkvfw 2IhX
T X
X X
Q\ X
t:6 24 ,S ,$ 26b +3w +3T(^ +3Zet eV eN 37r # #C #m #J +/TPT]_ PHC PHs PH# PHdhivdw PHd [] 5S 5% 5c 5c 5an 5n7
t 7
x 7
= 7
r::C :C : DHPR %:S %:% %:# %:Wb %:N =A  c . 15R 
# 
0 7;2 )<G )<V
#8 #J <@ )I )IV+A +AZ 24 /1S /1 /1b
t 
V 
x 
* @BPT $  :>D_cln DCw DCc DCY\ DCsw  yA  tB DCL >B" %5# %5s %5NZ &eBSW >P@# s  c TX `c r  r3   )8ccxt.base.exchanger   ccxt.abstract.mexcr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   typingr"   ccxt.base.errorsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   ccxt.base.decimal_to_precisionr0   ccxt.base.preciser1   r3    r  r  <module>rD     s    ( *  U  U  U  U  U  U  U  U  * 0 - - . ' & . + ) ) * ) 4 %IZ8[ IZr  