
    ih                    h   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 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m*Z* d dlm+Z+ d dlm,Z, d dl-m.Z. d dl/m0Z0  G d dee          Z1dS )    )Exchange)ImplicitAPIN)AccountBalances
CurrenciesCurrency	IndexTypeIntLeverageMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)NotSupported)OnMaintenance)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi 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dvdededefdZd	d	i fd
edededee         fdZdwde	defdZdxdZdd	d	i fd
edededee         fdZdwd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dwde	defdZd	i f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.Z-d	d	d	i fd
e,dededee.         fd/Z/d	i fd
e,fd0Z0d	d	d	i fd
e,dededee.         fd1Z1d	d	d	i fd
e,dededee.         fd2Z2d	d	d	i fd
e,dedefd3Z3d	d	d	i fd
e,dedefd4Z4d	i fd-ed
e,fd5Z5d	i fd
e,fd6Z6d	i fd
e,fd7Z7dwde	de.fd8Z8d9 Z9d: Z:d; Z;d< Z<d= Z=i fdee>         fd>Z?i fde@fd?ZAdeBfd@ZCdA ZDi fdeBfdBZEd	d	d	i fd
e,dedefdCZFd	d	d	i fd-ed
e,dedefdDZGi fd
efdEZHi fd
edeIfdFZJi fd
edeIfdGZKd	i fdHed
e,fdIZLd	d	d	i fd
e,dedefdJZMdwde	fdKZNi fd
efdLZOd	d	d	i fd
e,dedefdMZPd	i fdefdNZQdwde	fdOZRdwdPeSfdQZTi fdRefdSZUi fdRefdTZVi fdRefdUZWd	d	d	i fdRe,dededeeX         fdVZYd	d	d	i fdRe,dededeeX         fdWZZdwdPeSdeXfdXZ[dwdYZ\i fd
efdZZ]d	i fdefd[Z^dwde	fd\Z_d	d	i fd-ededefd]Z`d	d	d	i fdRe,dedefd^Zai fdRed%e!d_ed`edebf
daZcdwdPeSfdbZddc Zedd Zfd	i fdRed%e!fdeZgd	i fdfehd
e,fdgZid	i fd
e,fdhZjd	i fdiee         fdjZkdwdkZldwdPeSfdlZmd	i fdiefdmZndwdPeSfdnZoi fd
edepfdoZqdwdepfdpZri d	f fdq	Zsdrdsi d	d	fdtZtdu Zu xZvS )ymexcc                    |                      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d5d6d7dd8dd9dd:dd;d d<dd=dd>dd?dd@d dAd dBddCdi dDddEddFddGd dHddIddJddKddLd dMddNddOddPd dQddRddSddTdi dUddVd dWddXddYddZdd[dd\dd]d d^dd_d d`d6daddbd dcddddded dddddd dd d ddf
dgdhdididjdkdkdjdldmdjdndoidpdqdrgdsgdtdudvdwdxdxdydxdzdxdxdxdxdxdxdxdxd{ii d|d}d~dddyddyddyddxddxddyddxddxddyddyddxddxddxddxddxi ddxddxddxddxddxddxddxddxddxddxddxddxddxddxddxddxddxdxdxdxdxdxdxdxddxdxdxdxdxdxdydxdxdxdxdxdydxdxdddxidxdxdxdxdxdxdddjdwi 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}d}d}d}dȜi dd}dd}dd}dd}ddΓdd}dd}dd}dd}dd}dd}dd}dd}dd}dd}dd}dڜdjdwdxd}dxd}dxdxdxdxd}dۜ	idxdxdxdxdxdxd}d}d}d}dydydyd}dܜdxdxdxd}dydݜdxdxd}dޜdߜdjdndxdxdxdxdxdxddxdxdxdxdxdxdddxidߜiddt          dddddddddddd
dddd|                     d          |                     d          diddddddddddddiddddddddddddddd ddddd
ddddddddd	i d
d
dddddddddddddddddddddddddddd d!d"d#d$i d%d&d'd(d)d*d+d+d,d,d-d.d/d0d1d1d2d2d3d4d5d5d6d7d8d9dd:d;d<d=d=d>d>i d?d@dAdBdCdCdDdEdFdGdHdHdIdIdJdKdLdLdMdNdOdPdQdRdSdTdUdUdVdVdWdWddXi dYdZd[d\d]d]d^d^d_d_d`d`dadadbdbdcdcdddedfdfdgdgdhdhdidjdkdkdldmdndni dodpdqdrdsdsdtdtdududvdvdwdwdxdydzdzd{d{d|d|d}d~ddddddddddi ddddddddddddddddddddddddddddddddddi dddd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ȓ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ddddddi d(d'ddddddddd$d#d&d%d7d6d*d)d9d8d:dddd.d-dd6dd6d0d6ddi dĐdÓd֐dՓdBdAd@d?dEdDd"d!dKdJdPdOdTdSdNdMdddZdYdXddedddjdidrdqdpdoi dydxd~d}dddddddddܐdۓdddddސdݓdddddRdQddddddddddddِddƐdɐdːd͐dϐdߐdddddddi dddddddddddd dddddddddddd	d
ddddddddddddddi dt          dt          dt          dt          dt          dt          dt          dt          dt          d t          d!t          d"t          d#t          d$t          d%t          d&t          d't          i d(t          d)t          d*t          d+t          d,t          d-t          d.t          d/t          d0t          d1t          d2t          d3t          d4t          d5t          d6t          d7t          d8t          i d9t          d:t          d;t          d<t          d=t          d>t          d?t          d@t          dAt          dBt          dCt          dDt          dEt          dFt          dGt          dHt          dIt          i dJt          dKt          dLt          dMt          dNt          dOt          dPt          dQt          dRt          dSt          dTt          dUt          dVt          dWt          dXt          dYt          dZt          i d[t          d\t          d]t          d^t          d_t          d`t          dat          dbt          dct          ddt          det          dft          dgt          dht          dit          djt          dkt          t          t          t          t          t          t          t          t          t          t          t          t          t          dlt          t          t          t          t          t          t          t          t          t          t          dmdn          S (o  Nidr-   namezMEXC Global	countriesSC	rateLimit2   versionv3	certifiedTprohasCORSspotmarginswapfutureFoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateReduceOnlyOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL2OrderBookfetchLedgerfetchLedgerEntryfetchLeveragefetchLeveragesfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionModefetchPositions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)r;   spot2contractbrokerzhttps://www.mexc.com/z&https://mexcdevelop.github.io/apidocs/zhttps://www.mexc.com/feez/https://m.mexc.com/auth/signup?inviteCode=1FQ1G)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sub-account/listsub-account/apiKeyzcapital/config/getallzcapital/deposit/hisreczcapital/withdraw/historyzcapital/withdraw/addresscapital/deposit/addresscapital/transferzcapital/transfer/tranIdcapital/transfer/internal%capital/sub-account/universalTransfer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/taxQueryzrebate/detail)zrebate/detail/kickbackzrebate/referCodezrebate/affiliate/commissionzrebate/affiliate/withdrawz"rebate/affiliate/commission/detailmxDeduct/enableuserDataStream)r   z
order/testsub-account/virtualSubAccountr   sub-account/futureszsub-account/marginbatchOrderscapital/withdraw/applyr   r   r   r   r   r   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   )r;   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options)zBTC/USDT:USDTzLTC/USDT:USDTzETH/USDT:USDTtypes)linearinverse)r;   r=   60m)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   ABBCACAACALAADAzCardano(ADA)AEALGOzAlgorand(ALGO)ALPHzAlephium(ALPH)AMEAOKAPTz
APTOS(APT)ARARBzArbitrum One(ARB)ARBNOVAARBONEzArbitrumOne(ARB)ARKASTRASTARATOMzCosmos(ATOM)AVAXCzAvalanche C Chain(AVAX CCHAIN)AVAXXzAvalanche X Chain(AVAX XCHAIN)AZEROzAleph Zero(AZERO)BCHzBitcoin Cash(BCH)BDXBEAMBEP2zBNB Beacon Chain(BEP2)BEP20zBNB Smart Chain(BEP20)BITCIBNCBNCDOTBNCPOLKABOBABSCz
BEP20(BSC)BSVzBitcoin SV(BSV)zBitcoin(BTC)BTMBTM2CELOCFXCHZzChiliz Legacy Chain(CHZ)CHZ2zChiliz Chain(CHZ2)CKBCLOREzClore.ai(CLORE)CRC20CRONOSCSPRDASHDCzDogechain(DC)DCRDNXz
Dynex(DNX)DOGEzDogecoin(DOGE)DOTzPolkadot(DOT)DYMzDymension(DYM)EDGEGLDEOSzEthereum(ERC20)ETCzEthereum Classic(ETC)ETHFETFETHWEVERFETFILFIOFLOWFSNFTMzFantom(FTM)FUSEGLMRGRINHBARzHedera(HBAR)HIVEHRC20HECOHYDRAICPzInternet Computer(ICP)INDEXzIndex ChainIOSTIOTAIOTXIRISKARKASz
Kaspa(KAS)KAVAKDAKILTKLAYzKlaytn(KLAY)KMAKSMLATLAVAzElysium(LAVA)zLitecoin(LTC)LUNATerra(LUNA)MASSMATICzPolygon(MATIC)MCOINzMcoin NetworkMETISMINAMNTzMantle(MNT)MOVRMTRGzMeter(MTRG)NASNEARzNEAR Protocol(NEAR)NEBLNEMNEONEO3NEOXAzNeoxa NetworkNULSOASISROSEOASYSOKCOKTOMNzOmega Network(OMN)OMNIONEONTOPTIMISMzOptimism(OP)OSMOPLCUPOKTQKCQTUMRAP20zRAP20(Rangers Mainnet)REIRSKRBTCRVNzRavencoin(RVN)SATOXSatoxcoin(SATOX)SCRTSDNSGBSOLSolana(SOL)STARSTARKStarknet(STARK)STEEMSYSTAOzBittensor(TAO)TIAzCelestia(TIA)TOMOTONToncoin(TON)TRC10TRC20Tron(TRC20)UGASUGAS(Ultrain)VETVeChain(VET)VEXVexanium(VEX)VSYSWAVESWAXWEMIXXCHz	Chia(XCH)XDCXECXLMStellar(XLM)XMRzMonero(XMR)XNAzNeurai(XNA)XPRXPR NetworkXRDXRPzRipple(XRP)XTZXVGXYMZECZENZilliqa(ZIL)ZTG)r  r  r  ZILr  zBNB Smart Chain(BEP20-RACAV1)zBNB Smart Chain(BEP20-RACAV2)r  )r}  r  r  r  rW  r  r  r  r  r  r  r    l   W CCXT)!createMarketBuyOrderRequiresPriceunavailableContractsrr   r   defaultTypedefaultNetworkdefaultNetworksnetworksnetworksById
recvWindowmaxTimeTillEndr   commonCurrenciesBEYONDPROTOCOLBEYONDBIFIBIFIFBYNBeyondFiCOFICOFIXDFI
DfiStarterDFTdFutureDRKEGCzEgoras CreditFLUX1FLUXFREEFreeRossDAOGASGASDAOGASNEOGMTz	GMT TokenSTEPNHEROz	Step HeroMIMOMimosazPros.FinancezSin City Tokenz	Soul Swap)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superr-   describer*   parse_numberr"   r#   r$   r&   r   r   r)   r   r    r(   )self	__class__s    O/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/mexc.pyr<  zmexc.describe   s    dD 1 1 : : < < R?
&R?
MR?
 $R?
 	R?

 tR?
 R?
 4R?
  ``` $` 	`
 %` %` T` "4` t` ` $U`  ` '` /` ,U`  0!`" t#` `$ %`& &t'`( ()`* 4+`, T-`.  /`0 1`2  3`4 )$5`6 &t7`8 #D9`: $T;`< '=`> (?`@ "4A`B C`D &tE` ` `F (G`H 1$I`J  K`L *:M`N +DO`P &tQ`R #DS`T *4U`V $TW`X "4Y`Z *5[`\ +E]`^ #D_`` ta`b #Dc`d  e`f !%g` ` `h %di`j /k`l "5m`n +Do`p q`r !$s`t  u`v dw`x !$y`z "4{`| d}`~ !$`@ "4A`B tC`D #DE`F  G`H $TI` ` `J !$K`L %dM`N )%O`P tQ`R tS`T U`V TW`X tY`Z "4[`\ #D]`^ %d_`` &za`b 'c`d $Te`f  g`h !$i`j "4k` `l %) $$)',#!%#'  ` ` `R?
R ~ #9#9 
 #E#E 
 #N#M! !
 "#G " /< / N5 SR?
J  $%$%,.%&&'01)*&'()+,,-12()   $* #Q* (!*  (*  &r	* 
 '*  /*  1!*  4R*  5a*  7*  7*  6r*  /*  6q*  8*   DQ!* " .q#*  * $ 3A%* & *1'* ( /)* * .q+* , 0-* . 5a/* 0 01* 2 +A3* 4 6q5* 6 3A7* 8 +A9* : 3A;* < 9!=* > 8?* @ 8A* B .qC* D ,QE*  * F 7801;<9:BC/0./S*  *  * X &'*+=>233423+-67019:78EF/1/0./! !$ -a  &'*+23,-12./# #AH  H %[ [|   "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!##   Ua aKR?
N YOR?
P  QR?
h !&"&!..w77!..w77	 iR?
x 59%)%)%)) )  $&*',! ! ! #"$$#"""	 	 %$&&%%%$%&  0  &"' ##  $ $HFH7H >H $	H
 ,H ,H 5H 5H <H $H .H yH 0H 5H GH  N!H" =#H H$ =%H& 0'H( .)H* 5+H, F-H. 4/H0 51H2 W3H4 55H6 j7H8 F9H: <;H< ,=H> >?H@ 6AHB FCHD 5EH H HF 5GHH 0IHJ 5KHL .MHN XOHP FQHR FSHT /UHV 5WHX <YHZ ,[H\ ?]H^ +_H` 5aHb FcHd 5eHf .gH H Hh 2iHj EkHl FmHn FoHp 5qHr 5sHt 5uHv FwHx 5yHz ={H| F}H~ FH@ FAHB NCHD FEHF VGHH WIH H HJ 3KHL ]MHN FOHP FQHR FSHT FUHV 5WHX <YHZ F[H\ 5]H^ F_H` NaHb 5cHd 5eHf 5gHh OiHj ?kH H Hl MmHn FoHp -qHr _sHt WuHv FwHx =yHz F{H| M}H~ 5H@ 1AHB FCHD 5EHF 5GHH FIHJ _KHL FMH H HN VOHP WQHR 5SHT /UHV FWHX 5YHZ 5[H\ ]H^ F_H` FaHb FcHd 5eHf FgHh 5iHj 5kHl 6mHn +oH H Hp /qHr $sHt FuHv 5wHx 5yHz ={H| F}H~ .H@ WAHB 5CHD +EHF ?GHH FIHJ >KHL WMHN ]OHP OQH H HR >SHT ?UHV FWHX WYHZ 5[H\ W]H^ ;_H` 5aHb 5cHd >eHf =gHh =iHj =kHl 5mHn =oHp 5qHr 5sH Ht !  ) }H H HRL!'L!$fL! %fL! !%	L!
 (L! 5gL! 5gL! !%L! (L! &uL! #EL! %eL! -fL! 4UL! 4UL!  -e!L!" #E#L! L!$ $U%L!&  'L!( )&)L!* /+L!, &w-L!. #F/L!0 $T1L!2 %f3L!4 %e5L!6 !%7L!8 $V9L!: ,U;L!< &w=L!> "5?L!@ #FAL!B "7CL!D -eEL! L! L!F !%GL!H #FIL!J $UKL!L "5ML!N $WOL!P "6QL!R "5SL!T *6UL!V $WWL!X "5YL!Z )%[L!\ #J]L!^ $U_L!` %gaL!b -gcL!d %eeL!f "5gL! L!h )0#('.$)#)$)#*%+$)%*#($)L! L! L!Z '"7 SJ JyR?
N  ! (!! z! 	!
 |! y! u! ! ! ! ! x! %! {! !  !!" #!$ ''#)! ! !OR?
z 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. ./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 e 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 e 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 e 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 ep )(((((((((((1Ie e eN DNBL4>7C 1->->?K'0$.#0 Ot t{R?
 R R R	    c                    |                      dd|          \  }}d}d}d}|dk    r_|                     |          }t          |                                          }t	          |          }|r|                     |          nd}n^|dk    rX|                     |          }|                     |d          rdn|                     |          }|                     |d          }||dd|dS )	a  
        the latest known information on the availability of the exchange API
        :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   Nr;   okr=   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responserF  rG  rN  lengths	            r@  fetch_statuszmexc.fetch_status  s	    !>>}dTZ[[
E--e44H ((DYYF,2<TYYx(((FF6!!11%88H "__XyAAZTTtyyQYGZGZF''&99G
 
 	
rA  c                    |                      dd|          \  }}d}|dk    r+|                     |          }|                     |d          S |dk    r+|                     |          }|                     |d          S dS )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        r   Nr;   
serverTimer=   rE  )rK  spotPublicGetTimerS  rQ  )r>  rT  rU  rV  rW  s        r@  
fetch_timezmexc.fetch_time  s     !>>{DRXYY
E--e44H $$X|<<<6!!11%88H $$Xv666trA  returnc                    |                      d          sdS |                     |          }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }d}	d}
d}d}d}d}i }|                     |dg           }t          dt          |                    D ]
}||         }|                     |d          }|                     |          }|                     |dd          }|                     |d	d          }|o|}|p|	}	|                     |d
          }|                     |d          }||n|}||n|}| 	                    |d          }|
|n|
}
t          j        ||          r|}t          j        ||          r|}|rd}|rd}|||||||dd||did	||<   t          |                                          }t          |          }|dk    sd|v r$|                     |d|dz
            }||d         }
|||||	|||
dddd||dd|d||<   |S )a4  
        fetches all available currencies on an exchange
        :see: 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   coinr0   networkListnetworkdepositEnablewithdrawEnablewithdrawMinwithdrawMaxwithdrawFeeTr   minmax)	rJ  r/   rb  activerN   r   fee	precisionlimitsr   NONErl  )amountr   )rJ  r/   coder0   rk  rN   r   rl  rm  rn  r  )check_required_credentials!spotPrivateGetCapitalConfigGetallrangerO  safe_stringsafe_currency_coderR  network_id_to_code	safe_boolsafe_numberr+   	string_gt	string_ltrM  rN  safe_value_2)r>  rT  rW  resulticurrencyr/   rq  r0   currencyActivecurrencyFeecurrencyWithdrawMincurrencyWithdrawMaxdepositEnabledwithdrawEnabledr  chainsjchain	networkIdrb  isDepositEnabledisWithdrawEnabledrk  re  rf  rl  networkKeysnetworkKeysLengthr  s                                 r@  fetch_currencieszmexc.fetch_currencies  s?    ..u55 	499&AAN q#h--(( N	 N	A{H!!(F33B**2..D##Hf55D"NK"&"&"N#OH__X}bAAF1c&kk** % %q	 ,,UI>>	11)<<#'>>%%#P#P $(NN5:JE$R$R!*@/@!'!9>"..umDD"..umDD6I6QkkXk#6I6QkkXk#&&um<<&1&9cc$%8+FF 6*5'$%8+FF 6*5'# *%)N$ +&*O!#&$/ 1!%"#.#.% %% %!!  x}}//K #K 0 0!Q&&Fh,>,>!%!2!28VEVYZEZ![![!-"0"7K ()+"!  $# 
  32! !	 	 %) F4LL, rA  c                     |                      |          }|                     |          }|                     ||          S )z
        retrieves data on all markets for mexc
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )fetch_spot_marketsfetch_swap_marketsarray_concat)r>  rT  
spotMarket
swapMarkets       r@  fetch_marketszmexc.fetch_marketsp  s@     ,,V44
,,V44
  Z888rA  c                    |                      |          }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|                     |d          }|                     |d          }d}|d	k    r|rd
}|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                    i d|d|
dz   |z   d|
d|dd d|d|	dd dddd
d|ddddddd|dddd d ||d d d d d |                     | 	                    |                     |d                               |                     | 	                    |                     |d!                              d"d d d#|                     |d$          d d#d d d#|                     |d%          |d#d&d |d'           |S )(Nsymbolsr   symbol	baseAsset
quoteAssetrF  isSpotTradingAllowedFENABLEDTisMarginTradingAllowedmakerCommissiontakerCommissionmaxQuoteAmountr/   /basequotesettlebaseIdquoteIdsettleIdtyper;   r<   r=   r>   r?   rk  r   r   baseAssetPrecisionquoteAssetPrecisionrp  pricerh  baseSizePrecisionquoteAmountPrecisionleveragerp  r  costr   r   r   contractSizeexpiryexpiryDatetimestrike
optionTyperm  rn  createdrJ  )
spotPublicGetExchangeInforR  rt  rO  ru  rv  ry  appendr=  parse_precision)r>  rT  rW  rE  r}  r~  marketr/   r  r  r  r  rF  r  rk  r  r  r  r  s                      r@  r  zmexc.fetch_spot_marketsz  si   11&99V xB77q#d))$$ B	 B	A!WF!!&(33B%%fk::F&&v|<<G**622D++G44E%%fh77F#'??6;Q#R#R F)##*>#%)__V=U%V%V""..v7HIIO"..v7HIIO!--f6FGGNMM 2b2$*u,2 2 	2
 $2 &2 72 D2 2 2 02 2 %2 %2 &2  E!2" $#2$  (( $"&""//0D0DTEUEUV\^rEsEs0t0tuu!..t/C/CDDTDTU[]rDsDs/t/tuu   $#! !
  $//8KLL# 
  $# 
  $//8NOO-  $  c2 2 2 2 2 2 2f rA  c                 n   |                      |          }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |          }|                     |	          }|                     |
          }|                     |d          }|                    i d|d|d	z   |z   d
z   |z   d|d|d|d|d|	d|
ddddddddddddd|dk    ddddd|                     |d          |                     |d          |                     |d          d d d d |                     |d           |                     |d!          d"|                     |d#          |                     |d$          d%|                     |d&          |                     |d'          d%d d d%d d d%d(d |d)           |S )*NrE  r   r  baseCoin	quoteCoin
settleCoinstater/   r  :r  r  r  r  r  r  r  r=   r;   Fr<   Tr>   r?   rk  0r   r   takerFeeRatemakerFeeRater  volUnit	priceUnitr  minLeveragemaxLeveragerh  minVolmaxVolr  r  )contractPublicGetDetailrR  rt  rO  ru  rv  r  ry  )r>  rT  rW  rE  r}  r~  r  r/   r  r  r  r  r  r  r  s                  r@  r  zmexc.fetch_swap_markets  s'   //77Z x44q#d))$$ <	 <	A!WF!!&(33B%%fj99F&&v{;;G''==H**622D++G44E,,X66F$$VW55EMM 2b2$*u,s2V;2 2 	2
 &2 &2 72 H2 2 2 %2 2 %2 %2 5C<2  D!2" $#2$ !))&.AA))&.AA $ 0 0 H H"&""..vyAA!--fkBB   $//FF#//FF! !
  $//AA#//AA 
  $# 
  $#  $  c2 2 2 2 2 2 2f rA  Nr  limitc                    |                                   |                     |          }d|d         i}|||d<   d}|d         rp|                     |                     ||                    }|                     |d          }|                     |||          }|                     |d          |d<   n|d	         r|                     |                     ||                    }|                     |d
          }	|                     |	d          }
|                     |	||
          }|                     |	d          |d<   |S )a  
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#order-book
        :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-contract-s-depth-information
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  r/   Nr  r;   	timestamplastUpdateIdnoncer=   rE  r5   )load_marketsr  spotPublicGetDepthextendrS  parse_order_bookcontractPublicGetDepthSymbolrR  )r>  r  r  rT  r  request	orderbookrW  spotTimestamprE  r  s              r@  fetch_order_bookzmexc.fetch_order_book\  sV    	V$$fTl
 $GG	&> )	D..t{{7F/K/KLLH !--hDDM--hNNI!%!2!28^!L!LIgF^ 	D88Wf9U9UVVH& ??8V44D))$<<I--dFIFFI!%!2!24!C!CIgrA  r   r   r   priceKey	amountKeycountOrIdKeyc                     d}|                      ||          }|                      ||          }|                      ||          }||||gS ||gS )Nr   )ry  )	r>  bidaskr  r  r  countKeyr  rp  counts	            r@  parse_bid_askzmexc.parse_bid_ask  sc      22!!&)44  2265))vrA  sincec                    |                                   |                     |          }d|d         i}|||d<   d}|d         rI|                     |g d          }|||d<   |t          | j        dz             ||t          | j        d	z             ||d
<   |                     | j        dd          }	|                     |d|	          }	|                     |dg          }|	dk    r*|                     | 	                    ||                    }n|	dk    r*| 
                    | 	                    ||                    }n|	dk    r*|                     | 	                    ||                    }n^t          | j        dz             |d         r?|                     | 	                    ||                    }
|                     |
d          }|                     ||||          S )ae  
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#recent-trades-list
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#compressed-aggregate-trades-list
        :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-transaction-data
        get the list of most recent trades for a particular symbol
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: *spot only* *since must be defined* the latest time in ms to fetch entries for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r/   Nr  r;   )endTimeuntiltill	startTimezA fetchTrades() requires an until parameter when since is providedz@ fetchTrades() requires a since parameter when until is providedr  fetchTradesMethodspotPublicGetAggTradesmethodspotPublicGetHistoricalTradesspotPublicGetTradesz& fetchTrades() not support self methodr=   rE  )r  r  safe_integer_nr!   r/   ru  r   omitr  r  r  r  r'   contractPublicGetDealsSymbolrR  parse_trades)r>  r  r  r  rT  r  r  r   r  r  rW  s              r@  fetch_tradeszmexc.fetch_trades  s    	V$$fTl
 $GG&> E	7''0L0L0LMME ',$=+DG6y,yzzz =+DG6x,xyyy%*	"%%dl4GIabbF%%fh??FYYvz22F11144T[[&5Q5QRR:::;;DKKQW<X<XYY00011$++gv2N2NOO"47-U#UVVV> F^ 	788Wf9U9UVVH" __Xv66F  >>>rA  r  c                    d }d }d }d }d }d }d }	d }
d }d }d }d|v r|                      |d          }|                     d |          }|d         }|                     |d          }|                     |d          }|                     |                     |d                    }	d}
n|                     |d          }|                     ||          }|d         }|                     |dd          }|                     |d	d          }|                     |d
          }d|v r|                      |d          }|                     |d          }|                     |                     |d                    }	|                     |d          |                     |                     |d                    d}|                     |d          rdnd}
n|                     |dd          }|                     |dd          }|                     |d          }|                     |d          }|                     |d          }|                     |dd          }||rdnd}
||rdnd}	||rdnd}	d}
|                     |d          }|,|                     |d          |                     |          d}|| 	                    |||	||||
          }| 
                    ||||                     |          |||	|
|||||d|          S ) Nvtr  pTr   r/   ar  orderIdpositionModer  volsiderl  feeCurrencyr  r  r   r   qtyqquoteQtyisBuyerisMakerisBuyerMakermbuysellcommissionAsset
commission)r/   r   r  datetimer  r  r  takerOrMakerr  rp  r  rl  rJ  )rS  safe_marketru  parse_order_sidesafe_string_2rv  rR  safe_integer_2r|  synthetic_trade_id
safe_tradeiso8601)r>  trader  r/   r  r  r  rl  r  r  r  priceStringamountString
costStringmarketIdr  r  
buyerMakerfeeAssets                      r@  parse_tradezmexc.parse_trade   s   	
%<< ))%55I%%dF33FH%F**5#66K++E377L(()9)9%)E)EFFD"LLh ''x88H%%h77FH%F##E455B,,UGSAAK&&ui88G&& --e[AA	#//u==,,T-=-=eV-L-LMM ,,UE:: $ 7 78H8HP]8^8^ _ _  +///%*I*IVwww //vsCC	#11%DD!--eZ@@
//%;;//%;;!..uncJJ
&.5#B777L&$+755D)%/:66UD#*L++E3DEE' $ 0 0 E E$($;$;H$E$E C :((D,P[]acoppB"Y//( " 
  
   	rA  c                    d}||                      |          dz   |                     |dd          z   }||d|z   z  }||d|                      |          z   z  }||d|                      |          z   z  }||d|z   z  }||d|z   z  }|S )N -r/   _)number_to_stringru  )	r>  r  r  r  rp  r  	orderTyper  r/   s	            r@  r  zmexc.synthetic_trade_id  s     &&y11C7$:J:J6SWY\:]:]]BcDj !cD11&9999 cD11%8888'cL(($cIo%	rA  r   c           	      <   |                                   |                     |          }|d         rdnd}d}|                     |ddd          \  }}|r|                     d||||||          S |                     | j        di           }	|                     |	|d         i           }
|                     |
|          }|                     |          dz  }|d	         |d
}d}|d         r|                     |g d          }|G||d<   |@| 	                    |||z            }| 
                                }t          ||          |d<   |||d<   ||                     |ddg          }||d<   |                     |                     ||                    }|}ne|d         r\|                     |g dd          }||                     |dz            |d<   ||                     |ddg          }||d<   |                     |dd          }|                     |d          }d}|dk    r*|                     |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt)          | j        dz             |                     |d          }|                     |ddddd d!          }|                     |||||          S )"a;  
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#kline-candlestick-data
        :see: 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
        r;     i  Fru   paginater   r  r/   )r  intervalN)r  r  r  r  r  r  r  r  r=   gMbP?startendr  defaultindexmarkzA fetchOHLCV() not support self price type, [default, index, mark]rE  r   openhighlowcloser  )r  r  handle_option_and_params"fetch_paginated_call_deterministicrR  r   ru  parse_timeframer  summillisecondsri  r  spotPublicGetKlinesr  safe_integer_product_nparse_to_intcontractPublicGetKlineSymbol&contractPublicGetKlineIndexPriceSymbol%contractPublicGetKlineFairPriceSymbolr'   r/   convert_trading_view_to_ohlcvparse_ohlcvs)r>  r  	timeframer  r  rT  r  maxLimitr#  r   r   timeframeValuedurationr  candlesr  r&  nowrW  	priceTyperE  s                        r@  fetch_ohlcvzmexc.fetch_ohlcv  s}    	V$$"6N54488z[`aa& 	|::<QVX]_hjprz{{{//$,bAA__WfVnbAA
))*i@@''	22T9Tl&
 
 &> @	n''0L0L0LMME ',$=((5(X*=>>C++--C),S#GI& #(  6GV+<==%*	"//GV0L0LMMH GGF^ "	n//8T8T8TV[\\E #'#4#4UT\#B#B  6GV+<==!&(()DDIYYvw//FHI%%<<T[[RX=Y=YZZg%%FFt{{SZ\bGcGcddf$$EEdkkRY[aFbFbcc"47-p#pqqq  ??8V44D88vvvW\^eglmmG  &)UEJJJrA  c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r   r      r   )rS  ry  )r>  ohlcvr  s      r@  parse_ohlcvzmexc.parse_ohlcv  s~    eQ''UA&&UA&&UA&&UA&&UA&&
 	
rA  r  c                 .   |                                   i }d}d}|@t          |          }|dk    }|                     |d          }|                     |          }|                     d||          \  }}	d}
|r|d         |d<   |dk    r*|                     |                     ||	                    }
nF|d	k    r@|                     |                     ||	                    }|                     |d
g           }
|r|
g}
| 	                    |
|          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :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   r/   r  r;   r=   rE  )
r  rO  ru  r  rK  spotPublicGetTicker24hrr  contractPublicGetTickerrR  parse_tickers)r>  r  rT  r  r  isSingularMarketrX  firstSymbolrU  rV  tickersrW  s               r@  fetch_tickerszmexc.fetch_tickers  s7    	 \\F%{**7A66K[[--F >>~vW]^^
E 	- &tGH224;;w3N3NOOGG2 6!!33DKK4O4OPPH8 ooh;;G 	 iG!!'7333rA  c                    |                                   |                     |          }|                     d||          \  }}d}d|d         i}|dk    r*|                     |                     ||                    }nF|dk    r@|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   Nr  r/   r;   r=   rE  )r  r  rK  rH  r  rI  rR  parse_ticker)	r>  r  rT  r  rU  rV  r   r  rW  s	            r@  fetch_tickerzmexc.fetch_tickerW  s     	V$$ >>}fV\]]
EfTl
 11$++gu2M2MNNFF. 6!!33DKK4O4OPPH4 __Xvr::F  000rA  c                 8   |                      |d          }|                     ||          }d }d }d }d }d }d }	d }
d }d }d }d }d }d }|                     |d          }|sd|v r|                     |d          }|                      |d          }|                      |d          }|                      |d          }	|                      |d          }
|                      |d          }|                      |d	          }|                      |d
          }|                      |d          }t	          j        |d          }na|                     |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }t	          j        |d          rd }t	          j        |d          rd }|                      |d          }	|                      |d          }
|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }t	          j        |d          }|                     i d|d         d|d|                     |          d|d|d|d|                      |d           d!|d"|d#|d$|d%d d&|d'|d(|d)d d*|	|
|d+|          S ),Nr  r=   r  bid1ask1volume24amount24high24Pricelower24PriceriseFallValueriseFallRate100	closeTimebidPriceaskPricebidQtyaskQtyr  volumequoteVolume	openPrice	highPricelowPriceprevClosePricepriceChangepriceChangePercentr
  r*  r+  r,  r-  	lastPricebid	bidVolumeask	askVolumevwappreviousClosechanger   average
baseVolume)rb  rJ  )	ru  r  rR  rS  r+   
string_mul	string_eqsafe_tickerr  )r>  r   r  r  r  rj  rl  rk  rm  rr  rb  r*  r+  r,  
changePcntchangeValue	prevCloseisSwaps                     r@  rP  zmexc.parse_ticker  s   ##FH55!!(F33			

	00 H	?kV++, ))&+>>I""6622C""6622C))&*==J**6:>>K##FM::D""6>::C**6?CCK))&.AAJ +J>>JJ0 ))&+>>I""6:66C""6:66C((::I((::I C00 ! 	 C00 ! 	))&(;;J**6=AAK##FK88D##FK88D""6:66C((1ABBI**6=AAK))&2FGGJ +J>>J !
fX&!
!
 Y//!
 D	!

 D!
 3!
 T%%fk::!
 3!
 !
 3!
 !
 D!
 Y!
 k!
 *!
  t!!
" *#!
$ ''!
 !
 !
( )  	rA  c                    |                                   d}d}|0t          |          }|dk    }|                     |d                   }|                     d||          \  }}d}|dk    r|                     |          }n#|dk    rt          | j        dz   |z   d	z             |r|g}|                     ||          S )
a  
        fetches the bid and ask price and volume for multiple markets
        :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   rR   r;   r=   z& fetchBidsAsks() is not available for z markets)r  rO  r  rK  spotPublicGetTickerBookTickerr'   r/   rJ  )	r>  r  rT  r  rK  rX  rU  rV  rM  s	            r@  fetch_bids_askszmexc.fetch_bids_asks  s     	 \\F%{[[,,F >>PVX^__
E88??GG 6!!tw)QQT^^akklll 	 iG!!'7333rA  r  c                     |                                   |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|          S )a  
        create a market buy order by providing the symbol and cost
        :see: 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>`
        r;   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr  r  r  N)r  r  r'   r/   create_order)r>  r  r  rT  r  s        r@  !create_market_buy_order_with_costz&mexc.create_market_buy_order_with_cost1  ss     	V$$f~ 	ftw)ddeee6;23  5$fMMMrA  r  r  rp  r  c           	         |                                   |                     |          }|                     d|          \  }}	|d         r|                     |||||||	          S |                     |||||||	          S )a  
        create a trade order
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
        :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#order-under-maintenance
        :see: 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 fullfilled, 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
         *
         * 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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rJ   r;   )r  r  handle_margin_mode_and_paramscreate_spot_ordercreate_swap_order)
r>  r  r  r  rp  r  rT  r  
marginModerV  s
             r@  r~  zmexc.create_orderA  s    0 	V$$ >>}fUU
E&> 	`))&$feZY^___))&$feZY^___rA  c                    |d         }|                                 }	|d         |	|                                 d}
|	dk    r|dk    rd}|                     |ddd          \  }}|                     |d	d
          }|                     |d	          }||}n\|rZ|t	          | j        dz             |                     |          }|                     |          }t          j        ||          }|}| 	                    ||          |
d
<   n| 
                    ||          |
d<   ||                     ||          |
d<   |                     |d          }|||
d<   |                     |ddg          }|#|dk    rt          | j        dz   |z   dz             d }|                     |dk    |dk    |          \  }}|rd|
d<   |                     |
|          S )Nr  r/   )r  r  r  BUYr  TrJ   r  r  quoteOrderQtyz createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentquantityr  clientOrderIdnewClientOrderIdr  isolatedz+ createOrder() does not support marginMode  for spot-margin tradingLIMIT_MAKER)upperr.  safe_number_2r  r&   r/   r  r+   rs  cost_to_precisionamount_to_precisionprice_to_precisionru  r"   handle_post_onlyr  )r>  r  r  r  rp  r  r  rT  r  	orderSider  r  r  r  r  quoteAmountr  postOnlys                     r@  create_spot_order_requestzmexc.create_spot_order_requesta  sW   !JJLL	TlJJLL
 

 $("2"204-8<8U8UV\^k  nQ  SW  9X  9X5-v%%ffoFFDYYvv..F2 )=&tw  2m  (m  n  n  n#'#8#8#@#@L"&"7"7">">K")"4\;"O"OK(F'+'='=ff'M'MGO$$"&":":66"J"JGJ#66vuEEGG((AA$*7G&'YYv'@AAF!Z'' +X!X[e!e  iC  "C  D  D  D001A4=CXZ`aa& 	,+GFO{{7F+++rA  c           	      
   |                                   |                     |||||||          }|                     |                     ||                    }	|                     |	|          }
||
d<   ||
d<   ||
d<   ||
d<   |
S )Nr  r  r  rp  )r  r  spotPrivatePostOrderr  parse_order)r>  r  r  r  rp  r  r  rT  r  rW  r   s              r@  r  zmexc.create_spot_order  s    00tVUT^`fgg,,T[[&-I-IJJ(   622ffg hrA  c                    |                                   |d         }|                     | j        di           }	|                     |	|d          }
|
rt	          | j        dz   |z             d }|)|dk    rd}n7|dk    rd}n.t          | j        d	z             |                     |d
d          }|dk    rA|dk    r;|dk    r5|dk    r/|dk    r)|dk    r#|dk    r|dk    rt          | j        dz             d }| 	                    |dk    |dk    |          \  }}|rd}n|dk    rd}n|dk    rd}|d         t          |                     ||                    ||d}|dk    r2|dk    r,|dk    r&t          |                     ||                    |d<   |dk    r/|                     |d          }|t          | j        dz             |                     |dd          }|r|dk    rdnd|d<   n|dk    rdnd|d<   |                     |dd          }|||d<   |                     |dd          }|                     |g d          }d }|r|                     ||          |d<   |                     |dd          |d<   |                     |d d          |d <   |                     |d!d          |d!<   |                     |d"d          |d"<   |                     |                     ||                    }n)|                     |                     ||                    }|                     |d#          }|                     ||          S )$Nr  r  Fz4 createSwapOrder() does not support yet self symbol:crossr   r  r   zN createSwapOrder() marginMode parameter should be either "cross" or "isolated"openTyper  r  r   rD  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 pricer/   )r  r  r  r  r  r  zK createSwapOrder() requires a leverage parameter for isolated margin orders
reduceOnlyr  r  r  externalOidtriggerPrice	stopPrice)r  r  r  r  r  triggerTypeexecuteCycletrendr   rE  )r  rR  r   rx  r'   r/   r!   rS  r&   r  floatr  r  r  r  r  !contractPrivatePostPlanorderPlacer  contractPrivatePostOrderSubmitru  r  )r>  r  r  r  rp  r  r  rT  r  r  isContractUnavaiabler  r  r  r  r  r  r  rW  rE  s                       r@  r  zmexc.create_swap_order  s2   !#t|=SUWXX#~~.BFERR 	jtw)__bhhiii!W$$z))'  3C  )C  D  D  D((Q??HGOO$("2"2QRY]abYbYbimqririry}  BC  zC  zC  JN  RS  JS  JStw  *y   y  z  z  z001A419fUU& 	DDW__DDXDTl11&&AABB  #
 
4 AIIDAIIDH,<,<$T%<%<VU%K%KLLGGq==((<<H'2(  A  A  A^^FL%@@
 	:$(EMMaaGFOO$(EMMaaGFO**6?MRR$%2GM"&&v~{KK	6#l#l#lmm 	Y&*&=&=fi&P&PGN#%)%6%6v}a%P%PGM"&*&7&7PQ&R&RGN##00!DDGG#'#4#4V[!#L#LGK ==dkk'SY>Z>Z[[HH::4;;wPV;W;WXXH &11f---rA  ordersc           
      T   |                                   g }d}t          dt          |                    D ]1}||         }|                     |d          }|                     |          }|d         st          | j        dz             ||}n||k    rt          | j        dz             |                     |d          }	|                     |d          }
|                     |d	          }|                     |d
          }|                     |di           }d}| 	                    d|          \  }}| 
                    ||	|
||||          }|                    |           3d|                     |          i}|                     |          }|                     |          S )a   
        *spot only*  *all orders must have the same symbol* create a list of trade orders
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#batch-orders
        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]: extra parameters specific to api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  r;   z2 createOrders() is only supported for spot marketsz; createOrders() requires all orders to have the same symbolr  r  rp  r  rT  rJ   r   )r  rt  rO  ru  r  r'   r/   r"   rR  r  r  r  rP  spotPrivatePostBatchOrdersparse_orders)r>  r  rT  ordersRequestsr  r~  rawOrderr  r  r  r  rp  r  orderParamsr  orderRequestr  rW  s                     r@  create_orderszmexc.create_orders	  s    	q#f++&& 	0 	0AayH''(;;H[[**F&> c"47-a#abbb~!X%%$TW/l%lmmm##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAKJ!%!C!CMSY!Z!ZJ99&$fV[]gituuL!!,////499^44
 227;;*   ***rA  r/   c                    |t          | j        dz             |                                  |                     |          }d|d         i}d}|d         r|                     |d          }||                     |d          }||d<   n||d<   |                     d	|          \  }}	|M|d
k    rt          | j        dz   |z   dz             |                     | 	                    ||	                    }nv| 
                    | 	                    ||	                    }nL|d         rD||d<   |                     | 	                    ||                    }
|                     |
d          }|                     ||          S )a  
        fetches information on an order made by the user
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: only 'isolated' is supported, for spot-margin trading
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentr  r/   r;   r  origClientOrderIdr  rx   r  z* fetchOrder() does not support marginMode r  r=   order_idrE  )r!   r/   r  r  ru  r  r  r"   spotPrivateGetMarginOrderr  spotPrivateGetOrder!contractPrivateGetOrderGetOrderIdrR  r  )r>  r/   r  rT  r  r  rE  r  r  rV  rW  s              r@  fetch_orderzmexc.fetch_order:	  s    >#DG.X$XYYYV$$fTl
 &> ]	5 ,,V_EEM(6?;;/<+,,%'	" $ B B<QW X XJ%++$TW/[%[^h%h  lF  &F  G  G  G55dkk'56Q6QRR//GU0K0KLLZ F^ #	5"$GJ==dkk'SY>Z>Z[[HB ??8V44Df---rA  c                    |                                   i }d}| |                     |          }|d         |d<   |                     d||          \  }}|dk    r|t          | j        dz             |                     d|          \  }	}
|||d<   |||d<   d}|	M|	d	k    rt          | j        d
z   |	z   dz             |                     |                     ||
                    }n)| 	                    |                     ||
                    }| 
                    ||||          S |A||d<   |                     |d          }|$|                     || j        d                   |d<   |||d<   |                     | j        dd          }|                     |d|          }g }g }|dk    r@|                     |                     ||                    }|                     |d          }n?|                     |                     ||                    }|                     |d          }|                     ||          }| 
                    |||||          S )aK  
        fetches information on multiple orders made by the user
        :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 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/   r  r{   r;   z9 fetchOrders() requires a symbol argument for spot marketr  r  r  z+ fetchOrders() does not support marginMode r  
start_timeend_timer  	page_size(contractPrivateGetOrderListHistoryOrdersr  rE  )r  r  rK  r!   r/   r  r"   spotPrivateGetMarginAllOrdersr  spotPrivateGetAllOrdersr  rS  r1  r   ru  r  rR  %contractPrivateGetPlanorderListOrdersr  )r>  r  r  r  rT  r  r  rU  rV  r  
queryInnerrW  r&  r  ordersOfRegularordersOfTriggermergeds                    r@  fetch_orderszmexc.fetch_orders	  s    	[[((F &tGH >>}fV\]]
E~'2m(mnnn%)%G%GW]%^%^"J
 ',$ #( H%++$TW/\%\_i%i  mG  &G  H  H  H==dkk'S]>^>^__77GZ8X8XYYb $$XvueDDD (-%''
;;;*.((5$,GW:X*Y*YGJ' ',$%%dlMCmnnF%%eXv>>F O OCCCHHU\^cIdIdeeF #'//(F"C"C  EEdkkRY[`FaFabb6 #'//(F"C"C&&HHF$$VVUE6JJJrA  c                    |                                   i }d }| |                     |          }|d         |d<   |                     d||          \  }}|dk    rt          | j        dz   |z             d                    |          |d<   |                     |                     ||                    }|                     |d          }	| 	                    |	|          S )	Nr/   r  fetchOrdersByIdsr;   z) fetchOrdersByIds() is not supported for ,	order_idsrE  )
r  r  rK  r"   r/   join!contractPrivateGetOrderBatchQueryr  	safe_listr  )
r>  idsr  rT  r  r  rU  rV  rW  rE  s
             r@  fetch_orders_by_idszmexc.fetch_orders_by_idsM
  s    [[((F &tGH >>?QSY[abb
ETW'RRU__```#&88C==GK ==dkk'SX>Y>YZZHF >>(F33D$$T6222rA  c                 t   |                                   i }d}d}||                     |          }|                     d||          \  }}|dk    r|t          | j        dz             |d         |d<   |                     d|          \  }}	d}
|M|dk    rt          | j        dz   |z   d	z             |                     |                     ||	                    }
n)| 	                    |                     ||	                    }
| 
                    |
|||          S |                     d
||||          S )a&  
        fetch all unfilled currently open orders
        :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>`
        Nrw   r;   z= fetchOpenOrders() requires a symbol argument for spot marketr/   r  r  z/ fetchOpenOrders() does not support marginMode r  r   )r  r  rK  r!   r/   r  r"   spotPrivateGetMarginOpenOrdersr  spotPrivateGetOpenOrdersr  fetch_orders_by_state)r>  r  r  r  rT  r  r  rU  r  rV  rW  s              r@  fetch_open_orderszmexc.fetch_open_orders
  ss    	
[[((F!??@QSY[abb
F~'2q(qrrr &tGH $ B BCTV\ ] ]JH%++$TW/`%`cm%m  qK  &K  L  L  L>>t{{7TY?Z?Z[[88We9T9TUUb $$XvueDDD --avNNNrA  c                 4    |                      d||||          S )a  
        fetches information on multiple closed orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r   r  r>  r  r  r  rT  s        r@  fetch_closed_orderszmexc.fetch_closed_orders
        ))!VUE6JJJrA  c                 4    |                      d||||          S )a  
        fetches information on multiple canceled orders made by the user
        :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>`
        rD  r  r  s        r@  fetch_canceled_orderszmexc.fetch_canceled_orders
  r  rA  c           	      0   |                                   i }d }||                     |          }|                     d||          }|dk    rt          | j        dz   |z             ||d<   |                     ||||                     ||                    S )NfetchOrdersByStater;   z+ fetchOrdersByState() is not supported for states)r  r  rK  r'   r/   r  r  )	r>  r  r  r  r  rT  r  r  rU  s	            r@  r  zmexc.fetch_orders_by_state
  s    [[((F778LfV\]]
tw)VVYccddd %GH$$VUE4;;wPV;W;WXXXrA  c                    |                                   i }d}| |                     |          }|d         |d<   d}|                     d||          \  }}|                     d|          \  }}d}	|dk    r|t	          | j        dz             d|d         i}
|                     |d          }||                     |d          }||
d<   n||
d	<   |N|d
k    rt          | j        dz   |z   dz             | 	                    | 
                    |
|                    }	n|                     | 
                    |
|                    }	n|                     | j        dd          }|                     |d|          }d}|dk    r|                     |g          }n4|dk    r|                     |g          }nt          | j        dz             |                     |d          }	|                     |	d          }|                     |dd          }|dk    r t#          | j        dz   |z   dz   |z             |                     |	|          S )a  
        cancels an open order
        :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>`
        Nr/   r  rB   r;   z) cancelOrder() requires a symbol argumentr  r  r  r  z+ cancelOrder() does not support marginMode r  contractPrivatePostOrderCancelr  "contractPrivatePostPlanorderCancelz& cancelOrder() not support self methodrE  r   errorMsgr  rD  z! cancelOrder() the order with id z cannot be cancelled: )r  r  rK  r  r!   r/   ru  r  r"   spotPrivateDeleteMarginOrderr  spotPrivateDeleteOrderr   r  r  r'   rR  r&   r  )r>  r/   r  rT  r  r  rU  r  rV  rE  requestInnerr  r  rW  r   r  s                   r@  cancel_orderzmexc.cancel_order
  s    	[[((F &tGH
!??vW]^^
F >>}fUU
E~'2](]^^^&,L !,,V_EEM(5/::4A011*,Y'%++$TW/\%\_i%i  mG  &G  H  H  H88\SX9Y9YZZ224;;|U3S3STTJ %%dlMCcddF%%eXv>>FH999>>tDD???BBB4HH"47-U#UVVV ??8V44DOOD!,,Euj"==H9$$"47-P#PSU#UXp#ps{#{|||f---rA  c                 L   |                                   ||                     |          nd}|                     d||          }|dk    rt          | j        dz   |z             |                     |          }|                     |d          }|                     ||          S )aF  
        cancel multiple orders
        :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>`
        NrC   r;   z% cancelOrders() is not supported for rE  )r  r  rK  r"   r/   r  r  r  )r>  r  r  rT  r  rU  rW  rE  s           r@  cancel_orderszmexc.cancel_ordersZ  s     	)/);V$$$$77PVWW
TW'NNQ[[\\\::3??H >>(F33D$$T6222rA  c                    |                                   ||                     |          nd}i }d}|                     d||          \  }}|                     d|          \  }}|dk    r|t	          | j        dz             |d         |d<   d}|M|dk    rt          | j        dz   |z   d	z             |                     |                     ||                    }n)| 	                    |                     ||                    }| 
                    ||          S ||d         |d<   |                     | j        dd
          }	|                     |d|	          }	d}|	d
k    r*|                     |                     ||                    }n/|	dk    r)|                     |                     ||                    }|                     |dg           }
| 
                    |
|          S )a  
        cancel all open orders
        :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>`
        NrA   r;   z5 cancelAllOrders() requires a symbol argument on spotr/   r  r  z/ cancelAllOrders() does not support marginMode r  !contractPrivatePostOrderCancelAllr  %contractPrivatePostPlanorderCancelAllrE  )r  r  rK  r  r!   r/   r"   !spotPrivateDeleteMarginOpenOrdersr  spotPrivateDeleteOpenOrdersr  ru  r   r  r  r  )r>  r  rT  r  r  rU  r  rV  rW  r  rE  s              r@  cancel_all_orderszmexc.cancel_all_ordersy  s*    	)/);V$$$$
!??@QSY[abb
F >>?PRXYY
E~'2i(ijjj &tGHH%++$TW/`%`cm%m  qK  &K  L  L  LAA$++gW\B]B]^^;;DKKQV<W<WXXJ $$Xv666!$*4L! %%dl4EGjkkF%%eXv>>FH<<<AA$++gW\B]B]^^BBBEEdkkRY[`FaFabb >>(FB77D$$T6222rA  c                    |                      |d          }|-|                     |d|                     |d          d          S d }t          |t                    r|}n|                     |dd          }|                     |d          }|                     ||          }|                     |g d          }d }|                     |d	          }|Y|                     |d
          }	|                     |d          }
t          j	        |	|
          }|| 
                    |          d}|                     i d|d|                     |d          d|d|                     |          dd d|                     |                     |dd                    d|d         d|                     |                     |d                    d|                     |                     |d                    d|                     |                     |d                    d|                     |d          d|                     |dd          d|                     |dd          d|                     |d          d|                     |dd          d|                     |d          d |                     |d!d"          d |d |d#|          S )$Nrq  rejectedr  )rJ  rF  r  r  r/   r  )r   
createTimetransactTimer  takerFeemakerFee)r  r  r  r  r
  lastTradeTimestamprF  r  r  timeInForcer  r  r  r  rq  dealAvgPricerp  origQtyr  r  cummulativeQuoteQtyfilledexecutedQtydealVol)	remainingrl  r   rJ  )rS  
safe_orderru  
isinstancestrr  r  r  r+   
string_addr=  r  parse_order_statusparse_order_typeparse_order_time_in_forcer  ry  r  )r>  r   r  rq  r/   r  r  rl  r  r  r  feeSums               r@  r  zmexc.parse_order  sp   z   //??$!%!1!1%9K!L!L$ $   
 eS!! 	<BB##E9d;;B##E844!!(F33''/U/U/UVV	&&um<<"''z::H''z::H'(;;F'))&11 C   
" 
T--e_EE 
  
 Y//	 

 !$ 
 d--d.@.@RY.Z.Z[[ 
 fX& 
 D))$*:*:5&*I*IJJ 
 499$:J:J5R_:`:`aa 
 D))$*:*:5&*I*IJJ 
 T%%eW55 
 ++E;OO 
 D..uk>RR 
 t''~>> 
 d((	5AA 
  D$$U,ABB! 
" d((yII# 
$ + 
  
  
, -  	rA  c                 >    ddddd}|                      |||          S )Nr  r  )r  SELL12ru  r>  rF  statusess      r@  r  zmexc.parse_order_side  s4    	
 
 &&999rA  c                 <    dddd}|                      |||          S )Nr  r  )MARKETLIMITr  r
  r  s      r@  r  zmexc.parse_order_type  s1    "
 

 &&999rA  c           	      F    ddddddddd}|                      |||          S )Nr*  closedcanceled)NEWFILLEDCANCELEDPARTIALLY_FILLEDPARTIALLY_CANCELEDr	  34r
  r  s      r@  r  zmexc.parse_order_status  sB    " &", 
 
 &&999rA  c                 <    dddd}|                      |||          S )NGTCFOKIOC)r  r  r  r
  r  s      r@  r  zmexc.parse_order_time_in_force  s1    
 

 &&999rA  c                     |dk    r|                      |          S |dk    r+|                     |          }|                     |d          S d S )Nr;   r=   rE  )spotPrivateGetAccountcontractPrivateGetAccountAssetsrR  )r>  r  rT  rW  s       r@  fetch_account_helperzmexc.fetch_account_helper  sX    6>>--f555: V^^;;FCCH& ??8V444trA  c                    |                      dd|          \  }}|                                  |                     ||          }|                     |dg           }g }t	          dt          |                    D ]x}||         }|                     |dd          }	|                     |	          }
|                    | 	                    |d          | 	                    |d          |
|d	           y|S )
a  
        fetch all the accounts associated with a profile
        :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
        rP   Nbalancesr   assetr  r/   r  )r/   r  rq  rJ  )
rK  r  r!  rR  rt  rO  r  rv  r  ru  )r>  rT  rU  rV  rW  rE  r}  r~  r   
currencyIdrq  s              r@  fetch_accountszmexc.fetch_accounts  s    !>>PTV\]]
E,,Z??xR88q#d))$$ 		 		A1gG++GWjIIJ**:66DMM&&w55((&99	      rA  c                    |                                   |                     d|          }|                     |d          }|                     |d          }t          j        |d          }t          j        |d          }i }t          dt          | j                            D ]A}| j        |         }||                     |          |                     |          dd|d||<   B|S )	a  
        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r;   r  r  1000r   TF)r  r   r   r   r   rJ  )	r  r!  ru  r+   
string_divrt  rO  r  r=  )r>  rT  rW  r  r  r}  r~  r  s           r@  fetch_trading_feeszmexc.fetch_trading_fees  s     	,,VV<<##H.?@@##H.?@@%h77%h77q#dl++,, 		 		A\!_F **844**844""  F6NN rA  c                    d }|dk    r|                      |dg           }n5|dk    r|                      |dg           }n|                      |dg           }d|i}|dk    r"t          dt          |                    D ]}||         }|                     |d          }|                     |d           }|                      |d	i           }	|                      |d
i           }
|                     |                     |	d                    }|                     |                     |
d                    }i }|                     |	          ||<   |                     |
          ||<   |                     |          ||<   |S |dk    rt          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nr<   assetsr=   rE  r#  rJ  r   r  r  r  r$  r  availableBalancefreefrozenBalanceusedlocked)	rR  rt  rO  ru  safe_symbolrv  parse_balance_helpersafe_balancer   )r>  rW  rU  walletr}  r~  entryr  r  r  r  baseCode	quoteCode	subResultr%  rq  r   s                    r@  custom_parse_balancezmexc.custom_parse_balance,  s   z !!__Xx<<FF6!!__Xvr::FF__Xz2>>F(#!!1c&kk** > >q	++E8<<))(D99uk2>>|R@@2243C3CD'3R3RSS 33D4D4DUG4T4TUU		&*&?&?&E&E	(#'+'@'@'G'G	)$!%!2!29!=!=vM6!!1c&kk** ' 'q	!--eZ@@
..z::,,.."&"2"25:L"M"M"&"2"25/"J"J&t$$V,,,1c&kk** ' 'q	!--eW==
..z::,,.."&"2"25&"A"A"&"2"25("C"C&t$$V,,,rA  c                 L   |                                  }|                     |d          |d<   |                     |d          |d<   |                     |d          |d<   |                     |d          }|                     |d          }t          j        ||          |d<   |S )	Nr1  r0  r.  
totalAssettotalborrowedinterestdebt)r   ru  r+   r  )r>  r6  r   r@  r?  s        r@  r3  zmexc.parse_balance_helper  s    ,,..**5(;;**5&99++E<@@z22##E:66!,T8<<rA  c                    |                                   d}i }|                     dd|          \  }}|                     |d          }|                     |dd          }|                     |ddg          }d}||s|dk    rd}|                     |d          }|A|                     |d          }	|	(d                    |                     |	                    }n|                     |          }
|
d	         }| 	                    d|d
           d}||d<   |                     |ddg          }| 
                    |                     ||                    }nw|dk    r*|                     |                     ||                    }nG|dk    r*|                     |                     ||                    }nt          | j        dz             |                     ||          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#account-information
        :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-informations-of-user-39-s-asset
        :see: 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>`
        NrQ   r  r<   Fr  r  r  r/   zsymbol or symbolsr;   r=   z' fetchBalance() not support self method)r  rK  ru  rx  r  rR  r  
market_idsr  check_required_argument#spotPrivateGetMarginIsolatedAccountr  r  r   r'   r/   r:  )r>  rT  rU  r  r  isMarginrW  parsedSymbolsr  r  r  s              r@  fetch_balancezmexc.fetch_balance  s    	
!??PTV\]]
F%%fl;;
>>&(E::6Hl#;<<""jH6L6L M%%fh77F~//&)<<&$'HHT__W-E-E$F$FMV,, &t((H[\\\!J!.GIYYv)'<==F??GU[@\@\]]HH6!!11$++gv2N2NOOHH6!!;;DKKQW<X<XYYHHtw)RRSSSj ((:>>>rA  c                    |t          | j        dz             |                                  |                     |          }|                     d||          \  }}d|d         i}d}	|dk    r8|||d<   |||d<   |                     |                     ||                    }	n|A||d<   |                     |d	          }
|
$|                     || j	        d
                   |d	<   |||d<   | 
                    |                     ||                    }|                     |d          }	|                     |	|||          S )a  
        fetch all trades made by the user
        :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
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nz+ fetchMyTrades() requires a symbol argumentrt   r  r/   r;   r  r  r  r  r  rE  )r!   r/   r  r  rK  spotPrivateGetMyTradesr  rS  r1  r   %contractPrivateGetOrderListOrderDealsrR  r  )r>  r  r  r  rT  r  rU  rV  r  r   r&  rW  s               r@  fetch_my_tradeszmexc.fetch_my_trades  sr    >#DG.[$[\\\V$$ >>PVX^__
EfTl
  (-% #( 00We1L1LMMFF.  (-%''
;;;*.((5$,GW:X*Y*YGJ' ',$AA$++gW\B]B]^^H0 __Xv66F  >>>rA  c                    |                                   i }d}||                     |          }|                     d||          \  }}	d}
|dk    rS|t          | j        dz             |d         |d<   ||d<   |                     |                     ||	                    }
nD||d<   |                     |                     ||	                    }|                     |d	          }
| 	                    |
||||	          S )
a  
        fetch all the trades made from a single order
        :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|   r;   z. fetchOrderTrades() requires a symbol argumentr/   r  r  r  rE  )
r  r  rK  r!   r/   rI  r  )contractPrivateGetOrderDealDetailsOrderIdrR  r  )r>  r/   r  r  r  rT  r  r  rU  rV  r   rW  s               r@  fetch_order_tradeszmexc.fetch_order_tradesk  s    	[[((F >>?QSY[abb
E~'2b(bccc &tGH!#GI00We1L1LMMFF. #%GJEEdkkRY[`FaFabbH0 __Xv66F  uEEErA  c                     |                      |d          }|t          | j        dz             |                                  |||d}|                     |                     ||                    }|S )N
positionIdz5 modifyMarginHelper() requires a positionId parameter)rP  rp  r  )rS  r!   r/   r  'contractPrivatePostPositionChangeMarginr  )r>  r  rp  addOrReducerT  rP  r  rW  s           r@  modify_margin_helperzmexc.modify_margin_helper  s    &&v|<<
#DG.e$efff$
 

 ??GU[@\@\]] rA  c                 2    |                      ||d|          S )aS  
        remove margin from a position
        :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rS  r>  r  rp  rT  s       r@  reduce_marginzmexc.reduce_margin       ((GGGrA  c                 2    |                      ||d|          S )a6  
        add 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>`
        ADDrV  rW  s       r@  
add_marginzmexc.add_margin  rY  rA  r  c                    |                                   d|i}|                     |d          }|x|                     |d          }|                     |d          }||                     |          nd}|||t	          | j        dz             ||d<   |d         |d<   ||d<   n||d<   |                     |                     ||                    S )	a$  
        set the level of leverage for a market
        :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
        r  rP  Nr  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 positionsr/   r  )r  rS  ry  r  r!   r/   )contractPrivatePostPositionChangeLeverager  )	r>  r  r  rT  r  rP  r  r^  r  s	            r@  set_leveragezmexc.set_leverage  s
    	
 &&v|<<
''
;;H++FNCCL-3-?T[[(((dF l&:'  3V  )V  W  W  W&.
#$*4L!*6''$.GL!==dkk'SY>Z>Z[[[rA  c                 f   |                                   d}i }| |                     |          }|d         |d<   |||d<   |                     |                     ||                    }|                     |di           }|                     |dg           }	g }
t          dt          |	                    D ]x}|	|         }|                     |d          }|
                    ||d|| 	                    |          | 
                    |d          | 
                    |d	          d
           y|
S )a  
        fetch the history of funding payments paid and received on self account
        :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>`
        Nr/   r  r  rE  
resultListr   
settleTimefunding)rJ  r  rq  r  r
  r/   rp  )r  r  (contractPrivateGetPositionFundingRecordsr  rR  rt  rO  rS  r  r  ry  )r>  r  r  r  rT  r  r  rW  rE  rb  r}  r~  r6  r  s                 r@  fetch_funding_historyzmexc.fetch_funding_history  sW    	
 [[((F &tGH#(GK @@WV\A]A]^^B x44__T<<<
q#j//** 	 	AqME))%>>IMM & LL33&&ud33**5)<<      rA  c                    |                      |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 S )NfundingRatenextSettleTimer  r  rJ  	markPrice
indexPriceinterestRateestimatedSettlePricer
  fundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)ry  rS  ru  r2  r  )	r>  r   r  rp  rq  r  r  r  r
  s	            r@  parse_funding_ratezmexc.parse_funding_rate=  s`    **8]CC#00;KLL##Hh77!!(F33%%h<<	<<	**
H
f
 
 $	

 D
 #D
 
 
 ?
  4
 t||,@AA
 t
 #D
 "4
 "4
  '!
" &t#
 	
rA  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     ||          S )a  
        fetch the current funding rate
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r  r/   rE  )r  r  "contractPublicGetFundingRateSymbolr  rR  rv  )r>  r  rT  r  r  rW  r}  s          r@  fetch_funding_ratezmexc.fetch_funding_ratec  s     	V$$fTl
 ::4;;wPV;W;WXX  6266&&vv666rA  c           
         |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |d          }|                     |dg           }	g }
t          dt          |	                    D ]}|	|         }| 	                    |d          }| 
                    |          }|                     |d	          }|
                    |||                     |d
          ||                     |          d           |                     |
d          }|                     ||d         ||          S )a  
        fetches historical funding rate prices
        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not used by mexc, but filtered internally by ccxt
        :param int [limit]: mexc limit is page_size default 20, maximum is 100
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentr  r/   r  rE  rb  r   rc  rh  )rJ  r  rh  r  r
  r  )r!   r/   r  r  #contractPublicGetFundingRateHistoryr  rR  rt  rO  ru  r2  rS  r  ry  r  sort_byfilter_by_symbol_since_limit)r>  r  r  r  rT  r  r  rW  rE  r}  ratesr~  r6  r  symbolInnerr  sorteds                    r@  fetch_funding_rate_historyzmexc.fetch_funding_rate_history  s    >#DG.e$efffV$$fTl

 #(GK ;;DKKQW<X<XYY2 x00|R88q#f++&& 	 	A1IE''x88H**844K))%>>ILL%#//}EE& LL33      e[11009I5RWXXXrA  c                     |                                   |                     |ddd          }|                     |          }|                     |d          }|                     ||d          S )ad  
        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
        :see: 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
        r=   TrE  r  )r  market_symbolsr  r  parse_leverage_tiersr>  r  rT  rW  rE  s        r@  fetch_leverage_tierszmexc.fetch_leverage_tiers  sp     	%%gvtTBB//77\ ~~h//((wAAArA  c                    |                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }d}	g }
|                      |d          }|dk    r2d	|                     |          d d d |                     |d
          |dgS t          j        |	|          rt          j        |	|          }|
                    |                     t          j        ||                    |                     |          |                     |	          |                     |          |                     |          |                     t          j        d|                    |d           t          j        ||          }t          j        ||          }|}	t          j        |	|          |
S )NmaintenanceMarginRateinitialMarginRater  riskIncrVolriskIncrMmrriskIncrImrr  r  r   r  )tierr  notionalFloornotionalCapr  r  rJ  r  )	ru  rv  ry  r+   r{  r  r  r=  r)  )r>  rJ  r  r  r  r  r  r  r  floortiersr  caps                r@  parse_market_leverage_tiersz mexc.parse_market_leverage_tiers  s   N !% 0 07N O O ,,T3FGG!!$11&&t];;&&t];;&&t];;""455#  $ 7 7 @ @%)#'-1#'#3#3D-#H#H  
 
 v.. 	$UK88CLL))'*<S+*N*NOO 33G<<!%!2!25!9!9#0055)-):):;P)Q)Q#001CCIZ1[1[\\     !( 23Dk R R$+$67Lk$Z$Z!E v.. 	 rA  r  c                 6   |                      |d          }|                      |d          }|                      |d          }|                     |           |                     ||          ||                      |d          |                     |          |dS )Naddressr`  rb  memo)r  r  tagrb  rJ  )ru  check_addressrv  rw  )r>  depositAddressr  r  r%  r  s         r@  parse_deposit_addresszmexc.parse_deposit_addressH  s     "">9==%%nf==
$$^Y??	7###//
HEE##NF;;..y99"
 
 	
rA  rq  c                    |                                   |                     |          }d|d         i}|                     |d          }d}||                     ||          }|||d<   |                     |d          }|                     |                     ||                    }|                     |dd          }|                     |d          S )a  
        fetch a dictionary of addresses for a currency, indexed by network
        :see: 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`  r/   rb  NF)	r  r  ru  network_code_to_idr  #spotPrivateGetCapitalDepositAddressr  parse_deposit_addressesindex_by)	r>  rq  rT  r  r  networkCoder  rW  addressStructuress	            r@  "fetch_deposit_addresses_by_networkz'mexc.fetch_deposit_addresses_by_network]  s     	==&&HTN
 &&vy99	"//TBBI !*GI69--;;DKKQW<X<XYY !884OO}}.	:::rA  c                    |                                   |                     |          }d|d         i}|                     |d          }|t          | j        dz             |                     ||          }|||d<   |                     |d          }|                     |                     ||                    }| 	                    ||          S )a  
        create a currency deposit address
        :see: 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`  r/   rb  Nz4 createDepositAddress requires a `network` parameter)
r  r  ru  r!   r/   r  r  $spotPrivatePostCapitalDepositAddressr  r  )r>  rq  rT  r  r  r  r  rW  s           r@  create_deposit_addresszmexc.create_deposit_address  s     	==&&HTN
 &&vy99#DG.d$deee++K>>	 !*GI69--<<T[[RX=Y=YZZ ))(H===rA  c                 b   |                      |d          }|                     |dg          }|                     ||          }d}|+|                     ||                     ||                    }n|                     | j        d          }|                      ||          }||                     ||          }nMt          |                                          }|                      |d          }	|                     ||	          }|#t          | j	        dz   |z   dz   |z   dz             |S )a1  
        fetch the deposit address for a currency associated with self account
        :see: 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>`
        rb  Nr  r   z9 fetchDepositAddress() cannot find a deposit address for z, and networkzMconsider creating one using .createDepositAddress() method or in MEXC website)
ru  r  r  	safe_dictrw  r   rM  rN  r%   r/   )
r>  rq  rT  rb  r  r}  r   defaultNetworkForCurrencyrN  keys
             r@  fetch_deposit_addresszmexc.fetch_deposit_address  sQ    ""69556I;// CCD&QQ^^$5t7N7NwX\7]7]^^FFnnT\3DEEG(,(8(8$(G(G%(4(9;TUU-224455&&tQ//(93??> +f!fim!mp!  CJ  "J  M\  "\  ]  ]  ]rA  c                    |                                   i }d}|a|                     |          }|d         |d<   |                     |d          }|)|                     |d          }|dxx         d|z   z  cc<   |||d<   ||dk    rt	          d          ||d	<   |                     |                     ||                    }|                     ||||          S )
a*  
        fetch all deposits made to an account
        :see: 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>`
        Nr/   r`  rb  r  r  r"  .This exchange supports a maximum limit of 1000r  )r  r  ru  r  r   "spotPrivateGetCapitalDepositHisrecr  parse_transactions)	r>  rq  r  r  rT  r  r  
rawNetworkrW  s	            r@  fetch_depositszmexc.fetch_deposits  s	    	
 }}T**H&tnGFO ))&)<<J%69553#33#(GK t||#$TUUU$GG::4;;wPV;W;WXX" &&x5%HHHrA  c                 >   |                                   i }d}| |                     |          }|d         |d<   |||d<   ||dk    rt          d          ||d<   |                     |                     ||                    }|                     ||||          S )a6  
        fetch all withdrawals made from an account
        :see: 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>`
        Nr/   r`  r  r"  r  r  )r  r  r   $spotPrivateGetCapitalWithdrawHistoryr  r  )r>  rq  r  r  rT  r  r  rW  s           r@  fetch_withdrawalszmexc.fetch_withdrawals  s     	
 }}T**H&tnGFO#(GK t||#$TUUU$GG<<T[[RX=Y=YZZ( &&x5%HHHrA  c                    |                      |d          }|dnd}|                     |dd          }d }|                      |d          }||                    d          d         }d }|                      |d	          }	|	|                     |	          }|                     ||          }
|                     |                      |d
          |          }|                      |d          }|                      |d          }|                      |d          }d }|                      |d          }||                     |          |
d}|dk    rt          j        ||          }i d|d|d|d|d| 	                    |          d	|d|d|dd d|                      |d          dd dd d|d|                     |          d|
d
|dd d d |dS )Nr/   rN   
withdrawal
insertTime	applyTimer`  r  r   rb  rF  rp  r  txIdtransactionFeer  rJ  txidr  r
  	addressToaddressFromr  r  tagTotagFromr  r  rG  )commentinternalrl  )
ru  r  splitrw  rv   parse_transaction_status_by_typer=  r+   
string_subr  )r>  transactionr  r/   r  r  r%  currencyWithNetworkrb  r  rq  rF  r  r  r  rl  feeCostStrings                    r@  parse_transactionzmexc.parse_transaction!  s   R k400Zyyl''\;OO	
"..{FCC*,22377:J%%k9==
!--j99G&&z8<<66t7G7GU]7^7^`dee''X>>"";	::V44((6FGG$))-88  C <"-lMJJL
K
"
 D
 	

 Y//
 w
 w
 
 4
 4##K88
 T
 t
 D
 d''55
 
  f!
" t#
$ )
 
 
 	
rA  c                     ddddddddddddddddddd
d}|                      ||i           }|                     |||          S )NfailedpendingrC  )r  r	  r  r  567r  )
r  r	  r  r  r  r  r  8910)rN   r  )rR  ru  )r>  rF  r  statusesByTyper  s        r@  r  z%mexc.parse_transaction_status_by_type{  s        
 
. ??>4<<&&999rA  c                     |                                   |                     |          }d|d         i}|                     d|                     ||                    }|                     |d          S )aa  
        fetch data on a single open contract trade position
        :param str symbol: unified market symbol of the market the position is held in, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        r  r/   Nr   )r  r  fetch_positionsr  rR  )r>  r  rT  r  r  rW  s         r@  fetch_positionzmexc.fetch_position  sp     	V$$fTl
 ''dkk'6.J.JKKx+++rA  c                     |                                   |                     |          }|                     |dg           }|                     ||          S )a*  
        fetch all open positions
        :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>`
        rE  )r  'contractPrivateGetPositionOpenPositionsr  parse_positionsr  s        r@  r  zmexc.fetch_positions  sV     	??GG> ~~h33##D'222rA  c                 0   |                      |                     |d          |          }|d         }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|dk    rdnd}|                     |d	          }	|	dk    rd
nd}
|                     |d          }|                     |d          }|                     |d          }|                     i d|dd d|d|                     |          dd d|dd d|dd d|                     |          dd d|
dd dd dd d|d|                     |          d d d d ||                     |          d d d d d
          S )Nr  holdVolopenAvgPriceimr^  r  longshortmargin_moder  r  r  liquidatePrice
updateTimerJ  r/   	contractsr  
entryPrice
collateralr  unrealizedProfitr   r  notionalrj  ri  liquidationPriceinitialMargin)
initialMarginPercentagemaintenanceMarginmaintenanceMarginPercentagemarginRatior  r
  hedgedstopLossPricetakeProfitPricelastUpdateTimestamp)r  ru  ry  rS  safe_positionr=  r  )r>  positionr  r  r  r  r  rawSider  r  
marginTyper  r  r  s                 r@  parse_positionzmexc.parse_position  sJ   2 !!$"2"28X"F"FOO!$$Xy99	%%h??
((488""8^<<!S..vvw##Hm<<$,OOZZ'
##Hj99++H6FGG%%h==	!! #
H#
$#
 f#
 **955	#

 D#
 *#
 $#
 D#
 #
 ))(33#
 $#
 *#
 #
 #
 #
   0!#
" T..}==##
$ (,!%+/"Y//!##'7#
 #
 #
   	rA  c                 `   |                      dd |          \  }}|                                  |dk    rYd|i}|                     |                     ||                    }|                     |di           }	|                     |	          S |dk    rt          | j        dz   |z             d S )Nr   r;   transact_idrE  r=   z& fetchTransfer() is not supported for )rK  r  (spot2PrivateGetAssetInternalTransferInfor  r  parse_transferr"   r/   )
r>  r/   r  r  rT  rU  rV  r  rW  rE  s
             r@  fetch_transferzmexc.fetch_transfer  s     >>PTV\]]
ErG DDT[[QXZ_E`E`aaH >>(FB77D&&t,,,6!!TW'OOR\\]]]trA  c                    |                      dd|          \  }}|                                  i }d}d}	| |                     |          }|d         |d<   |dk    r{|||d<   ||dk    rt          d          ||d	<   |                     |                     ||                    }
|                     |
d
i           }|                     |dg           }	nb|dk    r\|||d<   |                     |                     ||                    }
|                     |
d
          }|                     |d          }	|                     |	|||          S )a  
        fetch a history of internal transfers made on an account
        :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   Nr/   r  r;   r  r4   z,This exchange supports a maximum limit of 50z	page-sizerE  result_listr=   r  rb  )	rK  r  r  r   *spot2PrivateGetAssetInternalTransferRecordr  rR  'contractPrivateGetAccountTransferRecordparse_transfers)r>  rq  r  r  rT  rU  rV  r  r  rb  rW  rE  s               r@  fetch_transferszmexc.fetch_transfers-  s}    !>>?OQUW]^^
E
}}T**H"*4.GJ (-% 2::'(VWWW',$FFt{{SZ\aGbGbccH( ??8VR88D}bAAJJ6!! ',$CCDKKPWY^D_D_``H??8V44D|<<J2 ##J%GGGrA  fromAccount	toAccountc                    |                                   |                     |          }dddd}|                     ||          }|                     ||          }	|Nt          |                                          }
t          | j        dz   d                    |
          z             |	Nt          |                                          }
t          | j        dz   d                    |
          z             |d	         |||	d
}|dk    s|	dk    re|                     |d          }|                     |d          }|t          | j        dz             | 
                    |          }|d	         |d<   |                     |                     ||                    }|                     ||          }|                     ||||d          S )a  
        transfer currency internally between wallets on the same account
        :see: 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)r;   r=   r<   Nz fromAccount must be one of z, z toAccount must be one of r/   )r$  rp  fromAccountTypetoAccountTyper  z: transfer() requires a symbol argument for isolated margin)rp  r   r  )r  r  ru  rM  rN  r   r/   r  r  r!   r  spotPrivatePostCapitalTransferr  r  )r>  rq  rp  r   r  rT  r  accountsfromIdtoIdrN  r  r  r  rW  r  s                   r@  r   zmexc.transfer{  s    	==&&'
 

 !!(K88)44>((D*H H499UY?? Z[[[<((D*F FSW XYYYd^%!	
 
 '''T5F-F-F%%fh77FYYvx00F~'2n(nooo[[((F &tGH66t{{7F7S7STT ))(H=={{;&")
 )
   	rA  c                 z   |                      |d          }|                     |g d          }|                     |d          }||                     |          nd }|                      |d          }d }d }	||dk    rdnd}|dk    rdnd}	n,|                      |d          }|                      |d	          }	|||||                     ||          |                     |d
          |                     |          |                     |	          |                     |                     |dd                    d	S )Nr  )r  r  tranIdr  r  INMAINCONTRACTfromtorp  transact_stater  )	rJ  r/   r  r
  r  rp  r   r  rF  )	ru  safe_string_nrS  r  rv  ry  parse_account_idparse_transfer_statusr  )
r>  r   r  r%  r/   r  r
  	directionaccountFrom	accountTos
             r@  r  zmexc.parse_transfer  se   @ %%h
;;
*K*K*KLL%%h==	/8/D4<<	***4$$Xv66		 %.$%6%6&&ZK'0D'8'8

vII**8V<<K((488I" //
HEE&&x::00==..y99001C1CHN^`g1h1hii

 

 
	
rA  c                 :    ddd}|                      |||          S )Nr;   r=   )r  r  r
  r  s      r@  r  zmexc.parse_account_id  s.    
 
 &&999rA  c                 <    dddd}|                      |||          S )NrC  r  r  )SUCCESSFAILEDWAITr
  r  s      r@  r  zmexc.parse_transfer_status  s1    
 

 &&999rA  c                 &   |                      ||          \  }}|                     | j        di           }|                     |dd          }|                     |||          }|                     |           |                                  |                     |          }|d         ||d}	|||	d<   |||	d<   |                     |ddg          }| 	                    | 
                    |	|                    }
|                     |
|          S )a  
        make a withdrawal
        :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw
        :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  rb  r  r/   )r`  r  rp  Nr  )handle_withdraw_tag_and_paramsrR  r   r  ru  r  r  r  r  #spotPrivatePostCapitalWithdrawApplyr  r  )r>  rq  rp  r  r  rT  r  rb  r  r  rW  s              r@  r   zmexc.withdraw  s$    99#vFFV??4<R@@$$VY@@""8Wg>>7###==&&TN
 

 ?!GFO!(GIYYv	7';<<F;;DKKQW<X<XYY %%h999rA  r  c                 h    d|rdndi}|                      |                     ||                    }|S )Nr  r   r   )-contractPrivatePostPositionChangePositionModer  )r>  r  r  rT  r  rW  s         r@  set_position_modezmexc.set_position_mode  sC    .AAQ
 EEdkkRY[aFbFbcc rA  c                 j    |                      |          }|                     |d          }||dk    dS )NrE  r   )rJ  r  )&contractPrivateGetPositionPositionModerS  )r>  r  rT  rW  r  s        r@  fetch_position_modezmexc.fetch_position_mode)  sF    >>vFF ((6::#q(
 
 	
rA  codesc                     |                                   |                     |          }|                     ||          S )  
        fetch deposit and withdrawal fees
        :see: 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  rs  parse_transaction_feesr>  r(  rT  rW  s       r@  fetch_transaction_feeszmexc.fetch_transaction_fees8  sA     	99&AA< **8U;;;rA  c                 F   i }t          dt          |                    D ]|}||         }|                     |d          }|                     |          }|                     |d          }||                     ||          r|                     ||          ||<   }|i |dS )Nr   r`  rq  )r   rN   rJ  )rt  rO  ru  safe_currencyin_arrayparse_transaction_fee)	r>  rW  r(  withdrawFeesr~  r6  r%  r  rq  s	            r@  r+  zmexc.parse_transaction_feesa  s    q#h--(( 	Q 	QAQKE))%88J))*55H##Hf55D4==u#=#=%)%?%?x%P%PT"$
 
 	
rA  c                 .   |                      |dg           }i }t          dt          |                    D ]]}||         }|                     |d          }|                     | j        d         ||          }|                     |d          }	|	||<   ^|S )Nra  r   rb  r  rg  )rR  rt  rO  ru  r   ry  )
r>  r  r  ra  r}  r  networkEntryr  r  rl  s
             r@  r1  zmexc.parse_transaction_feep  s    6 ook="EEq#k**++ 	& 	&A&q>L((yAAI**4<
+CYPYZZK""<??C"%F;rA  c                     |                                   |                     |          }|                     ||d          S )r*  r`  )r  rs  parse_deposit_withdraw_feesr,  s       r@  fetch_deposit_withdraw_feesz mexc.fetch_deposit_withdraw_fees  sC     	99&AA< //%HHHrA  c                    |                      |dg           }|                     |          }t          dt          |                    D ]r}||         }|                     |d          }|                     ||                     |d                    }|                     |d          d dd d dd|d         |<   s|                     |          S )	Nra  r   rb  rq  rg  )rl  r   )r   rN   r  )rR  deposit_withdraw_feert  rO  ru  rw  ry  $assign_default_deposit_withdraw_fees)	r>  rl  r  ra  r}  r  r4  r  r  s	            r@  parse_deposit_withdraw_feezmexc.parse_deposit_withdraw_fee  s    6 ooc="==**3//q#k**++ 	 	A&q>L((yAAI11)T=M=MhX^=_=_``K  ++L-HH"& 
  "& 	/ 	/F:{++ 88@@@rA  c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||          S )ak  
        fetch the set leverage for a market
        :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-leverage
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
        r  r/   rE  )r  r  "contractPrivateGetPositionLeverager  r  parse_leverage)r>  r  rT  r  r  rW  rE  s          r@  fetch_leveragezmexc.fetch_leverage  s     	V$$fTl
 ::4;;wPV;W;WXX> ~~h33""4000rA  c                 X   d }d }d }t          dt          |                    D ]y}||         }|                     |d          }|                     |d          }	|	dk    r|                     |d          }n|	dk    r|                     |d          }|dk    rdnd}z||d	         |||d
S )Nr   r  r^  r   r  r   r  r  r  )rJ  r  r  longLeverageshortLeverage)rt  rO  rS  )
r>  r  r  r  rA  rB  r~  r6  r  r^  s
             r@  r>  zmexc.parse_leverage  s    
q#h--(( 	D 	DAQKE((
;;H,,UNCCLq  #00
CC"" $ 1 1% D D(0AGJJX&$(*
 
 	
rA  c                     |                      | j        d          }|                     |dd          }d}t          t          |                               |||          \  }}|dk    s|du rd}||gS )a  
         * @ignore
        marginMode specified by params["marginMode"], self.options["marginMode"], self.options["defaultMarginMode"], params["margin"] = True or self.options["defaultType"] = 'margin'
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.margin]: True for trading spot-margin
        :returns Array: the marginMode in lowercase
        r  r<   FNTr  )ru  r   rx  r;  r-   r  )r>  
methodNamerT  defaultValuer  rE  r  r?  s          r@  r  z"mexc.handle_margin_mode_and_params/  s     &&t|]CC>>&(E::
"4..LLZY_amnn
F8##T)9)9#JF##rA  r   GETc                    |                      |d          }|                      |d          }|                     ||          \  }}d }	|dk    s|dk    rX|dk    r | j        d         |         |         dz   |z   }	n*| j        d         |         |         dz   | j        z   dz   |z   }	d}
|d	k    r6|                                 |d
<   |                     | j        dd          |d<   |r|                     |          }
|	d|
z   z  }	|d	k    r|                                  | 	                    | 
                    |
          | 
                    | j                  t          j                  }|	d|z   z  }	| j        |                      | j        dd          d}|dk    s|dk    s|dk    rd|d<   n|dk    s|dk    r| j        d         |         |         dz   |                     ||          z   }	|                     ||                     |                    }|dk    r|r|	d|                     |          z   z  }	n|                                  t%          |                                           }d}| j        |d|                      | j        dd          d}|dk    r|                     |          }|}n7|                     |          }|r ||                     |          z  }|	d|z   z  }	| j        |z   |z   }| 	                    | 
                    |          | 
                    | j                  t          j                  }||d<   |	|||dS )Nr   r   r;   r   r   r  z/api/r  r   r  r  r  ?z&signature=r  )zX-MEXC-APIKEYsourcePOSTPUTDELETEzapplication/jsonContent-Typer   r   r   )ApiKeyzRequest-TimerM  rI  	Signature)rH  r  bodyheaders)ru  resolve_pathr   r5   r2  rS  r   	urlencoderr  hmacencodesecrethashlibsha256apiKeyimplode_paramsr  extract_paramsr   rP  keysort)r>  pathr   r  rT  rQ  rP  sectionaccessrH  paramsEncoded	signaturer  auths                 r@  signz	mexc.sign?  s   ""3**!!#q))((v66ff8 3 3(""i&w/7#=Di&w/7'ADLPSVVY]]M""&*&7&7&9&9{#'+'8'8|UY'Z'Z|$ + $v 6 6s]**""//111 IIdkk-&@&@$++dkBZBZ\c\jkk	)I55%)["..t|XvNN  &  foo6X;M;M*<'
""g&8&8)E"7+F3c9D<O<OPTV\<]<]]CYYvt':':4'@'@AAF!! 83!7!777C//111 1 1 3 344	"k$-$6"..t|XvNN	  V##99V,,DDD!\\&11F *v 6 66sTz){Y.5 IIdkk$&7&7T[9Q9QSZSabb	'0$fdwOOOrA  c
                 R   |d S |                      |dd          }
|
du rd S |                     |dd           }|l|dk    rf|dk    r`| j        dz   |z   }|                     | j        d         ||           |                     | j        d	         ||           t          |          d S )
NrD  FTrq  200r   r9  r8  )rx  ru  r/   throw_broadly_matched_exceptionr  throw_exactly_matched_exceptionr   )r>  rq  reasonrH  r  rQ  rP  rW  requestHeadersrequestBodyrD  responseCodefeedbacks                r@  handle_errorszmexc.handle_errorsw  s    4 ..9e<<d??4''&$??$<5+@+@|WZGZGZw}t+H001I4QYZZZ001I<Yabbb)))trA  )r   r   r   )N)NNNNNNN)w__name__
__module____qualname__r<  rY  r]  r   r  r   r   r  r  r  r   r
   r   r  r	   r  r   r  r  r  rM  rB  rF  r   r   rN  r   rQ  rP  r|  r  r  r   r   r   r~  r  r  r  r   r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r   r&  r   r*  r   r:  r3  rG  rK  rN  rS  r   rX  r\  r`  rf  rv  ry  r  r  r  r   r  r  r  r  r   r  r  r  r  r  r  r  r  r  r   r   r  r  r  r   boolr$  r'  r-  r+  r1  r7  r;  r   r?  r>  r  rc  rn  __classcell__)r?  s   @r@  r-   r-      s^       S S S S Sj #% 
 
 
 
B !#    , ') D DZ D D D DL $& 9 9$v, 9 9 9 9 )+ q q q qf )+ m m m m^ :>b < <s <3 <Y < < < <| i 	 en     6:UW [? [?3 [?s [?# [?\`af\g [? [? [? [?zH H H5 H H H HT   " 26DW[df _K _K# _Kc _KQT _Kkoptku _K _K _K _KB
 
 
4 
 
 
 
 04B O4 O4W O47 O4 O4 O4 O4b 02 C1 C13 C1f C1 C1 C1 C1Jo o6 oV o o o ob 26b "4 "4w "4 "4 "4 "4H RT N N N5 N N N N  gksu ` `3 `i `y `RW ``c ` ` ` `@ KO[_hj ', ', ', ',R CGSW`b    < CGSW`b W. W. W. W.r @B 7+ 7+D$6 7+ 7+ 7+ 7+r 26b n. n.c n.3 n. n. n. n.` *.Dt\^ aK aK3 aKc aK aKcghmcn aK aK aK aKF 6:" 03 03s 03 03 03 03d /3TXac PO PO PO3 POc POhlmrhs PO PO PO POd 154VZce 	K 	K# 	KS 	KPS 	Kjnotju 	K 	K 	K 	K 37TX\eg 	K 	KC 	Ks 	KRU 	K 	K 	K 	K :>D_cln Y Y3 Yc YY\ Y Y Y Y 37r d. d.s d.C d. d. d. d.L 04B 3 3 3 3 3 3> /32 Q3 Q3 Q3 Q3 Q3 Q3fM M M5 M M M M^: : :: : :: : : : : :4 4 4l %'  4=    0 )+  {    2f-H f- f- f- f-P   $& {? {?( {? {? {? {?z -1tRV_a N? N?c N? N?C N? N? N? N?` 9=4^bkm GF GFS GF# GFS GFX[ GF GF GF GFR MO  3    $ 9; H HC H?Q H H H H 68 H H H<N H H H H 9=R \ \S \# \ \ \ \6 37TX\eg F FC Fs FRU F F F FP$
 $
6 $
 $
 $
 $
L 68 7 7 7 7 7 7> 8<$]ajl =Y =Y =YC =YWZ =Y =Y =Y =Y~ 7;2 9B 9BG 9B 9B 9B 9BvJ J J J J JX
 
h 
 
 
 
* DF !; !;s !; !; !; !;F 8: > >3 > > > >< 79  #    8 *.Dt\^ 3I 3I3 3Ic 3I 3Icghsct 3I 3I 3I 3Ij -1tRV_a 0I 0Ic 0I 0IC 0Ifjkvfw 0I 0I 0I 0IdX
 X
x X
; X
 X
 X
 X
t: : : :6 24 , ,S , , , , 26b (3 (3w (3 (3 (3 (3TA Av A A A AF 48dSU   S     6 +/TPT]_ LH LHC LHs LH# LH LH LH LH\ [] 3 3S 3% 3c 3c 3an 3 3 3 3j7
 7
 7
 7
 7
 7
r: : :: : : ?C2 ": ":S ":% ": ": ": ":H =A   c     15R 
 
# 
 
 
 
 9=R '< '<DI '< '< '< '<R
 
 
 
# #8 # # # #J <@ 'I 'I 'I 'I 'I 'IR+A +A +A +A +A +AZ 24 -1 -1S -1 -1 -1 -1 -1^
 
x 
 
 
 
* @BPT $ $ $ $ $ $  &eBSW 6P 6P 6P 6Pp      rA  r-   )2ccxt.base.exchanger   ccxt.abstract.mexcr   rW  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   typingr   ccxt.base.errorsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   ccxt.base.decimal_to_precisionr*   ccxt.base.preciser+   r-    rA  r@  <module>r|     s   ( ' ' ' ' ' * * * * * *  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D  D       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %qQ qQ qQ qQ qQ8[ qQ qQ qQ qQ qQrA  