
    !:h4                         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 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  G d dee      Zy)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)ArgumentsRequired)InvalidOrder)	TICK_SIZE)Precisec                   Z    e Zd Zdef fdZi fdee   fdZdi fdede	de
fdZd5ded	edefd
Zi fdedefdZd5ded	edefdZddi fdede	de	dee   fdZdefdZi fdefdZdi fdededededef
dZdi fdedefdZdefdZd5ded	edefdZdi fdedefdZ di fdededede!fd Z"d5d!ed"e#de!fd#Z$d5d	ede%fd$Z&d%ddi fdede	de	dee%   fd&Z'dddi fdede	de	dee   fd'Z(dddi fdede	de	dee   fd(Z)dddi fdede	de	fd)Z*d* Z+d+d,i ddfd-Z,d.e-d/ed0ed1ed2ed3efd4Z. xZ/S )6mercadoreturnc                    | j                  t        t        |          dddg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d0dd1dd2dd3d
d4d
d5d
d6d
d7d
d8d
d9d
d:d
d;dd
dd
d
d
d
d
d
dd<	d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLgdMdNg dOidPg dQidNdRgidNdSgidIdTdUdVdWidXdYdYdZdZd[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dad
d d
d
ddbd
dcd_d_d
d
dddd dedidf	d d dgd d dgdht        di      S )jNr   zMercado BitcoinBR  v3CORSTspotmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTradesemulated
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTicker)	fetchTickersfetchTradesfetchTradingFeefetchTradingFeesreduceMarginsetLeveragesetMarginModesetPositionModewithdraw15m1h3h1d1w1M)r]   r^   r_   r`   ra   rb   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+   createOrdersrC   rH   rG   rJ   fetchClosedOrdersrE   )linearinverse)r!   r#   r$   )idname	countries	rateLimitversionhas
timeframesurlsrh   feesoptionsfeaturesprecisionMode)deep_extendsuperr   describer   )self	__class__s    T/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/mercado.pyr   zmercado.describe   s   gt = ?%=== %= 	=
 %= %= U= t= $U=  = $T= t= (= '= (=  "5!=" #=$ )%%=& ''=( ()=* &u+=, (-=. 1%/=0 &u1=2 #E3=4 *55=6 $U7=8 "59=: *5;=< +E==>  ?=@ %eA=B "5C=D E=F !%G=H  I=J dK=L +EM=N "4O=P dQ=R !$S=T tU=V  W=X 'Y=Z $U[=\ !%]=^ *5_=` (a=b %ec=d )%e=f tg=h !&##($) %$!&#( y=~  ~BD F#J	 ;?A   
  " ( ! C&P ""     %&+(-,0,1).+06:#(#("&#(	( #($)$)+/26/4#()$, %)&+!%$*%+*.& ',#($)*.	# ',!%#($)*.( ',!$$*%+#($)*.$ *.#o:x ##
 ##ADJ 'kVB
 V V	    c                 h  K   | j                  |       d{   }g }| j                  | j                  di       }t        dt	        |            D ]  }||   }|}d}| j                  |      }	| j                  |      }
|
|	z   }|j                  i d|d|	dz   |
z   d|	d	|
d
dd|d|dddddddddddddddddddddddddd| j                  d      | j                  d      dddd| j                  ||      dd| j                  d      ddddddd|d
        |S 7 w)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_marketszmercado.fetch_markets   s     ,,V44, t||XrBq#h-( 7	A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  $#!
  $//fE#
  $008#
  $#$  _0 07	p a 5s   D2D/DD2Nr   r   c                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||d         S 7 Z7 w)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_bookzmercado.fetch_order_bookE  s|      !!!V$F6N
 44T[[&5QRR$$Xvh/?@@ 	"
 Ss"   A5A1A A5A3A53A5tickerr   c                    | j                  d |      }| j                  |d      }| j                  |d      }| j                  i d|d|d| j	                  |      d| j                  |d      d| j                  |d      d| j                  |d	      d
d d| j                  |d      dd dd dd d|d|dd dd dd dd | j                  |d      d |d|      S )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_tickerzmercado.parse_tickerU  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                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  |di       }| j                  ||      S 7 j7 +w)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>`
        Nr   r   r   )r   r   publicGetCoinTickerr   r   r  )r   r   r   r   r   r   r   s          r   fetch_tickerzmercado.fetch_ticker|  s      !!!V$F6N
 11$++gv2NOO8R8   00+ 	"
 Ps"   BBA BB*BBtradec                 ~   | j                  |dd      }| j                  d |      }| j                  |dd      }d }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d	      }	d }
|	|	d d
}
| j	                  |||| j                  |      |d   d ||d ||d |
d|      S )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   r  r   r   feeCostr  s              r   parse_tradezmercado.parse_trade  s    ))%9MN	!!$/un=v.  0##E8Z@""5*5 C "Y/X&  
  	r   sincec                 `  K   | j                          d{    | j                  |      }d}d|d   i}||dz  }| j                  |dz        |d<   | j                  |d      }||d	z  } t	        | |      | j                  ||             d{   }	| j                  |	|||      S 7 7 w)
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   r  r   r   r   methodr   r  r   s
             r   fetch_tradeszmercado.fetch_trades  s      !!!V$&F6N
 fF"//=GFOvt,>dNF.v.t{{7F/KLL  65%@@ 	" Ms"   B.B*A:B.B,B.,B.c                    | j                  |di       }| j                  |di       }d|i}t        |j                               }t        dt	        |            D ]o  }||   }| j                  |      }||v s| j                  ||i       }	| j                         }
| j                  |	d      |
d<   | j                  |	d      |
d<   |
||<   q | j                  |      S )Nresponse_databalancer   r   	availablefreetotal)	r   listkeysr   r   r   accountr   safe_balance)r   r   databalancesr   currencyIdsr   
currencyIdcoder(  r.  s              r   parse_balancezmercado.parse_balance  s    x"=??4B7)8==?+q#k*+ 	'A$QJ**:6DX%//(JC,,."&"2"27K"H#'#3#3GW#E &t	'   ((r   c                    K   | j                          d{    | j                  |       d{   }| j                  |      S 7 .7 w)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   privatePostGetAccountInfor5  )r   r   r   s      r   fetch_balancezmercado.fetch_balance  sG      !!!77??!!(++ 	"?s   A	AA	AA	A	r   r  r   r   c                   K   | j                          d{    | j                  |      }d|d   i}| j                  |      dz   }	|dk(  r6d|	z   }	| j                  |d   |      |d<   | j	                  |d   |      |d	<   nd
|	z   }	|dk(  rz|t        | j                  dz         | j                  |      }
| j                  |      }| j                  t        j                  |
|            }| j                  |d   |      |d<   n| j	                  |d   |      |d	<    t        | |	      | j                  ||             d{   }| j                  |t        |d   d   d         d|      S 7 Y7 .w)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_pricer  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   r'  r  order_id)r   r   )r   r   
capitalizeprice_to_precisionamount_to_precisionr   r   number_to_stringparse_to_numericr   
string_mulr"  r   
safe_orderstr)r   r   r   r  r   r   r   r   r   r$  amountStringpriceStringr   r   s                 r   create_orderz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-?-?k-Z["&"9"9&:JD"Q&*&>&>vh?OQW&X
#.v.t{{7F/KLLh/8DE 
  	/ 	"* Ms"   E4E/D,E4E2,E42E4r   c                 j  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   |d}| j	                  | j                  ||             d{   }| j                  |di       }| j                  |di       }| j                  ||      S 7 ~7 >w)aD  
        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   r:  r>  r'  r  )	r   r   r   r   privatePostCancelOrderr   r   	safe_dictparse_order	r   r   r   r   r   r   r   responseDatar  s	            r   rn   zmercado.cancel_order  s      >#DGG.Y$YZZ!!!V$
 44T[[&5QRR0 x"E|Wb9v..A 	" Ss"   .B3B/AB32B13=B31B3statusc                 4    dddd}| j                  |||      S )Nr   canceledclosed)234)r   )r   rQ  statusess      r   parse_order_statuszmercado.parse_order_status>  s)    

 &&99r   r  c                    | j                  |d      }| j                  |d      }d }d|v r	|dk(  rdnd}| j                  | j                  |d            }| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d	      |d
   d}	| j                  |d      }
| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |dg       }| j                  i d|d|dd d|d| j                  |      d|d|d   dddd dd d|d|
dd d d d!|d"|d#|d ||	|d$|      S )%Nr>  
order_type1r   r   rQ  r:  created_timestampr  r   r  r<  executed_price_avgr  executed_quantityupdated_timestamp
operationsr   r   clientOrderIdr   r   lastTradeTimestampr   r   r   r   postOnlyr  r   r   r   r   r   filled)	remainingrQ  r  trades)r   rY  r  r   r   rE  r  )r   r  r   r   r[  r  rQ  marketIdr   r  r   r   r   re  rc  	rawTradess                   r   rN  zmercado.parse_orderF  s,   4 eZ0%%e\:
5 '3.5VD(()9)9%)JK##E;7!!(F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                 z  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   t	        |      d}| j                  | j                  ||             d{   }| j                  |di       }| j                  |d      }| j                  ||      S 7 7 =w)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   rK  r'  r  )
r   r   r   r   intprivatePostGetOrderr   r   rM  rN  rO  s	            r   fetch_orderzmercado.fetch_order  s      >#DGG.X$XYY!!!V$B
 11$++gv2NOOx"E|W5v.. 	" Ps"   .B;B7A
B;;B9<<B;9B;r4  addressc                   K   | j                  ||      \  }}| j                  |       | j                          d{    | j                  |      }|d   t	        |d      |d}|dk(  r!d|v }|slt        | j                  dz   |z         |dk7  rLd	|v }	|	st        | j                  d
z   |z         |dk(  r&|d|vr t        | j                  dz   |z         ||d<   | j                  | j                  ||             d{   }
| j                  |
di       }| j                  |d      }| j                  ||      S 7 7 =w)a  
        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   r  rn  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 r'  
withdrawal)handle_withdraw_tag_and_paramscheck_addressr   r  formatr   r   privatePostWithdrawCoinr   r   rM  parse_transaction)r   r4  r   rn  tagr   r  r   rp  rq  r   rP  rs  s                r   r\   zmercado.withdraw  sv     99#vFV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14G-.55dkk'66RSS( x"E^^L,?
%%j(;;W 	"* Ts"   :E D<CE  D><E >E transactionr  c                     | j                  d |      }i d| j                  |d      dd dd dd dd dd d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   txidr   r   networkaddressFromrn  	addressTor   r   r  r4  rQ  updatedtagFromry  tagTocomment)internalr  r   )safe_currencyr   )r   rz  r  s      r   rx  zmercado.parse_transaction  s
    %%dH5
$"";5
D
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 	
r   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr                  )r!  r   )r   ohlcvr   s      r   parse_ohlcvzmercado.parse_ohlcv   sl    eQ'UA&UA&UA&UA&UA&
 	
r   r]   c           	      X  K   | j                          d{    | j                  |      }| j                  | j                  ||      |d   dz   |d   z   d}|d}|B| j	                  |dz        |d<   | j                  |d   || j                  |      z        |d	<   n0| j                         |d	<   |d	   || j                  |      z  z
  |d<   | j                  | j                  ||             d{   }| j                  |d
ddddd      }	| j                  |	||||      S 7 7 3w)aQ  
        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   r  r  tohlcv)r   r   r   r   r   sumparse_timeframesecondsv4PublicNetGetCandlesr   convert_trading_view_to_ohlcvparse_ohlcvs)
r   r   	timeframer  r   r   r   r   r   rz   s
             r   fetch_ohlcvzmercado.fetch_ohlcv
  s?     !!!V$**4??IyQVns*VG_<
 =E"//=GFO HHWV_ed>R>RS\>]6]^GDM LLNGDM%dmut7K7KI7V/VWGFO33DKK4PQQ44XsCcSVX[\  &)UEJJ! 	" Rs"   D*D%CD*4D(51D*(D*c                 l  K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}| j	                  | j                  ||             d{   }| j                  |di       }| j                  |dg       }	| j                  |	|||      S 7 7 @w)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 argumentr:  r   r'  orders	r   r   r   r   privatePostListOrdersr   r   	safe_listparse_orders
r   r   r  r   r   r   r   r   rP  r  s
             r   fetch_orderszmercado.fetch_orders&  s      >#DGG.Y$YZZ!!!V$
 33DKK4PQQx"Eh;  >> 	"
 Rs"   .B4B0A B41B22?B42B4c                 n  K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dd}| j	                  | j                  ||             d{   }| j                  |di       }| j                  |dg       }	| j                  |	|||      S 7 7 @w)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])r:  status_listr'  r  r  r  s
             r   fetch_open_orderszmercado.fetch_open_orders;  s      >#DGG.]$]^^!!!V$ 
 33DKK4PQQx"Eh;  >> 	" Rs"   .B5B1AB52B33?B53B5c                   K   |t        | j                  dz         | j                          d{    | j                  |      }|d   dd}| j	                  | j                  ||             d{   }| j                  |di       }| j                  |dg       }	| j                  |	|||      }
| j                  |
      }| j                  ||d   ||      S 7 7 hw)	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)r:  	has_fillsr'  r  r   )
r   r   r   r   r  r   r   r  orders_to_tradesfilter_by_symbol_since_limit)r   r   r  r   r   r   r   r   rP  	ordersRawr  rg  s               r   fetch_my_tradeszmercado.fetch_my_tradesQ  s      >#DGG.[$[\\!!!V$
 33DKK4PQQx"EOOL(B?	""9feUC&&v.009I5RWXX 	" Rs#   .CCAC2C3A'CCc                     g }t        dt        |            D ]F  }| j                  ||   dg       }t        dt        |            D ]  }|j                  ||           H |S )Nr   rg  )r   r   r   r   )r   r  r   r   rg  ys         r   r  zmercado.orders_to_tradesi  sh    q#f+& 	)A__VAY"=F1c&k* )fQi()	) r   rc   GETc                    | j                   d   |   dz   }| j                  || j                  |            }|dk(  s
|dk(  s|dk(  r/|| j                  ||      z  }|r|d| j	                  |      z   z  }n| j                          || j                  dz   z  }| j                         }	| j	                  | j                  ||	d|            }d| j                  z   dz   dz   |z   }
d	| j                  | j                  | j                  |
      | j                  | j                        t        j                        d
}||||dS )Nrh   r   rc   re   rf   ?)tapi_method
tapi_noncez/tapi/z!application/x-www-form-urlencoded)zContent-TypezTAPI-IDzTAPI-MAC)urlr$  bodyheaders)r   omitextract_paramsimplode_params	urlencodecheck_required_credentialsr   noncer   apiKeyhmacencodesecrethashlibsha512)r   pathrh   r$  r   r  r  r  queryr  auths              r   signzmercado.signq  s=   iis#c)		&$"5"5d";<8O
!2}8L4&&tV44CsT^^E222++-4<<#%%CJJLE>>$++##/ # D dll*S036=D C;; IIdkk$&7T[[9QSZSaSabG
 fdwOOr   httpCodereasonr  r$  r  r  c
                     |y | j                  |d      }
|
*t        | j                  dz   | j                  |      z         y )Nerror_message )r   r   r   json)r   r  r  r  r$  r  r  r   requestHeadersrequestBodyerrorMessages              r   handle_errorszmercado.handle_errors  sG     xA##		(0C CDDr   )N)0__name__
__module____qualname__r   r   r   r	   r   rF  r   r   r   dictr   r  r  r   r  r%  r   r5  r8  r   r   floatr
   rI  r   rn   rY  r   rN  rm  r   r\   r   rx  r,  r  r  r  r  r  r  r  rk  r  __classcell__)r   s   @r   r   r      s   W# Wr *, 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 / /* JNVX 7<3 7< 7< 7<]h 7<r$
T $
X $
Q\ $
L
 
4 
 8=4^bkm K KS KX[ Krvw{r| 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   <module>r     sJ    6 -  O  O  O  O  * . ) 4 %Ah Ar   