
    E#iq                         S SK Jr  S SKJr  S SKrS SKJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr   " S S\\5      rg)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)ArgumentsRequired)InvalidOrder)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S\\   4S jjrS0 4S\	S\
S\4S jjrS9S	\S
\S\4S jjr0 4S\	S\4S jjrS9S\S
\S\4S jjrSS0 4S\	S\
S\
S\\   4S jjrS\4S jr0 4S\4S jjrS0 4S\	S\S\S\S\4
S jjrS0 4S\	S\4S jjrS\4S jrS9S\S
\S\4S jjr S0 4S\	S\4S jjr!S0 4S\	S\S \	S!\S\"4
S" jjr#S9S#\S$\$S\"4S% jjr%S9S
\S\&4S& jjr'S'SS0 4S\	S(\	S\
S\
S\\&   4
S) jjr(SSS0 4S\S\
S\
S\\   4S* jjr)SSS0 4S\S\
S\
S\\   4S+ jjr*SSS0 4S\S\
S\
4S, jjr+S- r,S.S/0 SS4S0 jr-S1\.S2\	S3\	S4\	S5\S6\	4S7 jr/S8r0U =r1$ ):mercado   returnc                   > U R                  [        [        U ]  5       SSS/SS0 SS_SS_S	S
_SS
_SS
_SS
_SS
_SS
_SS
_SS
_SS_SS
_SS
_SS_SS_SS
_SS
_0 SS
_SS
_SS
_SS_SS
_SS
_SS
_S S
_S!S
_S"S
_S#S
_S$S
_S%S
_S&S
_S'S
_S(S
_S)S
_E0 S*S
_S+S
_S,S
_S-S
_S.S
_S/S
_S0S
_S1S
_S2S
_S3S
_S4S
_S5S
_S6S
_S7S
_S8S
_S9S
_S:S
_E0 S;S
_S<S
_S=S
_S>S_S?S
_S@S
_SAS
_SBS
_SCS
_SDSE_SFS_SGS
_SHS
_SIS
_SJS_SKS
_SLS
_E0 SMS_SNS_SOS_SPS
_SQS
_SRS
_SSS
_STS
_SUS
_SVS
_SWS
_SXS
_SYS_SZS
_S[S_S\S
_S]S
_ES
S
S
S
S
S
S
S
S
SS^.
ES_S`SaSbScSdSe.SfSgShSiSjSk.SlSmSn/So.Sp/ SqQ0Sr/ SsQ0SpSt/0SpSu/0Sk.SvSwSxSy.0SzS{S{S|S|S}S~.0S
S
S
S S
S
S
S S
S
SS
S.S
S
S
SSS
S
S.S S
S SSSS.S
S
S
SS.S
S S
S
SS.S
SSSS
S
SS.S SS0S.	S S S.S S S.S.[        S.5      $ )Nr   zMercado BitcoinBR  v3CORSTspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTradesemulated
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFees)
fetchUnderlyingAssetsfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModewithdraw15m1h3h1d1w1M)r   r   r   r   r   r   zchttps://user-images.githubusercontent.com/1294454/27837060-e7c58714-60ea-11e7-9192-f05e86adb83f.jpgz"https://www.mercadobitcoin.net/apiz#https://www.mercadobitcoin.net/tapiz$https://www.mercadobitcoin.com.br/v4z%https://api.mercadobitcoin.net/api/v4)publicprivatev4Publicv4PublicNetz!https://www.mercadobitcoin.com.brz)https://www.mercadobitcoin.com.br/api-docz+https://www.mercadobitcoin.com.br/trade-api)logoapiwwwdocget)coinsz{coin}/orderbook/z{coin}/ticker/z{coin}/trades/z{coin}/trades/{from}/z{coin}/trades/{from}/{to}z({coin}/day-summary/{year}/{month}/{day}/post)cancel_orderget_account_info	get_orderget_withdrawallist_system_messageslist_orderslist_orderbookplace_buy_orderplace_sell_orderplace_market_buy_orderplace_market_sell_orderwithdraw_coinz{coin}/candle/candlestradingg~jth?gy&1|?)makertakerlimitsgMbP?g{Gz?g?)BTCBCHETHLTCXRP)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   i  )r   r   r   r   r   r   r   r   )	sandboxr/   createOrdersr]   rf   rc   rh   fetchClosedOrdersr_   )linearinverse)r"   r$   r%   )idname	countries	rateLimitversionhas
timeframesurlsr   feesoptionsfeaturesprecisionMode)deep_extendsuperr   describer   )self	__class__s    T/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/async_support/mercado.pyr   mercado.describe   s   gt = ?%``` %` 	`
 %` %` U` $U` '` ` t` $U`  ` $T` t`  (!`" '#`$ (%`& "5'`( !%)`* +`, &u-`. "5/`0 +E1`2 )%3`4 #E5`6 ,U7`8 '9`: (;`< "5=`> &u?`@ (A`B 1%C`D &uE`F 'G`H (I`J #EK`L *5M`N $UO`P uQ`R "5S`T *5U`V +EW`X )%Y`Z  [`\ !%]`^ %e_`` $Ua`b &uc`d -ee`f /g`h "5i`j #Ek`l +Em`n o`p !%q`r !%s`t "5u`v &uw`x +Ey`z  {`| d}`~ $U`@ +EA`B %eC`D "4E`F uG`H #EI`J dK`L !$M`N tO`P  Q`R 'S`T $UU`V !%W`X *5Y`Z ([`\ %e]`^ )%_`` )%a`b tc`d e`f tg`h "5i`j #Ek`l */*/ %$)',$"!&#( `D  ~BD F#J	 ;?A   
  " ( ! C&P ""     %&+(-,0,1).+06:#(#("&#(	( #($)$)+/26/4#()$, %)&+!%$*%+*.& ',#($)*.	# ',!%#($)*.( ',!$$*%+#($)*.$ *.#o:x ##
 ##ADJ 'qyB
 y y	    c                 f  #    U R                  U5      I Sh  vN n/ nU R                  U R                  S0 5      n[        S[	        U5      5       H  nX%   nUnSnU R                  U5      n	U R                  U5      n
X-   nUR                  0 SU_SU	S-   U
-   _SU	_S	U
_S
S_SU_SU_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSU R                  S5      U R                  S5      S.SSS.U R                  XG5      SS.U R                  S5      SS.SSS.S.SUS.
E5        M     U$  GN7f)z
retrieves data on all markets for mercado
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
Nr   r   BRLr   symbol/basequotesettlebaseIdquoteIdsettleIdtyper"   Tr#   Fr$   r%   r&   activecontractr   z1e-8z1e-5)amountprice)minmax)r   r   r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionr   createdinfo)	publicGetCoins
safe_valuer   rangelensafe_currency_codeappendparse_numbersafe_number)r   paramsresponseresultamountLimitsicoinr   r   r   r   r   s               r   fetch_marketsmercado.fetch_markets  s     ,,V44, t||XrBq#h-(A;DFG**62D++G4EBMM 0b0$*u,0 0 	0
 $0 &0 70 D0 0 0 %0 0 %0 %0 $0  E!0" $#0$   $"&""//7!..v6  $#!
  $//E#
  $008#
  $#$  _0 0 )p a 5s   D1D.DD1Nr   r   c                    #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XS5      5      I Sh  vN nU R	                  XdS   5      $  NX N7f)a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr   r   r   )load_marketsmarketpublicGetCoinOrderbookextendparse_order_book)r   r   r   r   r  requestr   s          r   fetch_order_bookmercado.fetch_order_bookh  sv      !!!V$F6N
 44T[[5QRR$$Xh/?@@ 	"
 Ss!   A3A/?A3A1A31A3tickerr  c                    U R                  S U5      nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _SU R                  US5      _SU R                  US5      _SU R                  US	5      _S
S _SU R                  US5      _SS _SS _SS _SU_SU_SS _SS _SS _SS _U R                  US5      S US.EU5      $ )Ndatelastr   	timestampdatetimehighlowbidbuy	bidVolumeasksell	askVolumevwapopenclosepreviousClosechange
percentageaveragevol)
baseVolumequoteVolumer   )safe_symbolsafe_timestampsafe_stringsafe_tickeriso8601)r   r  r  r   r  r  s         r   parse_tickermercado.parse_tickerx  sy    !!$/''7	/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FF3!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **659)!
* + 	r   c                 
  #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U R                  XB5      5      I Sh  vN nU R	                  US0 5      nU R                  Xc5      $  Nh N*7f)ah  
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>`
Nr   r   r  )r  r  publicGetCoinTickerr  r   r)  )r   r   r   r  r	  r   r  s          r   fetch_tickermercado.fetch_ticker  s      !!!V$F6N
 11$++g2NOO8R8   00+ 	"
 Ps!   BA??BB)BBtradec                    U R                  USS5      nU R                  S U5      nU R                  USS5      nS nU R                  US5      nU R                  US5      nU R                  USS5      nU R                  US	5      n	S n
U	b  U	S S
.n
U R	                  UUUU R                  U5      US   S UUS UUS U
S.U5      $ )Nr  executed_timestamptidoperation_idr   r   r   quantityfee_rater   currencyr   )r   r   r  r  r   orderr   sidetakerOrMakerr   r   r   fee)safe_timestamp_2safe_marketsafe_string_2r&  
safe_trader(  )r   r/  r  r  r   r   r9  r   r   feeCostr;  s              r   parse_trademercado.parse_trade  s    ))%9MN	!!$/un=v.  0##E8Z@""5*5 C "Y/X&  
  	r   sincec                 \  #    U R                  5       I Sh  vN   U R                  U5      nSnSUS   0nUb  US-  nU R                  US-  5      US'   U R                  US5      nUb  US	-  n[	        X5      " U R                  Xt5      5      I Sh  vN n	U R                  XX#5      $  N N7f)
a  
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
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NpublicGetCoinTradesr   r   Fromr   fromtoTo)r  r  parse_to_intsafe_integergetattrr  parse_trades)
r   r   rC  r   r   r  methodr	  rH  r   s
             r   fetch_tradesmercado.fetch_trades  s      !!!V$&F6N
 fF"//=GFOvt,>dNF .t{{7/KLL  5@@ 	" Ms"   B,B(A:B,B*B,*B,c                    U R                  US0 5      nU R                  US0 5      nSU0n[        UR                  5       5      n[        S[	        U5      5       Ho  nXV   nU R                  U5      nXs;   d  M  U R                  X70 5      n	U R                  5       n
U R                  U	S5      U
S'   U R                  U	S5      U
S'   XU'   Mq     U R                  U5      $ )Nresponse_databalancer   r   	availablefreetotal)	r   listkeysr   r   r   accountr&  safe_balance)r   r   databalancesr   currencyIdsr   
currencyIdcoderS  rY  s              r   parse_balancemercado.parse_balance  s    x"=??4B7)8==?+q#k*+A$J**:6D%//(C,,."&"2"27K"H#'#3#3GW#E &t ,   ((r   c                    #    U R                  5       I Sh  vN   U R                  U5      I Sh  vN nU R                  U5      $  N. N7f)a  
query for balance and get the amount of funds available for trading or funds locked in orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
N)r  privatePostGetAccountInfor`  )r   r   r   s      r   fetch_balancemercado.fetch_balance  sE      !!!77??!!(++ 	"?s   A	AA	AA	A	r   r9  r   r   c                   #    U R                  5       I Sh  vN   U R                  U5      nSUS   0nU R                  U5      S-   n	US:X  a6  SU	-   n	U R                  US   U5      US'   U R	                  US   U5      US	'   OS
U	-   n	US:X  a{  Uc  [        U R                  S-   5      eU R                  U5      n
U R                  U5      nU R                  [        R                  " X5      5      nU R                  US   U5      US'   OU R	                  US   U5      US	'   [        X	5      " U R                  X5      5      I Sh  vN nU R                  U[        US   S   S   5      S.U5      $  GNZ N.7f)a  
create a trade order
:param str symbol: unified symbol of the market to create an order in
:param str type: 'market' or 'limit'
:param str side: 'buy' or 'sell'
:param float amount: how much of currency you want to trade in units of base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
N	coin_pairr   r   r   privatePostPlacer   limit_pricer4  privatePostPlaceMarketr  a    createOrder() requires the price argument with market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amountr   rR  r8  order_id)r   r   )r  r  
capitalizeprice_to_precisionamount_to_precisionr   r   number_to_stringparse_to_numericr   
string_mulrL  r  
safe_orderstr)r   r   r   r9  r   r   r   r  r	  rN  amountStringpriceStringr   r   s                 r   create_ordermercado.create_order  s     !!!V$
 &07?'&0F%)%<%<VH=Mu%UGM""&":":6(;KV"TGJ-6Fu}=&tww  2t  (t  u  u#44V<"33E:,,W-?-?-Z["&"9"9&:JD"Q&*&>&>vh?OQW&X
# .t{{7/KLLh/8DE 
  	/ 	"* Ms"   E5E0D-E5E3,E53E5r   c                 h  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   US.nU R	                  U R                  XS5      5      I Sh  vN nU R                  US0 5      nU R                  US0 5      nU R                  X5      $  N| N=7f)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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz) cancelOrder() requires a symbol argumentr   rg  rk  rR  r8  )	r   r   r  r  privatePostCancelOrderr  r   	safe_dictparse_order	r   r   r   r   r  r	  r   responseDatar8  s	            r   r   mercado.cancel_order5  s      >#DGG.Y$YZZ!!!V$
 44T[[5QRR0 x"E|Wb9..A 	" Ss"   /B2B.A B22B03<B20B2statusc                 2    SSSS.nU R                  X!U5      $ )Nr  canceledclosed)234)r&  )r   r  statusess      r   parse_order_statusmercado.parse_order_statusa  s'    

 &99r   r8  c                    U R                  US5      nU R                  US5      nS nSU;   a
  US:X  a  SOSnU R                  U R                  US5      5      nU R                  US5      nU R                  Xr5      nU R                  US5      nU R                  US	5      US
   S.n	U R                  US5      n
U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R	                  US/ 5      nU R                  0 SU_SU_SS _SU_SU R                  U5      _SU_SUS   _SS_SS _SS _SU_SU
_SS _S S _S!U_S"U_S#U_S UU	US$.EU5      $ )%Nrk  
order_type1r  r  r  rg  created_timestampr;  r   r6  ri  executed_price_avgr4  executed_quantityupdated_timestamp
operationsr   r   clientOrderIdr  r  lastTradeTimestampr   r   r   r   postOnlyr9  r   r   r   r   r   filled)	remainingr  r;  trades)r&  r  r=  r%  r   rr  r(  )r   r8  r  r   r  r9  r  marketIdr  r;  r   r   r   r  r  	rawTradess                   r   r|  mercado.parse_orderi  s*   4 eZ0%%e\:
5 '3.5VD(()9)9%)JK##E;7!!(3''/BC	$$UE2w
   6""5*>?!!%4!!%)<=!008KLOOE<<	  
E 
" 
 T 
 	 

 Y/ 
 !"4 
 fX& 
 G 
 4 
  
 D 
 U 
 D 
 D 
 w 
  f! 
" f# 
$ + 
, - 	r   c                 x  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   [	        U5      S.nU R                  U R                  XS5      5      I Sh  vN nU R                  US0 5      nU R                  US5      nU R                  X5      $  N N<7f)a/  
fetches information on an order made by the user
: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
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nz( fetchOrder() requires a symbol argumentr   ry  rR  r8  )
r   r   r  r  intprivatePostGetOrderr  r   r{  r|  r}  s	            r   fetch_ordermercado.fetch_order  s      >#DGG.X$XYY!!!V$B
 11$++g2NOOx"E|W5.. 	" Ps"   /B:B6A	B:;B8<;B:8B:r_  addresstagc                   #    U R                  XE5      u  pEU R                  U5        U R                  5       I Sh  vN   U R                  U5      nUS   [	        US5      US.nUS:X  a(  SU;   nU(       d  [        U R                  S-   U-   5      eO\US:w  aV  S	U;   n	U	(       d  [        U R                  S
-   U-   5      eUS:X  a)  Uc"  SU;  a  [        U R                  S-   U-   5      eOXGS'   U R                  U R                  Xu5      5      I Sh  vN n
U R                  U
S0 5      nU R                  US5      nU R                  X5      $  GN N=7f)aO  
make a withdrawal
: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>`
Nr   z.10f)r   r4  r  r   account_refz7 withdraw() requires account_ref parameter to withdraw r   tx_feez2 withdraw() requires tx_fee parameter to withdraw r   destination_tagzM withdraw() requires a tag argument or destination_tag parameter to withdraw rR  
withdrawal)handle_withdraw_tag_and_paramscheck_addressr  r7  formatr   r   privatePostWithdrawCoinr  r   r{  parse_transaction)r   r_  r   r  r  r   r7  r	  r  r  r   r~  r  s                r   r   mercado.withdraw  sv     99#F7#!!!==&TNvv.

 5=(F2K'2k(knr(rss U]&(F'2f(fim(mnnu};-7/  ;J  1J  MQ  1Q  R  R 8 25-.55dkk'6RSS( x"E^^L,?
%%j;;W 	"* Ts"   8EECEE;EEtransactionr7  c                     U R                  S U5      n0 SU R                  US5      _SS _SS _SS _SS _SS _SS _SS _S	S _S
S _SUS   _SS _SS _SS _SS _SS _SS _S S US.E$ )Nr   txidr  r  networkaddressFromr  	addressTor   r   r7  r_  r  updatedtagFromr  tagTocomment)internalr;  r   )safe_currencyr&  )r   r  r7  s      r   r  mercado.parse_transaction  s
    %%dH5
$"";5
D
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 	
r   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr                  )rK  r   )r   ohlcvr  s      r   parse_ohlcvmercado.parse_ohlcv#  sl    eQ'UA&UA&UA&UA&UA&
 	
r   r   	timeframec           	      P  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  X"5      US   S-   US   -   S.nUc  SnUbA  U R	                  US-  5      US'   U R                  US   X@R                  U5      -  5      US	'   O/U R                  5       US	'   US	   X@R                  U5      -  -
  US'   U R                  U R                  Xu5      5      I Sh  vN nU R                  US
SSSSS5      n	U R                  XX#U5      $  GN N17f)a  
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
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nr   -r   )
resolutionr   d   r   rG  rH  tohlcv)r  r  r&  r   rJ  sumparse_timeframesecondsv4PublicNetGetCandlesr  convert_trading_view_to_ohlcvparse_ohlcvs)
r   r   r  rC  r   r   r  r	  r   r   s
             r   fetch_ohlcvmercado.fetch_ohlcv-  s1     !!!V$**4??IQVns*VG_<
 =E"//=GFO HHWV_e>R>RS\>]6]^GDM LLNGDM%dmu7K7KI7V/VWGFO33DKK4PQQ44XsCcSVX[\  )EJJ! 	" Rs"   D&D!CD&2D$3/D&$D&c                 h  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nSUS   0nU R	                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $  N| N>7f)a  
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
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nz) fetchOrders() requires a symbol argumentrg  r   rR  orders	r   r   r  r  privatePostListOrdersr  r   	safe_listparse_orders
r   r   rC  r   r   r  r	  r   r~  r  s
             r   fetch_ordersmercado.fetch_ordersI  s      >#DGG.Y$YZZ!!!V$
 33DKK4PQQx"Eh;  >> 	"
 Rs!   /B2B.?B21B02=B20B2c                 j  #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   SS.nU R	                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      n	U R                  XX#5      $  N} N>7f)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 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>`
Nz- fetchOpenOrders() requires a symbol argumentr   z[2])rg  status_listrR  r  r  r  s
             r   fetch_open_ordersmercado.fetch_open_orders^  s      >#DGG.]$]^^!!!V$ 
 33DKK4PQQx"Eh;  >> 	" Rs"   /B3B/A B32B13=B31B3c                   #    Uc  [        U R                  S-   5      eU R                  5       I Sh  vN   U R                  U5      nUS   SS.nU R	                  U R                  Xd5      5      I Sh  vN nU R                  US0 5      nU R                  US/ 5      n	U R                  XX#5      n
U R                  U
5      nU R                  XS   X#5      $  N Nd7f)	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 argumentr   T)rg  	has_fillsrR  r  r   )
r   r   r  r  r  r  r   r  orders_to_tradesfilter_by_symbol_since_limit)r   r   rC  r   r   r  r	  r   r~  	ordersRawr  r  s               r   fetch_my_tradesmercado.fetch_my_tradest  s      >#DGG.[$[\\!!!V$
 33DKK4PQQx"EOOL(B?	""9eC&&v.009I5XX 	" Rs#   /CCA C2C3A#CCc                     / n[        S[        U5      5       HG  nU R                  X   S/ 5      n[        S[        U5      5       H  nUR                  XE   5        M     MI     U$ )Nr   r  )r   r   r   r   )r   r  r   r   r  ys         r   r  mercado.orders_to_trades  sZ    q#f+&A__VY"=F1c&k*fi( + ' r   r   GETc                    U R                   S   U   S-   nU R                  X@R                  U5      5      nUS:X  d  US:X  d  US:X  a2  XpR                  X5      -  nU(       a  USU R	                  U5      -   -  nOU R                  5         XpR                  S-   -  nU R                  5       n	U R	                  U R                  UU	S.U5      5      nSU R                  -   S-   S-   U-   n
S	U R                  U R                  U R                  U
5      U R                  U R                  5      [        R                  5      S
.nXsXeS.$ )Nr   r   r   r   r   ?)tapi_method
tapi_noncez/tapi/z!application/x-www-form-urlencoded)zContent-TypezTAPI-IDzTAPI-MAC)urlrN  bodyheaders)r   omitextract_paramsimplode_params	urlencodecheck_required_credentialsr   noncer  apiKeyhmacencodesecrethashlibsha512)r   pathr   rN  r   r  r  r  queryr  auths              r   signmercado.sign  s2   iis#c)		&"5"5d";<8O
!2}8L&&t44CsT^^E222++-<<#%%CJJLE>>$++##/ # D dll*S036=D C;; IIdkk$&7T[[9QSZSaSabG
 dOOr   httpCodereasonr  rN  r  r  c
                     Uc  g U R                  US5      n
U
b*  [        U R                  S-   U R                  U5      -   5      eg )Nerror_message )r   r   r   json)r   r  r  r  rN  r  r  r   requestHeadersrequestBodyerrorMessages              r   handle_errorsmercado.handle_errors  sG     xA##		(0C CDDr    )N)2__name__
__module____qualname____firstlineno__r   r   r   r	   r  rs  r   r   r
  dictr   r)  r-  r   rA  rO  r   r`  rd  r   r   floatr
   rv  r   r   r  r   r|  r  r   r   r   r  rW  r  r  r  r  r  r  r  r  r  __static_attributes____classcell__)r   s   @r   r   r      s   z# zx *, VV Vp @DB AS A AS\ A %4 % %6 %N 68 1 1F 1< v  > <@d[] A AS A Abfglbm A0) )  *, , , mqy{ % %I %Y %X] %fi %N 9=R */S */# */X: :D Dv D DL 8<B /C / /* QU]_ 7<3 7< 7< 7<# 7<do 7<r$
T $
X $
Q\ $
L
 
4 
 ?DRVeirt K K KC K_b Ky}  C  zD K8 04$UYbd ? ?C ?s ?imnsit ?* 59tZ^gi ?c ? ?TW ?nrsxny ?, 37TX\eg YC Ys YRU Y0 &eBSW P.c 3 S # X\ dg  r   r   ) ccxt.async_support.base.exchanger   ccxt.abstract.mercador   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r   r  r   r   <module>r!     sJ    6 -  O  O  O  O  * . ) 4 %dh dr   