
    eii                         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dS )    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTransaction)List)ExchangeError)ArgumentsRequired)InvalidOrder)	TICK_SIZE)Precisec                       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d7ded	edefd
Zi fdedefdZd7d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d7d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de!f
d!Z"d7d"ed#e#de!fd$Z$d7d	ede%fd%Z&d&ddi fded'ede	de	dee%         f
d(Z'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,d0e-d1ed2ed3ed4ed5efd6Z. xZ/S )8mercadoreturnc                    |                      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
d/d
d0d
d1d
d2d
d3d
d4d
d5d
d6d
d7d
d8d
d9d
d:d
i d;d
d<d
d=d
d>dd?d
d@d
dAd
dBd
dCd
dDdEdFddGd
dHd
dId
dJddKd
dLd
i dMddNddOddPd
dQd
dRd
dSd
dTd
dUd
dVd
dWd
dXd
dYddZd
d[dd\d
d]d
d
d
d
d
d
d
d
d
d
dd^
d_d`dadbdcdddedfdgdhdidjdkdldmdngdodpg dqidrg dsidpdtgidpdugidkdvdwdxdyidzd{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 ddddd
d
d
ddd
d d
d
ddd
dddd
d
ddd ddid	d d dd d ddt          d          S )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\   re   rb   rg   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    J/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/mercado.pyr   zmercado.describe   s   gt 4 4 = = ? ?%``` %` 	`
 %` %` 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 DJ 'qyB
 yB
 y y y	    c                    |                      |          }g }|                     | j        di           }t          dt	          |                    D ]}||         }|}d}|                     |          }	|                     |          }
|
|	z   }|                    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d
|d
           |S )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
        r   r   BRLr   symbol/basequotesettleN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  sW    &&v.., t|XrBBq#h--(( 7	 7	AA;DFG**622D++G4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7!..v66   $#! !
  $//fEE# 
  $0088# 
  $#  $  _0 0 0 0 0 0 0b r   Nr   r   c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||d                   S )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
        r   r   r   )load_marketsmarketpublicGetCoinOrderbookextendparse_order_book)r   r   r   r   r  requestr   s          r   fetch_order_bookzmercado.fetch_order_bookh  su     	V$$F6N
 ..t{{7F/K/KLL$$Xvh/?@@@r   tickerr  c                    |                      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|          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_tickerx  s    !!$//''77	// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FF33!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **6599)!
 !
 !
* +  	r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |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   r   r  )r  r  publicGetCoinTickerr  r   r%  )r   r   r   r  r  r   r  s          r   fetch_tickerzmercado.fetch_ticker  s     	V$$F6N
 ++DKK,H,HII8R88   000r   tradec                    |                      |dd          }|                     d |          }|                     |dd          }d }|                     |d          }|                     |d          }|                     |dd          }|                     |d	          }	d }
|	|	d d
}
|                     ||||                     |          |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   r3  r   r   feeCostr5  s              r   parse_tradezmercado.parse_trade  s   ))%9MNN	!!$//un==v..  00##E8Z@@""5*55  C "Y//X&  
  
   	r   sincec                 t   |                                   |                     |          }d}d|d         i}| |dz  }|                     |dz            |d<   |                     |d          }||d	z  } t	          | |          |                     ||                    }	|                     |	|||          S )
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>`
        publicGetCoinTradesr   r   NFromr   fromtoTo)r  r  parse_to_intsafe_integergetattrr  parse_trades)
r   r   r<  r   r   r  methodr  rA  r   s
             r   fetch_tradeszmercado.fetch_trades  s     	V$$&F6N
 fF"//==GFOvt,,>dNF(74((Wf)E)EFF  65%@@@r   c                    |                      |di           }|                      |di           }d|i}t          |                                          }t          dt	          |                    D ]}||         }|                     |          }||v rb|                      ||i           }	|                                 }
|                     |	d          |
d<   |                     |	d          |
d<   |
||<   |                     |          S )Nresponse_databalancer   r   	availablefreetotal)	r   listkeysr   r   r   accountr"  safe_balance)r   r   databalancesr   currencyIdsr   
currencyIdcoderK  rQ  s              r   parse_balancezmercado.parse_balance  s   x"==??4B77)8==??++q#k**++ 	' 	'A$QJ**:66DX%%//(JCC,,.."&"2"27K"H"H#'#3#3GW#E#E &t  (((r   c                 ~    |                                   |                     |          }|                     |          S )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>`
        )r  privatePostGetAccountInforX  )r   r   r   s      r   fetch_balancezmercado.fetch_balance  s=     	11&99!!(+++r   r   r3  r   r   c                 `   |                                   |                     |          }d|d         i}|                     |          dz   }	|dk    rDd|	z   }	|                     |d         |          |d<   |                     |d         |          |d<   nd	|	z   }	|d
k    r|t          | j        dz             |                     |          }
|                     |          }|                     t          j
        |
|                    }|                     |d         |          |d<   n|                     |d         |          |d<    t          | |	          |                     ||                    }|                     |t          |d         d         d                   d|          S )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>`
        	coin_pairr   r   r   privatePostPlacer   limit_pricer.  privatePostPlaceMarketr  Na    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   rJ  r2  order_id)r   r   )r  r  
capitalizeprice_to_precisionamount_to_precisionr   r   number_to_stringparse_to_numericr   
string_mulrE  r  
safe_orderstr)r   r   r   r3  r   r   r   r  r  rG  amountStringpriceStringr   r   s                 r   create_orderzmercado.create_order  s    	V$$
 &&07??'&0F%)%<%<VH=Mu%U%UGM""&":":6(;KV"T"TGJ-6Fu}}=&tw  2t  (t  u  u  u#44V<<"33E::,,W-?k-Z-Z[["&"9"9&:JD"Q"Q&*&>&>vh?OQW&X&X
#(74((Wf)E)EFFh/8DEE 
  
   	r   r   c                 v   |t          | j        dz             |                                  |                     |          }|d         |d}|                     |                     ||                    }|                     |di           }|                     |di           }|                     ||          S )aB  
        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]  ra  rJ  r2  )	r   r   r  r  privatePostCancelOrderr  r   	safe_dictparse_order	r   r   r   r   r  r  r   responseDatar2  s	            r   r   zmercado.cancel_order5  s     >#DG.Y$YZZZV$$
 
 ..t{{7F/K/KLL0 x"EE|Wb99v...r   statusc                 <    dddd}|                      |||          S )Nr  canceledclosed)234)r"  )r   rt  statusess      r   parse_order_statuszmercado.parse_order_statusa  s1    
 

 &&999r   r2  c                 j   |                      |d          }|                      |d          }d }d|v r
|dk    rdnd}|                     |                      |d                    }|                      |d          }|                     ||          }|                     |d          }|                      |d	          |d
         d}	|                      |d          }
|                      |d          }|                      |d          }|                      |d          }|                     |d          }|                     |dg           }|                     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$|          S )%Nra  
order_type1r  r  rt  r]  created_timestampr5  r   r0  r_  executed_price_avgr.  executed_quantityupdated_timestamp
operationsr   r   clientOrderIdr  r  lastTradeTimestampr   r   r   r   postOnlyr3  r   r   r   r  r   filled)	remainingrt  r5  trades)r"  r|  r7  r!  r   rh  r$  )r   r2  r  r   r~  r3  rt  marketIdr  r5  r   r  r   r  r  	rawTradess                   r   rq  zmercado.parse_orderi  su   4 eZ00%%e\::
5  '3..55VD(()9)9%)J)JKK##E;77!!(F33''/BCC	$$UE22w
 
   66""5*>??!!%44!!%)<==!008KLLOOE<<<	  
E 
" 
 T 
 	 

 Y// 
 !"4 
 fX& 
 G 
 4 
  
 D 
 U 
 D 
 D 
 w 
  f! 
" f# 
$ + 
  
  
, -  	r   c                    |t          | j        dz             |                                  |                     |          }|d         t	          |          d}|                     |                     ||                    }|                     |di           }|                     |d          }| 	                    ||          S )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   rn  rJ  r2  )
r   r   r  r  intprivatePostGetOrderr  r   rp  rq  rr  s	            r   fetch_orderzmercado.fetch_order  s     >#DG.X$XYYYV$$B
 
 ++DKK,H,HIIx"EE|W55v...r   rW  addresstagc                    |                      ||          \  }}|                     |           |                                  |                     |          }|d         t	          |d          |d}|dk    r!d|v }|st          | j        dz   |z             nR|dk    rLd|v }	|	st          | j        d	z   |z             |d
k    r&|d|vrt          | j        dz   |z             n||d<   |                     |                     ||                    }
| 	                    |
di           }| 
                    |d          }|                     ||          S )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>`
        r   z.10f)r   r.  r  r   account_refz7 withdraw() requires account_ref parameter to withdraw r   tx_feez2 withdraw() requires tx_fee parameter to withdraw r   Ndestination_tagzM withdraw() requires a tag argument or destination_tag parameter to withdraw rJ  
withdrawal)handle_withdraw_tag_and_paramscheck_addressr  r1  formatr   r   privatePostWithdrawCoinr  r   rp  parse_transaction)r   rW  r   r  r  r   r1  r  r  r  r   rs  r  s                r   r   zmercado.withdraw  s    99#vFFV7###==&&TNvv..
 

 5==(F2K t'2k(knr(rssstU]]&(F o'2f(fim(mnnnu}};-77/  ;J  1J  MQ  1Q  R  R  R 8 25G-.//GV0L0LMM( x"EE^^L,??
%%j(;;;r   transactionr1  c                     |                      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S )Nr   txidr  r  networkaddressFromr  	addressTor   r   r1  rW  rt  updatedtagFromr  tagTocomment)internalr5  r   )safe_currencyr"  )r   r  r1  s      r   r  zmercado.parse_transaction  s    %%dH55
$"";55
D
 
 	

 t
 4
 t
 
 d
 D
 (
 d
 t
 t
 4
  T!
" t#
$ )
 
 
 	
r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr                  )rD  r   )r   ohlcvr  s      r   parse_ohlcvzmercado.parse_ohlcv#  s~    eQ''UA&&UA&&UA&&UA&&UA&&
 	
r   r   	timeframec           	         |                                   |                     |          }|                     | j        ||          |d         dz   |d         z   d}|d}|Q|                     |dz            |d<   |                     |d         ||                     |          z            |d	<   n;|                                 |d	<   |d	         ||                     |          z  z
  |d<   |                     | 	                    ||                    }| 
                    |d
ddddd          }	|                     |	||||          S )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
        r   -r   )
resolutionr   Nd   r   r@  rA  tohlcv)r  r  r"  r   rC  sumparse_timeframesecondsv4PublicNetGetCandlesr  convert_trading_view_to_ohlcvparse_ohlcvs)
r   r   r  r<  r   r   r  r  r   r   s
             r   fetch_ohlcvzmercado.fetch_ohlcv-  sQ    	V$$**4?IyQQVns*VG_<
 
 =E"//==GFO HHWV_ed>R>RS\>]>]6]^^GDMM LLNNGDM%dmut7K7KI7V7V/VWGFO--dkk'6.J.JKK44XsCcSVX[\\  &)UEJJJr   c                 x   |t          | j        dz             |                                  |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          S )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   rJ  orders	r   r   r  r  privatePostListOrdersr  r   	safe_listparse_orders
r   r   r<  r   r   r  r  r   rs  r  s
             r   fetch_orderszmercado.fetch_ordersI  s     >#DG.Y$YZZZV$$
 --dkk'6.J.JKKx"EEh;;  >>>r   c                 z   |t          | j        dz             |                                  |                     |          }|d         dd}|                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          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 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_listrJ  r  r  r  s
             r   fetch_open_orderszmercado.fetch_open_orders^  s     >#DG.]$]^^^V$$ 
 
 --dkk'6.J.JKKx"EEh;;  >>>r   c                    |t          | j        dz             |                                  |                     |          }|d         dd}|                     |                     ||                    }|                     |di           }|                     |dg           }	|                     |	|||          }
|                     |
          }| 	                    ||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 argumentr   T)r]  	has_fillsrJ  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   rs  	ordersRawr  r  s               r   fetch_my_tradeszmercado.fetch_my_tradest  s     >#DG.[$[\\\V$$
 
 --dkk'6.J.JKKx"EEOOL(B??	""9feUCC&&v..009I5RWXXXr   c                     g }t          dt          |                    D ]Z}|                     ||         dg           }t          dt          |                    D ]}|                    ||                    [|S )Nr   r  )r   r   r   r   )r   r  r   r   r  ys         r   r  zmercado.orders_to_trades  s    q#f++&& 	) 	)A__VAY"==F1c&kk** ) )fQi(((()r   r   GETc                    | j         d         |         dz   }|                     ||                     |                    }|dk    s|dk    s|dk    r7||                     ||          z  }|r|d|                     |          z   z  }n|                                  || j        dz   z  }|                                 }	|                     |                     ||	d|                    }d| j        z   dz   dz   |z   }
d	| j	        | 
                    |                     |
          |                     | j                  t          j                  d
}||||dS )Nr   r   r   r   r   ?)tapi_method
tapi_noncez/tapi/z!application/x-www-form-urlencoded)zContent-TypezTAPI-IDzTAPI-MAC)urlrG  bodyheaders)r   omitextract_paramsimplode_params	urlencodecheck_required_credentialsr   noncer  apiKeyhmacencodesecrethashlibsha512)r   pathr   rG  r   r  r  r  queryr  auths              r   signzmercado.sign  sr   is#c)		&$"5"5d";";<<8OO
!2!2}8L8L4&&tV444C 3sT^^E2222++---4<#%%CJJLLE>>$++##/ / # #  D dl*S036=D C; IIdkk$&7&7T[9Q9QSZSabb G
 fdwOOOr   httpCodereasonr  rG  r  r  c
                     |d S |                      |d          }
|
-t          | j        dz   |                     |          z             d S )Nerror_message )r   r   r   json)r   r  r  r  rG  r  r  r   requestHeadersrequestBodyerrorMessages              r   handle_errorszmercado.handle_errors  sR    4 xAA##		(0C0C CDDDtr   )N)0__name__
__module____qualname__r   r   r   r	   r   ri  r   r   r  dictr   r%  r(  r   r;  rH  r   rX  r[  r   r   floatr
   rl  r   r   r|  r   rq  r  r   r   r   r  rO  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r   r   r      s       z# z z z z z zx $& V V$v, V V V Vp :>b A As A3 AY A A A A % %4 % %6 % % % %N 02 1 13 1f 1 1 1 1<  v     > 6:UW A A3 As A# A\`af\g A A A A0) ) ) ) )  $& , ,( , , , , gksu % %3 %i %y %RW %`c % % % %N 37r */ */s */C */ */ */ */X: : : : :D D Dv D D D D DL 26b / /c /3 / / / /* KOWY 7< 7<S 7<% 7<# 7<C 7<^i 7< 7< 7< 7<r$
 $
T $
X $
Q\ $
 $
 $
 $
L
 
 
4 
 
 
 
 9>D_cln K K# K# Kc KY\ Kswx|s} K K K K8 *.Dt\^ ? ?3 ?c ? ?cghmcn ? ? ? ?* /3TXac ? ? ?3 ?c ?hlmrhs ? ? ? ?, -1tRV_a Y Yc Y YC Y Y Y Y0   &eBSW P P P P.c 3 S # X\ dg        r   r   )ccxt.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     s   ( ' ' ' ' ' - - - - - -  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O  O       * * * * * * . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %d d d d dh d d d d dr   