
    !:h                         d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlm Z  d dl!m"Z" d dl#m$Z$  G d dee      Z%y)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)InsufficientFunds)InvalidOrder)OrderNotFound)RateLimitExceeded)	TICK_SIZE)Precisec                       e Zd Zdef fdZi f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fd	Zi fdedefd
Zdi fdedefdZd7dededefdZdddi fdedededee   fdZdefdZd7dededefdZdi fdedededefdZdddi fde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!i fdede"fdZ#dddi fdedededee$   fd Z%dddi fdedededee$   fd!Z&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*d'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fd,Z/d- Z0d.d/i ddfd0Z1de2d1ed2ed3ed4ed5efd6Z3 xZ4S )8coinmatereturnc                 R   | j                  t        t        |          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	d/d	d0d	d1d	d2d	d3dd4dd5dd6dd7d	d8d9d:d	d	d	d	d	dd;d<d=d>id?d@dAdBgdCdDddddEdFg dGidHg dIidJdKdd| j	                  dL      | j	                  dM      | j	                  dN      | j	                  dL      g| j	                  dO      | j	                  dP      g| j	                  dQ      | j	                  dR      g| j	                  dS      | j	                  dT      g| j	                  dU      | j	                  dV      g| j	                  dW      | j	                  dX      g| j	                  dY      | j	                  dZ      g| j	                  d[      | j	                  d\      gg| j	                  dN      | j	                  dM      g| j	                  dO      | j	                  d]      g| j	                  dQ      | j	                  dZ      g| j	                  dS      | j	                  d^      g| j	                  dU      | j	                  d_      g| j	                  dW      | j	                  d`      g| j	                  dY      | j	                  da      g| j	                  d[      | j	                  db      ggdcddideddfdgdhdidjdkdldmdndo	dpid	d	dd d	d	d	d dd	dd	dqd	dd	d	d	d	ddrd d	dsdtdtd	dud	d	d	d	dvd	d d	d	ddwd	dxd d d	d	ddyd d dz	d d d{d d d{d|d}t
        it        t        t        t        t        t        d~dt        d      S )Nr!   CoinMate)GBCZEUiX  CORSTspotmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateOrdercreateReduceOnlyOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTradesfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsemulatedreduceMargin)setLeveragesetMarginModesetPositionModetransferwithdrawzdhttps://user-images.githubusercontent.com/51840849/87460806-1c9f3f00-c616-11ea-8c46-a77018a8f3f4.jpgrestzhttps://coinmate.io/apizhttps://coinmate.iozhttps://coinmate.io/feeszhttps://coinmate.docs.apiary.iozhttps://coinmate.io/developerszHhttps://coinmate.io?referral=YTFkM1RsOWFObVpmY1ZjMGREQmpTRnBsWjJJNVp3PT0)logoapiwwwfeesdocreferral)apiKeysecretuidget)	orderBookticker	tickerAllproductstransactionstradingPairspost)4balancesbitcoinCashWithdrawalbitcoinCashDepositAddressesbitcoinDepositAddressesbitcoinWithdrawalbitcoinWithdrawalFees
buyInstantbuyLimitr/   cancelOrderWithInfocreateVoucherdashDepositAddressesdashWithdrawalethereumWithdrawalethereumDepositAddresseslitecoinWithdrawallitecoinDepositAddresses
openOrdersorderorderHistory	orderById
pusherAuthredeemVoucherreplaceByBuyLimitreplaceByBuyInstantreplaceBySellLimitreplaceBySellInstantrippleDepositAddressesrippleWithdrawalsellInstant	sellLimittransactionHistory
traderFeestradeHistoryr_   transferHistoryunconfirmedBitcoinDepositsunconfirmedBitcoinCashDepositsunconfirmedDashDepositsunconfirmedEthereumDepositsunconfirmedLitecoinDepositsunconfirmedRippleDepositscancelAllOpenOrderswithdrawVirtualCurrencyvirtualCurrencyDepositAddresses"unconfirmedVirtualCurrencyDepositsadaWithdrawaladaDepositAddressesunconfirmedAdaDepositssolWithdrawalsolDepositAddressesunconfirmedSolDeposits)publicprivatetradingz0.006z0.004010000z0.003100000z0.0023250000z0.0021500000z0.00181000000z0.00153000000z0.001215000000z0.001z0.002z0.0009z0.0005z0.0003z0.0002z-0.0004)takermaker)	tierBased
percentager   r   tiersr`   privatePostBitcoinWithdrawalprivatePostLitecoinWithdrawal privatePostBitcoinCashWithdrawalprivatePostEthereumWithdrawalprivatePostRippleWithdrawalprivatePostDashWithdrawalprivatePostDaiWithdrawalprivatePostAdaWithdrawalprivatePostSolWithdrawal)	BTCLTCBCHETHXRPDASHDAIADASOL)fillResponsefromRequestmethods)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg  i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   d   )r   r   r   r   r   r   r   )	sandboxr2   createOrdersrF   rI   rH   rK   fetchClosedOrders
fetchOHLCV)linearinverse)r)   r+   r,   zNo order with given ID)z$Not enough account balance availablezIncorrect order IDzMinimum Order Size zmax allowed precisionzTOO MANY REQUESTSzAccess denied.)exactbroad)idname	countries	rateLimithasurlsrequiredCredentialsrc   re   optionsfeatures
exceptionsprecisionMode)deep_extendsuperr!   describeparse_numberr   r   r   r   r   r   )self	__class__s    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coinmate.pyr   zcoinmate.describe   s   h > @+999 %9 	9
 %9 %9 U9 t9 $U9  9 t9 (9 9 +E9 )%9  '!9" (#9$ +D%9& &u'9( #E)9* *5+9, $U-9. "5/90 *5192 +E394  596 %e798 "599: ;9< !%=9>  ?9@ +EA9B "4C9D dE9F !$G9H tI9J  K9L 'M9N $UO9P !%Q9R *5S9T (U9V %eW9X )%Y9Z t[9\ ]9^ t_9` "4a9b #Ec9d $Ze9f g9h  %!&#(! q9v 5 -254 g $  	  57CJ !%"&!..w7!..w7 "..s3T5F5Fw5OP!..w79J9J79ST!..x8$:K:KH:UV!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mg<VW	" "..s3T5F5Fw5OP!..w79J9J79ST!..x8$:K:KH:UV!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mi<XY	"> /3=>A>< ;999
 $  %&+(,,0,1).+06:#'#("&#(	( #($($)+027/4#')$, %)&+!%$*%+*/& ',#($)*/	# ',!%#($)*.( ',!$$(%)#($)*.$ *."&o8t ##
 ##}BJ -m =N*6+7-9):&9	 'gTC
 T T	    c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]9  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }|
dz   |z   }|j                  i d|d|d	|
d
|ddd|d|	dddddddddddddddddddddddddd| j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dddd| j                  |d      ddddddddd d|d!
       < |S )"a0  
        retrieves data on all markets for coinmate

        https://coinmate.docs.apiary.io/#reference/trading-pairs/get-trading-pairs/get

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        datar   r   firstCurrencysecondCurrency/r   symbolbasequotesettleNbaseIdquoteIdsettleIdtyper)   Tr*   Fr+   r,   r-   activecontractr   lotDecimalspriceDecimals)amountprice)minmax	minAmount)r   r  r  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)
publicGetTradingPairs
safe_valuerangelensafe_stringsafe_currency_codeappendr   parse_precisionsafe_number)r   paramsresponser   resultimarketr   r  r  r  r  r  s                r   fetch_marketszcoinmate.fetch_markets/  sS    --f5( x4q#d)$ 8	A!WF!!&&1B%%fo>F&&v/?@G**62D++G4ECZ%'FMM 0b0&0 0 	0
 $0 &0 70 D0 0 0 %0 0 %0 %0 $0  E!0" $#0$   $"&""//0D0DTEUEUV\^kEl0mn!..t/C/CDDTDTU[]lDm/no  $#!
  $//D#
  $#
  $#$  _0 08	r r   c                    | j                  |di       }d|i}t        |j                               }t        dt	        |            D ]~  }||   }| j                  |      }| j                  ||      }| j                         }	| j                  |d      |	d<   | j                  |d      |	d<   | j                  |d      |	d	<   |	||<    | j                  |      S )
Nr   r  r   	availablefreereservedusedbalancetotal)	r  listkeysr   r!  r#  accountr"  safe_balance)
r   r(  rs   r)  currencyIdsr*  
currencyIdcoder2  r6  s
             r   parse_balancezcoinmate.parse_balance  s    ??8VR8)8==?+q#k*+ 	#A$QJ**:6Dooh
;GllnG"..wDGFO"..w
CGFO#//CGG"F4L	#   ((r   c                 f    | j                          | j                  |      }| j                  |      S )ap  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://coinmate.docs.apiary.io/#reference/balance/get-balances/post

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )load_marketsprivatePostBalancesr;  )r   r'  r(  s      r   fetch_balancezcoinmate.fetch_balance  s1     	++F3!!(++r   Nr  r   c           	          | j                          | j                  |      }|d   dd}| j                  | j                  ||            }|d   }| j	                  |d      }| j                  ||d   |ddd	d
      S )aF  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://coinmate.docs.apiary.io/#reference/order-book/get-order-book/get

        :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   False)currencyPairgroupByPriceLimitr   	timestampr  bidsasksr  r  )r=  r+  publicGetOrderBookextendsafe_timestampparse_order_book)	r   r  r   r'  r+  requestr(  	orderbookrD  s	            r   fetch_order_bookzcoinmate.fetch_order_book  s     	V$"4L!(
 **4;;w+GHV$	''	;?	$$Yx0@)VU[]dfnoor   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://coinmate.docs.apiary.io/#reference/ticker/get-ticker/get

        :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>`
        rB  r   r   )r=  r+  publicGetTickerrH  	safe_dictparse_ticker)r   r  r'  r+  rK  r(  r   s          r   fetch_tickerzcoinmate.fetch_ticker  sp     	V$F4L
 ''GV(DE$ ~~h/  v..r   symbolsc                    | j                          | j                  |      }| j                  |      }| j                  |di       }t	        |j                               }i }t        dt        |            D ]C  }| j                  ||         }| j                  | j                  |||         |      }	|	||d   <   E | j                  |d|      S )a   
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://coinmate.docs.apiary.io/#reference/ticker/get-ticker-all/get

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   r   r  )r=  market_symbolspublicGetTickerAllr  r4  r5  r   r!  r+  rQ  filter_by_array_tickers)
r   rS  r'  r(  r   r5  r)  r*  r+  rm   s
             r   fetch_tickerszcoinmate.fetch_tickers  s     	%%g.**62( x4DIIK q#d)$ 	.A[[a)F&&ttT!W'EvNF'-F6(#$	. ++FHgFFr   rm   r+  c                    | j                  |d      }| j                  |d      }| j                  i d|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 )NrD  lastr  datetimehighlowbid	bidVolumeaskvwap	askVolumeopenclosepreviousClosechanger   averager  )
baseVolumequoteVolumer  )rI  r&  safe_tickeriso8601)r   rm   r+  rD  rZ  s        r   rQ  zcoinmate.parse_ticker  sl    ''<	/ !
fX&!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 !
 4##FE2!
 D!
 !
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **68<)!
* + 	r   r:  sincec                     | j                          ddi}|||d<   |||d<   || j                  |      }|d   |d<   | j                  | j                  ||            }|d   }| j	                  |d||      S )a}  
        fetch history of deposits and withdrawals

        https://coinmate.docs.apiary.io/#reference/transfers/get-transfer-history/post

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   r   NtimestampFromr   currencyr   )r=  ro  privatePostTransferHistoryrH  parse_transactions)	r   r:  rl  r   r'  rK  ro  r(  itemss	            r   fetch_deposits_withdrawalsz#coinmate.fetch_deposits_withdrawals/  s     	T
 $GG',GO$}}T*H"*4.GJ224;;w3OP &&udE5AAr   statusc                 <    dddddddd}| j                  |||      S )Nokpendingcanceled)	COMPLETEDWAITINGSENTCREATEDOKNEWCANCELEDr"  r   rt  statusess      r   parse_transaction_statusz!coinmate.parse_transaction_statusJ  s5      "
 &&99r   transactionro  c                 J   | j                  |d      }| j                  |d      }| j                  ||      }i d|d| j                  |dd      d| j                  |d      d| j	                  |d      d	|d
| j                  |d      d| j                  |d      d| j                  | j                  |d            d|d| j                  |      d| j                  |d      dd dd d| j                  |d      dd dd dd d d | j                  |d      |d ddS )NrD  amountCurrencyr  r   transactionIdtxidr
  transferTypero  network
walletTyper  rt  transferStatusr[  addressdestinationaddressFrom	addressTotagdestinationTagtagFromtagToupdatedfee)r  ro  rate)commentinternalr  )safe_integerr"  r#  safe_string_2safe_string_lowerr&  r  rk  )r   r  ro  rD  r9  r:  s         r   parse_transactionzcoinmate.parse_transactionV  s   R %%k;?	%%k3CD
&&z8<
K
$$$[/4H
 D$$[&9
 D**;G	

 
 t''\B
 d&&{H=
 d33D4D4D[Rb4cd
 
 Y/
 t'']C
 4
 
 4##K1AB
 t
  T!
" t#
$ ((e< )
 	
r   r  r  c                    | j                  ||      \  }}| j                  |       | j                          | j                  |      }| j	                  | j
                  di       }| j	                  |di       }| j                  ||      }	|	Ct        |j                               }
t        | j                  dz   dj                  |
      z         | j                  ||      |d}|||d<    t        | |	      | j                  ||            }| j	                  |d      }| j                  ||      }| j!                  |dd	      }|r||d
<   ||d<   ||d<   ||d<   d|d<   d|d<   |S )a  
        make a withdrawal

        https://coinmate.docs.apiary.io/#reference/bitcoin-withdrawal-and-deposit/withdraw-bitcoins/post
        https://coinmate.docs.apiary.io/#reference/litecoin-withdrawal-and-deposit/withdraw-litecoins/post
        https://coinmate.docs.apiary.io/#reference/ethereum-withdrawal-and-deposit/withdraw-ethereum/post
        https://coinmate.docs.apiary.io/#reference/ripple-withdrawal-and-deposit/withdraw-ripple/post
        https://coinmate.docs.apiary.io/#reference/cardano-withdrawal-and-deposit/withdraw-cardano/post
        https://coinmate.docs.apiary.io/#reference/solana-withdrawal-and-deposit/withdraw-solana/post

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r`   r   z> withdraw() only allows withdrawing the following currencies: z, )r  r  r  r   fillResponseFromRequestTr  ro  r  r  
withdrawalr
  rw  rt  )handle_withdraw_tag_and_paramscheck_addressr=  ro  r  r   r"  r4  r5  r   r   joincurrency_to_precisiongetattrrH  r  	safe_bool)r   r:  r  r  r  r'  ro  withdrawOptionsr   methodallowedCurrenciesrK  r(  r   r  r  s                   r   r`   zcoinmate.withdraw  s   $ 99#vFV7#==&//$,,
BG///9bA!!'40> $W\\^ 4*j jmqmvmv  xI  nJ  !J  K  K00v>
 ?(+G$%(74(Wf)EF x0,,T8<"&..B[]a"b"$*K!&*K
#%,K	"!$K".K$-K!r   c                    | j                          |d}d|i}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  |d||      S )a  
        fetch all trades made by the user

        https://coinmate.docs.apiary.io/#reference/trade-history/get-trade-history/post

        :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>`
        Nr   r   r   rB  rn  r   )r=  r+  privatePostTradeHistoryrH  	safe_listparse_trades)	r   r  rl  r   r'  rK  r+  r(  r   s	            r   fetch_my_tradeszcoinmate.fetch_my_trades  s     	=EU
 [[(F&,TlGN#',GO$//GV0LM~~h3  tUE::r   tradec                 "   | j                  |d      }| j                  ||d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d	      }	| j	                  |d
d      }
d }| j                  |d      }|||d   d}| j                  |d      }|dk(  rdnd}| j                  |	||
| j                  |
      |d   ||||||d |d|      S )NrB  _r  r  r
  	tradeType	orderTypeorderIdr  rD  createdTimestampr  r  )r  ro  feeTypeMAKERr   r   r  )r   r  rD  r[  r  r
  sider   takerOrMakerr  r  r  r  )r"  safe_marketsafe_string_lower_2r  safe_integer_2
safe_traderk  )r   r  r+  marketIdpriceStringamountStringr  r
  r  r   rD  r  feeCostStringr  s                 r   parse_tradezcoinmate.parse_trade  sM   8 ##E>:!!(FC8&&ug6''x8''v{C%%e[9""5)4e_5''{<NO	((6$%"7OC ''y9#/7#:w"Y/X&( " 
  	r   c                     | j                          | j                  |      }|d   dd}| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a0  
        get the list of most recent trades for a particular symbol

        https://coinmate.docs.apiary.io/#reference/transactions/transactions/get

        :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>`
        r   
   )rB  minutesIntoHistoryr   )r=  r+  publicGetTransactionsrH  r  r  )	r   r  rl  r   r'  r+  rK  r(  r   s	            r   fetch_tradeszcoinmate.fetch_trades.  sw     	V$"4L"$
 --dkk'6.JK" ~~h3  vue<<r   c                    | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |d      }| j                  |d      }| j                  t        j                  |d            }	| j                  t        j                  |d            }
||d   |	|
ddd	S )
ag  
        fetch the trading fees for a market

        https://coinmate.docs.apiary.io/#reference/trader-fees/get-trading-fees/post

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rB  r   r   r   r   100r  T)r  r  r   r   r   r   )	r=  r+  privatePostTraderFeesrH  r  r"  r   r   
string_div)r   r  r'  r+  rK  r(  r   makerStringtakerStringr   r   s              r   fetch_trading_feezcoinmate.fetch_trading_feeT  s     	V$F4L
 --dkk'6.JK x4&&tW5&&tW5!!'"4"4[%"HI!!'"4"4[%"HIX&
 	
r   c                 |    | j                  | j                  i |            }ddi}| j                  |d   d|||      S )a  
        fetch all unfilled currently open orders

        https://coinmate.docs.apiary.io/#reference/order/get-open-orders/post

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rt  rc  r   N)privatePostOpenOrdersrH  parse_orders)r   r  rl  r   r'  r(  	extensions          r   fetch_open_orderszcoinmate.fetch_open_ordersy  sG     --dkk"f.EF#V,	  &!14yQQr   c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   | j	                  | j                  ||            }| j                  |d   |||      S )a;  
        fetches information on multiple orders made by the user

        https://coinmate.docs.apiary.io/#reference/order/order-history/post

        :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>`
        z) fetchOrders() requires a symbol argumentrB  r   r   r   )r   r   r=  r+  privatePostOrderHistoryrH  r  )r   r  rl  r   r'  r+  rK  r(  s           r   fetch_orderszcoinmate.fetch_orders  s     >#DGG.Y$YZZV$F4L
 $GG//GV0LM  &!165%HHr   c                 6    ddddd}| j                  |||      S )Nclosedrx  rc  )FILLED	CANCELLEDPARTIALLY_FILLEDOPENr  r  s      r   parse_order_statuszcoinmate.parse_order_status  s,    # &	
 &&99r   r
  c                 2    ddd}| j                  |||      S )Nr   r+  )LIMITMARKETr  )r   r
  typess      r   parse_order_typezcoinmate.parse_order_type  s&    
 tT22r   r   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j	                  | j                  |d            }	| j                  | j                  |d	            }
| j                  |d
      }| j                  |d      }| j                  ||d      }| j                  |d      }| j                  i d|d|d|d| j                  |      dd d|d|
dd dd d|d|d| j                  |d      d|dd d|dd d||	d |d d|      S )Nr   rD  r
  r  originalAmountremainingAmountr  rt  orderTradeTypeavgPricerB  r  clientOrderIdr[  lastTradeTimestampr  r   postOnlyr  r   	stopPricer  rg  filled	remaining)rt  tradesr  r  )
r"  r  r  r  r  r  safe_symbol
safe_orderrk  r&  )r   r   r+  r   rD  r  r  r  remainingStringrt  r
  averageStringr  r  r  s                  r   parse_orderzcoinmate.parse_order  s   d eT*%%e[9	%%eV4&&ug6''/?@,,U4ExP(()9)9%)JK$$T%5%5e=M%NO((
;##E>:!!(FC8((@  
" 
] 
  
 Y/	 

 !$ 
 f 
 D 
 4 
  
 D 
 [ 
 D,,UK@ 
 l 
 D 
 } 
  d! 
" # 
$ + 
, - 	r   r  r  c                    | j                          d| j                  |      z   }| j                  |      }d|d   i}	|dk(  r6|dk(  r| j                  ||      |	d<   n| j                  ||      |	d<   |dz  }n>| j                  ||      |	d<   | j	                  ||      |	d	<   || j                  |      z  } t        | |      | j                  |	|            }
| j                  |
d
      }| j                  |
|d|      S )a  
        create a trade order

        https://coinmate.docs.apiary.io/#reference/order/buy-limit-order/post
        https://coinmate.docs.apiary.io/#reference/order/sell-limit-order/post
        https://coinmate.docs.apiary.io/#reference/order/buy-instant-order/post
        https://coinmate.docs.apiary.io/#reference/order/sell-instant-order/post

        :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>`
        privatePostrB  r   r+  buyr3  r  Instantr  r   )r  r   )	r=  
capitalizer+  amount_to_precisionprice_to_precisionr  rH  r"  r  )r   r  r
  r  r  r  r'  r  r+  rK  r(  r   s               r   create_orderzcoinmate.create_order  s   " 	!66V$F4L
 8u}#'#;#;FF#K $($<$<VV$L!iF $ 8 8 HGH#66vuEGGdood++F(74(Wf)EFh/ 
  	r   r   c                     | j                          d|i}d}|r| j                  |      }| j                  | j                  ||            }| j	                  |d      }| j                  ||      S )a  
        fetches information on an order made by the user

        https://coinmate.docs.apiary.io/#reference/order/get-order-by-orderid/post
        https://coinmate.docs.apiary.io/#reference/order/get-order-by-clientorderid/post

        :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>`
        r  Nr   )r=  r+  privatePostOrderByIdrH  rP  r  )r   r   r  r'  rK  r+  r(  r   s           r   fetch_orderzcoinmate.fetch_order0  sr     	r
 [[(F,,T[[&-IJ~~h/f--r   c                     d|i}| j                  | j                  ||            }| j                  |d      }| j                  |      S )a  
        cancels an open order

        https://coinmate.docs.apiary.io/#reference/order/cancel-order/post

        :param str id: order id
        :param str symbol: not used by coinmate cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r   )privatePostCancelOrderWithInforH  rP  r  )r   r   r  r'  rK  r(  r   s          r   cancel_orderzcoinmate.cancel_orderG  sK     #B66t{{7F7ST ~~h/%%r   c                 "    | j                         S N)milliseconds)r   s    r   noncezcoinmate.nonceb  s      ""r   r   GETc           	      2   | j                   d   d   dz   |z   }|dk(  r|r|d| j                  |      z   z  }n| j                          t        | j	                               }|| j
                  z   | j                  z   }	| j                  | j                  |	      | j                  | j                        t        j                        }
| j                  | j                  | j
                  || j                  |
j                         d|            }ddi}||||d	S )
Nrc   ra   r  r   ?)clientIdr  	publicKey	signaturezContent-Typez!application/x-www-form-urlencoded)urlr  bodyheaders)r   	urlencodecheck_required_credentialsstrr  rj   rh   hmacencoderi   hashlibsha256rH  upper)r   pathrc   r  r'  r  r  r  r  authr  s              r   signzcoinmate.signe  s    iiv&,t3(?sT^^F333++-

%E488#dkk1D		$++d"3T[[5Mw~~^I>>$++ HH![[&__.	/
 # D  CG fdwOOr   reasonr  r  r  r  c
                     |y | j                  |d      }
|
]| j                  dz   |z   }| j                  | j                  d   |
|       | j	                  | j                  d   |
|       t        |      y )NerrorMessage r   r   )r"  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r:  r  r  r  r  r  r(  requestHeadersrequestBodyr  feedbacks               r   handle_errorszcoinmate.handle_errorsz  s}    
 ''.A#ww}t+H001I<Yab001I<Yab))r   r  )5__name__
__module____qualname__r   r   r   r	   r,  r   r;  r?  r  r   r   rM  r   rR  r   r   rX  dictrQ  r   r   rs  r  r   r  floatr`   r  r   r  r  r   r  r   r  r  r  r  r  r   r   r
   r  r  r  r  r  intr#  __classcell__)r   s   @r   r!   r!      sB   U# Un $& X$v, Xt) ) $& ,( , :>b ps p3 pY p, 02 "/3 "/f "/H 04B 'GW 'G7 'GR%4 % %6 %N 6:[_hj Bs B# BUX Bost  pA B6
:s 
:E
T E
X E
Q\ E
N DHPR 6S 6% 6# 6Wb 6p -1tRV_a ;c ; ;C ;6< <v < <| 6:UW $=3 $=s $=# $=\`af\g $=L 57 #
 #
;N #
J /3TXac R R3 Rc Rhlmrhs R  *.Dt\^ I3 Ic I Icghmcn I2: :3S 3T Tv T Tl gksu &3 &i &y &RW &`c &P 26b .c .3 .. 37r &s &C &6# &eBSW P*# s  c TX `c r   r!   )&ccxt.base.exchanger   ccxt.abstract.coinmater   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r!    r   r   <module>r3     s\    ( .  v  v  v  v  v  * 0 . . ) * . 4 %qx qr   