
    i޲                        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 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$dS )    )Exchange)ImplicitAPIN)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 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d,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 Zd,dedefdZdi fde
defdZdddi fdededefdZd,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 Z%d Z&d,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' Z.d(d)i ddfd*Z/d+ Z0 xZ1S )-coinmatec                    |                      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	d5d6d7d	d8d	d9d	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|                     dL          |                     dM          |                     dN          |                     dO          g|                     dP          |                     dQ          g|                     dR          |                     dS          g|                     dT          |                     dU          g|                     dV          |                     dW          g|                     dX          |                     dY          g|                     dZ          |                     d[          g|                     d\          |                     d]          gg|                     dN          |                     d^          g|                     dP          |                     d_          g|                     dR          |                     d[          g|                     dT          |                     d`          g|                     dV          |                     d]          g|                     dX          |                     da          g|                     dZ          |                     db          g|                     d\          |                     dN          ggdcddideddfdgdhdidjdkdldmdndo	dpidqt
          it          t          t          t          t          t          drdst          dt          S )uNr    CoinMate)GBCZEU  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fetchPositionModefetchPositions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.0012z0.00250z0.003510000z0.0023100000z0.0021250000z0.0020500000z0.00151000000z0.00133000000z0.001015000000z0.0005z0.003z0.0011z0.0008z0.0003z0.0002)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methodsz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requiredCredentialsr_   ra   options
exceptionsprecisionMode)deep_extendsuperr    describeparse_numberr   r   r   r   r   r   )self	__class__s    S/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/coinmate.pyr   zcoinmate.describe   s   h 5 5 > > @ @+++666 %6 	6
 %6 %6 U6 t6 $U6  6 t6 (6 6 +E6 )%6  '!6" (#6 6$ +D%6& &u'6( #E)6* *5+6, $U-6. "5/60 *5162 +E364  566 %e768 "596: ;6< !%=6>  ?6@ +EA6B "4C6D dE6 6 6F !$G6H tI6J  K6L $UM6N !%O6P %eQ6R )%S6T tU6V W6X tY6Z "4[6\ #E]6^ $Z_6` a6b uc6d  e6f "5g6 6h " k6 6 6p 5 -254 g  $ $    	  5 5 57C CJ !%"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX	" "..s33T5F5Fw5O5OP!..w779J9J89T9TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mc<R<RS	"  > /3=>A>< ;999
  
  $ -m =N*6+7-9):&9 	  '[NC
 NC
 N N N	    returnc                    |                      |          }|                     |dg           }g }t          dt          |                    D ]p}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|
dz   |z   }|                    i d|d|d	|
d
|ddd|d|	dddddddddddddddddddddddddd|                     |                     |                     |d                              |                     |                     |                     |d                              dddd| 	                    |d          ddddddddd d|d!
           r|S )"a4  
        retrieves data on all markets for coinmate
        :see: 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contractlinearlotDecimalspriceDecimals)amountprice)minmax	minAmount)leverager   r   cost)
inverse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   s    --f55( x44q#d))$$ 8	 8	A!WF!!&&11B%%fo>>F&&v/?@@G**622D++G4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\^kElEl0m0mnn!..t/C/CDDTDTU[]lDmDm/n/noo   $#! !
  $//DD# 
  $# 
  $#  $  _0 0 0 0 0 0 0b r   c                    |                      |di           }d|i}t          |                                          }t          dt	          |                    D ]}||         }|                     |          }|                      ||          }|                                 }	|                     |d          |	d<   |                     |d          |	d<   |                     |d          |	d	<   |	||<   |                     |          S )
Nr   r   r   	availablefreereservedusedbalancetotal)	r   listkeysr   r   r  accountr  safe_balance)
r   r  ro   r  currencyIdsr	  
currencyIdcoder  r  s
             r   parse_balancezcoinmate.parse_balanceA  s    ??8VR88(#8==??++q#k**++ 	# 	#A$QJ**:66Dooh
;;GllnnG"..wDDGFO"..w
CCGFO#//CCGG"F4LL  (((r   c                 ~    |                                   |                     |          }|                     |          S )at  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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_balanceP  s=     	++F33!!(+++r   Nr   limitc           	      :   |                                   |                     |          }|d         dd}|                     |                     ||                    }|d         }|                     |d          }|                     ||d         |ddd	d
          S )aJ  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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  	orderbookr$  s	            r   fetch_order_bookzcoinmate.fetch_order_book[  s     	V$$"4L!(
 
 **4;;w+G+GHHV$	''	;??	$$Yx0@)VU[]dfnooor   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        r"  r   r   )r  r
  publicGetTickerr(  	safe_dictparse_ticker)r   r   r  r
  r+  r  r   s          r   fetch_tickerzcoinmate.fetch_tickero  s     	V$$F4L
 ''GV(D(DEE$ ~~h//  v...r   symbolsc                    |                                   |                     |          }|                     |          }|                     |di           }t	          |                                          }i }t          dt          |                    D ]X}|                     ||                   }| 	                    |                     |||                   |          }	|	||d         <   Y| 
                    |d|          S )a$  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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   r  r  r   r   r
  r1  filter_by_array_tickers)
r   r3  r  r  r   r  r  r	  r
  ri   s
             r   fetch_tickerszcoinmate.fetch_tickers  s     	%%g..**622( x44DIIKK  q#d))$$ 	. 	.A[[a))F&&ttT!W'E'EvNNF'-F6(#$$++FHgFFFr   r
  c                    |                      |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|          S )Nr$  lastr   datetimehighlowbid	bidVolumeaskvwap	askVolumeopenclosepreviousClosechanger   averager   )
baseVolumequoteVolumer   )r)  r  safe_tickeriso8601)r   ri   r
  r$  r:  s        r   r1  zcoinmate.parse_ticker  s    ''<<	// !
fX&!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 D!
 !
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **68<<)!
 !
 !
* +  	r   r  sincec                 $   |                                   ddi}|||d<   |||d<   | |                     |          }|d         |d<   |                     |                     ||                    }|d         }|                     |d||          S )a  
        fetch history of deposits and withdrawals
        :see: 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  privatePostTransferHistoryr(  parse_transactions)	r   r  rL  r  r  r+  rO  r  itemss	            r   fetch_deposits_withdrawalsz#coinmate.fetch_deposits_withdrawals  s     	T
 $GG',GO$}}T**H"*4.GJ224;;w3O3OPP &&udE5AAAr   c                 D    dddddddd}|                      |||          S )Nokpendingcanceled)	COMPLETEDWAITINGSENTCREATEDOKNEWCANCELEDr  r   statusstatusess      r   parse_transaction_statusz!coinmate.parse_transaction_status  s=      "
 
 &&999r   rO  c                    |                      |d          }|                     |d          }|                     ||          }i d|d|                     |dd          d|                     |d          d|                     |d          d	|d
|                     |d          d|                     |d          d|                     |                     |d                    d|d|                     |          d|                     |d          dd dd d|                     |d          dd dd dd d d |                     |d          |d ddS )Nr$  amountCurrencyr   r   transactionIdtxidr   transferTyperO  network
walletTyper   ra  transferStatusr;  addressdestinationaddressFrom	addressTotagdestinationTagtagFromtagToupdatedfee)r   rO  rate)commentinternalru  )safe_integerr  r  safe_string_2safe_string_lowerr  rc  rK  )r   transactionrO  r$  r  r  s         r   parse_transactionzcoinmate.parse_transaction  s   R %%k;??	%%k3CDD
&&z8<<
K
$$$[/4HH
 D$$[&99
 D**;GG	

 
 t''\BB
 d&&{H==
 d33D4D4D[Rb4c4cdd
 
 Y//
 t'']CC
 4
 
 4##K1ABB
 t
  T!
" t#
$ ((e<<  )
 
 
 	
r   r   c                 F   |                      ||          \  }}|                     |           |                                  |                     |          }|                     | j        di           }|                     |di           }|                     ||          }	|	Nt          |                                          }
t          | j
        dz   d                    |
          z             |                     ||          |d}|||d<    t          | |	          |                     ||                    }|                     |d          }|                     ||          }|                     |d	d
          }|r||d<   ||d<   ||d<   ||d<   d|d<   d|d<   |S )a%  
        make a withdrawal
        :see: https://coinmate.docs.apiary.io/#reference/bitcoin-withdrawal-and-deposit/withdraw-bitcoins/post
        :see: https://coinmate.docs.apiary.io/#reference/litecoin-withdrawal-and-deposit/withdraw-litecoins/post
        :see: https://coinmate.docs.apiary.io/#reference/ethereum-withdrawal-and-deposit/withdraw-ethereum/post
        :see: https://coinmate.docs.apiary.io/#reference/ripple-withdrawal-and-deposit/withdraw-ripple/post
        :see: https://coinmate.docs.apiary.io/#reference/cardano-withdrawal-and-deposit/withdraw-cardano/post
        :see: 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   Nz> withdraw() only allows withdrawing the following currencies: z, )r   rl  rq  r   fillResponseFromRequestTr   rO  rl  rp  
withdrawalr   rV  ra  )handle_withdraw_tag_and_paramscheck_addressr  rO  r   r   r  r  r  r   r   joincurrency_to_precisiongetattrr(  r}  	safe_bool)r   r  r   rl  rp  r  rO  withdrawOptionsr   methodallowedCurrenciesr+  r  r   r|  r  s                   r   r\   zcoinmate.withdrawK  s     99#vFFV7###==&&//$,
BGG///9bAA!!'400> $W\\^^ 4 4*j jmqmvmv  xI  nJ  nJ  !J  K  K  K00v>>
 
 ?(+G$%(74((Wf)E)EFF x00,,T8<<"&..B[]a"b"b" 	.$*K!&*K
#%,K	"!$K".K$-K!r   c                 <   |                                   |d}d|i}| |                     |          }|d         |d<   |||d<   |                     |                     ||                    }|                     |dg           }|                     |d||          S )a  
        fetch all trades made by the user
        :see: 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   r"  rN  r   )r  r
  privatePostTradeHistoryr(  	safe_listparse_trades)	r   r   rL  r  r  r+  r
  r  r   s	            r   fetch_my_tradeszcoinmate.fetch_my_trades  s     	=EU
 [[((F&,TlGN#',GO$//GV0L0LMM~~h33  tUE:::r   c                    |                      |d          }|                     ||d          }|                      |d          }|                      |d          }|                     |dd          }|                     |d          }|                      |d          }|                      |d	          }	|                     |d
d          }
d }|                      |d          }|||d         d}|                      |d          }|dk    rdnd}|                     |	||
|                     |
          |d         ||||||d |d|          S )Nr"  _r   r   r   	tradeType	orderTypeorderIdrf  r$  createdTimestampru  r   )r   rO  feeTypeMAKERr   r   r   )r   r   r$  r;  r   r   sider   takerOrMakerr   r   r   ru  )r  safe_marketsafe_string_lower_2r{  safe_integer_2
safe_traderK  )r   trader
  marketIdpriceStringamountStringr  r   r  r   r$  ru  feeCostStringr  s                 r   parse_tradezcoinmate.parse_trade  s   8 ##E>::!!(FC88&&ug66''x88''v{CC%%e[99""5)44e_55''{<NOO	((66$%"7O C ''y99#/7#:#:ww"Y//X&( " 
  
   	r   c                    |                                   |                     |          }|d         dd}|                     |                     ||                    }|                     |dg           }|                     ||||          S )a4  
        get the list of most recent trades for a particular symbol
        :see: 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   
   )r"  minutesIntoHistoryr   )r  r
  publicGetTransactionsr(  r  r  )	r   r   rL  r  r  r
  r+  r  r   s	            r   fetch_tradeszcoinmate.fetch_trades  s     	V$$"4L"$
 
 --dkk'6.J.JKK" ~~h33  vue<<<r   c                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |d          }|                     |d          }|                     t          j        |d                    }	|                     t          j        |d                    }
||d         |	|
ddd	S )
ak  
        fetch the trading fees for a market
        :see: 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>`
        r"  r   r   r   r   100r   T)r   r   r   r   r   r   )	r  r
  privatePostTraderFeesr(  r   r  r   r   
string_div)r   r   r  r
  r+  r  r   makerStringtakerStringr   r   s              r   fetch_trading_feezcoinmate.fetch_trading_fee  s    	V$$F4L
 --dkk'6.J.JKK x44&&tW55&&tW55!!'"4[%"H"HII!!'"4[%"H"HIIX&
 
 	
r   c                     |                      |                     i |                    }ddi}|                     |d         d|||          S )a  
        fetch all unfilled currently open orders
        :see: 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>`
        ra  rC  r   N)privatePostOpenOrdersr(  parse_orders)r   r   rL  r  r  r  	extensions          r   fetch_open_orderszcoinmate.fetch_open_orders  sP     --dkk"f.E.EFFv&	  &!14yQQQr   c                 6   |t          | j        dz             |                                  |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |d         |||          S )a?  
        fetches information on multiple orders made by the user
        :see: 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>`
        Nz) fetchOrders() requires a symbol argumentr"  r   r  r   )r   r   r  r
  privatePostOrderHistoryr(  r  )r   r   rL  r  r  r
  r+  r  s           r   fetch_orderszcoinmate.fetch_orders-  s     >#DG.Y$YZZZV$$F4L
 $GG//GV0L0LMM  &!165%HHHr   c                 >    ddddd}|                      |||          S )NclosedrW  rC  )FILLED	CANCELLEDPARTIALLY_FILLEDOPENr_  r`  s      r   parse_order_statuszcoinmate.parse_order_statusD  s4    # &	
 
 &&999r   c                 :    ddd}|                      |||          S )Nr  r
  )LIMITMARKETr_  )r   r   typess      r   parse_order_typezcoinmate.parse_order_typeM  s.    
 
 tT222r   c           	      V   |                      |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|          S )Nr   r$  r   r   originalAmountremainingAmountr   ra  orderTradeTypeavgPricer"  r  clientOrderId	stopPricer;  lastTradeTimestampr   timeInForcepostOnlyr  triggerPricer   rG  filled)	remainingra  tradesr   ru  )
r  ry  r{  rz  r  r  safe_symbolr  
safe_orderrK  )r   r   r
  r   r$  r  r  r  remainingStringra  r   averageStringr  r   r  r  s                   r   parse_orderzcoinmate.parse_orderT  sM   V eT**%%e[99	%%eV44&&ug66''/?@@,,U4ExPP(()9)9%)J)JKK$$T%5%5e=M%N%NOO((
;;##E>::!!(FC88((@@$$UK88	  
" 
] 
  
 Y//	 

 !$ 
 f 
 D 
 4 
  
 D 
 [ 
  
 I 
 l 
 D 
  }! 
" d# 
$ )- 
  
  
. /  	r   r   r  r   c                 n   |                                   d|                     |          z   }|                     |          }d|d         i}	|dk    r?|dk    r|                     ||          |	d<   n|                     ||          |	d<   |dz  }nJ|                     ||          |	d<   |                     ||          |	d	<   ||                     |          z  } t          | |          |                     |	|                    }
|                     |
d
          }|                     |
|d|          S )a  
        create a trade order
        :see: https://coinmate.docs.apiary.io/#reference/order/buy-limit-order/post
        :see: https://coinmate.docs.apiary.io/#reference/order/sell-limit-order/post
        :see: https://coinmate.docs.apiary.io/#reference/order/buy-instant-order/post
        :see: 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 fullfilled, 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>`
        privatePostr"  r   r
  buyr  r   Instantr   r   )r   r   )	r  
capitalizer
  amount_to_precisionprice_to_precisionr  r(  r  r  )r   r   r   r  r   r   r  r  r
  r+  r  r   s               r   create_orderzcoinmate.create_order  sW    	!6!66V$$F4L
 8u}}#'#;#;FF#K#K  $($<$<VV$L$L!iFF $ 8 8 H HGH#66vuEEGGdood+++F(74((Wf)E)EFFh// 
  
   	r   r   c                    |                                   d|i}d}|r|                     |          }|                     |                     ||                    }|                     |d          }|                     ||          S )a  
        fetches information on an order made by the user
        :see: https://coinmate.docs.apiary.io/#reference/order/get-order-by-orderid/post
        :see: https://coinmate.docs.apiary.io/#reference/order/get-order-by-clientorderid/post
        :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
  privatePostOrderByIdr(  r0  r  )r   r   r   r  r+  r
  r  r   s           r   fetch_orderzcoinmate.fetch_order  s     	r
  	)[[((F,,T[[&-I-IJJ~~h//f---r   c                 d    d|i}|                      |                     ||                    }d|iS )a  
        cancels an open order
        :see: 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   )privatePostCancelOrderWithInfor(  )r   r   r   r  r+  r  s         r   cancel_orderzcoinmate.cancel_order  s=     b/66t{{7F7S7STTH
 	
r   c                 *    |                                  S N)milliseconds)r   s    r   noncezcoinmate.nonce  s      """r   r   GETc           	      L   | j         d         d         dz   |z   }|dk    r|r|d|                     |          z   z  }n|                                  t          |                                           }|| j        z   | j        z   }	|                     |                     |	          |                     | j	                  t          j                  }
|                     |                     | j        || j        |
                                d|                    }ddi}||||d	S )
Nr_   r]   r   r   ?)clientIdr  	publicKey	signaturezContent-Typez!application/x-www-form-urlencoded)urlr  bodyheaders)r   	urlencodecheck_required_credentialsstrr  rf   rd   hmacencodere   hashlibsha256r(  upper)r   pathr_   r  r  r  r  r  r  authr  s              r   signzcoinmate.sign  s$   iv&,t3(?? 4sT^^F3333++---

%%E48#dk1D		$++d"3"3T[[5M5Mw~^^I>>$++ H![&__..	/ /
 # #  D  CG fdwOOOr   c
                 N   |d|v r|d         r|                      |d          }
| j        dz   |
z   }|                     | j        d         |
|           |                     | j        d         |
|           t          | j        dz   |                     |          z             |dk    r||r`| j        dz   |z   }|                     | j        d         ||           |                     | j        d         ||           t          |          t          | j        dz   |z             d S )NerrorerrorMessage r   r   i  )r  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   json)r   r  reasonr  r  r  r  r  requestHeadersrequestBodymessagefeedbacks               r   handle_errorszcoinmate.handle_errors  s:   (""G$ M"..xHHG#w}w6H889QSZ\deee889QSZ\deee'#		(8K8K(KLLL#:: .7S=4/44T_W5MtU]^^^44T_W5MtU]^^^#H---# 4555tr   r  )2__name__
__module____qualname__r   r   r   r  r   r  r  r  r   r   r-  r   r2  r   r   r8  r1  r   r   rS  rc  r   r}  floatr\   r  r   r  r  r   r  r
   r  r  r  r  r  r   r   r	   r  r  r  r  r  r  __classcell__)r   s   @r   r    r       s       O O O O Ob $& V V$v, V V V Vp) ) ) ) ) $& 	, 	,( 	, 	, 	, 	, :>b p ps p3 pY p p p p( 02  /  /3  /f  /  /  /  /D 04B %G %GW %G7 %G %G %G %GN% %6 %V % % % %N 6:[_hj B Bs B# BUX Bost  pA B B B B2
: 
: 
:E
 E
x E
; E
 E
 E
 E
N ?C2 4 4S 4% 4 4 4 4l -1tRV_a ; ;c ; ;C ; ; ; ;2< < <5 < < < <| 6:UW "= "=3 "=s "=# "=\`af\g "= "= "= "=H 57 !
 !
 !
;N !
 !
 !
 !
F /3TXac R R R3 Rc Rhlmrhs R R R R *.Dt\^ I I3 Ic I Icghmcn I I I I.: : :3 3 3O O O5 O O O Ob gksu $ $3 $i $y $RW $`c $ $ $ $L 26b . .c .3 . . . .( 37r 
 
s 
C 
 
 
 
 # # # &eBSW P P P P*      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   typingr   ccxt.base.errorsr   r   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>r     s    ( ' ' ' ' ' . . . . . .  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q       * * * * * * 0 0 0 0 0 0 . . . . . . . . . . . . ) ) ) ) ) ) * * * * * * . . . . . . 4 4 4 4 4 4 % % % % % %B B B B Bx B B B B Br   