
    eiv                        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%dS )    )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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d9d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d9d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ddi fdeded	efdZd9d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)d9d'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.Z0d/ Z1d0d1i ddfd2Z2de3d3ed4ed5ed6ed7efd8Z4 xZ5S ):coinmatereturnc                 x	   |                      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	d8dd9d	i d:d	d;d	d<d	d=dd>d	d?d	d@d	dAddBd	dCd	dDddEddFddGd	dHd	dId	dJd	i dKd	dLd	dMd	dNd	dOd	dPddQddRddSddTd	dUdVdWd	dXd	dYd	dZd	d[d	d\d	d	d	d	d	dd]d^d_d`idadbdcddgdedfddddgdhg diidjg dkidldmdd|                     dn          |                     do          |                     dp          |                     dn          g|                     dq          |                     dr          g|                     ds          |                     dt          g|                     du          |                     dv          g|                     dw          |                     dx          g|                     dy          |                     dz          g|                     d{          |                     d|          g|                     d}          |                     d~          gg|                     dp          |                     do          g|                     dq          |                     d          g|                     ds          |                     d|          g|                     du          |                     d          g|                     dw          |                     d          g|                     dy          |                     d          g|                     d{          |                     d          g|                     d}          |                     d          ggddidddddddddddd	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	dddd	dd	d	d	d	dd	d d	d	ddd	dd d d	d	ddd d d	d d dd d dddt
          it          t          t          t          t          t          ddt          d          S )Nr!   CoinMate)GBCZEUiX  CORSTspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelOrdercloseAllPositionsclosePositioncreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreatePostOnlyOrdercreateReduceOnlyOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTradesfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsemulatedfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginrepayMarginsetLeverage)	setMargin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tradingPairszsystem/timepost)6
currenciesbalancesbitcoinCashWithdrawalbitcoinCashDepositAddressesbitcoinDepositAddressesbitcoinWithdrawalbitcoinWithdrawalFees
buyInstantbuyLimitr2   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bankWireWithdrawal)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  )	sandboxr5   createOrdersr^   re   rb   rg   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requiredCredentialsr   r   optionsfeatures
exceptionsprecisionMode)deep_extendsuperr!   describeparse_numberr   r   r   r   r   r   )self	__class__s    K/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/coinmate.pyr  zcoinmate.describe   s
   h 5 5 > > @ @+++[[[ %[ 	[
 %[ %[ U[ $U[ '[ [ t[ $U[  [ t[ 7[  9%![" &u#[ [$ (%[& '[( &u)[* "5+[, +E-[. )%/[0 #E1[2 ,U3[4 '5[6 (7[8 +D9[: &u;[< '=[> (?[@ #EA[B *5C[D $UE[ [ [F uG[H "5I[J *5K[L +EM[N )%O[P  Q[R !%S[T %eU[V $UW[X &uY[Z -e[[\ /][^ "5_[` #Ea[b +Ec[d e[f !%g[ [ [h "5i[j &uk[l +Em[n  o[p $Uq[r +Es[t %eu[v "4w[x uy[z #E{[| d}[~ !$[@ tA[B  C[D 'E[F $UG[H !%I[ [ [J *5K[L (M[N %eO[P )%Q[R )%S[T tU[V W[X tY[Z "4[[\ #E][^ $Z_[` )%a[b c[d #Ee[f &ug[h ui[j uk[ [l #!&#(! u[ [ [z 5 -254 g  $ $    
  7 7 79F FP !%"&!..w77!..w77 "..s33T5F5Fw5O5OP!..w779J9J79S9ST!..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<Mg<V<VW	" "..s33T5F5Fw5O5OP!..w779J9J79S9ST!..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<Mi<X<XY	"  > /3=>A>< ;999
  
  $  %&+(,,0,1).+06:#'#("&#(	( ( #($($)+027/4#')$ $, %)&+!%$*%+*/& & ',#($)*/	# # ',!%#($)*.( ( ',!$$(%)#($)*.$ $ *."&o8 8t ## 
 ## }B BJ -m =N*6+7-9):&9 	  'q	yC
 yC
 y y y	    c                 X    |                      |          }|                     |d          S )a\  
        fetches the current integer timestamp in milliseconds from the bingx server

        https://coinmate.docs.apiary.io/#reference/system/get-server-time/get

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the bingx server
        
serverTime)publicGetSystemTimesafe_integerr  paramsresponses      r   
fetch_timezcoinmate.fetch_timeT  s/     ++F33   <888r!  c                    |                      |          }|                     |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 )"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  r'  r(  r+  resultimarketr  r3  r4  r0  r1  r/  s                r   fetch_marketszcoinmate.fetch_marketse  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+  rI  r   	availablefreereservedusedbalancetotal)	rK  listkeysrL  rM  rO  accountrN  safe_balance)
r  r(  r   rS  currencyIdsrT  
currencyIdcoder\  r`  s
             r   parse_balancezcoinmate.parse_balance  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 )an  
        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privatePostBalancesre  r&  s      r   fetch_balancezcoinmate.fetch_balance  s=     	++F33!!(+++r!  Nr/  r  c           	      :   |                                   |                     |          }|d         dd}|                     |                     ||                    }|d         }|                     |d          }|                     ||d         |ddd	d
          S )aD  
        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;  )rg  rU  publicGetOrderBookextendsafe_timestampparse_order_book)	r  r/  r  r'  rU  requestr(  	orderbookrn  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

        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>`
        rl  r  r+  )rg  rU  publicGetTickerrr  	safe_dictparse_ticker)r  r/  r'  rU  ru  r(  r+  s          r   fetch_tickerzcoinmate.fetch_ticker  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

        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/  )rg  market_symbolspublicGetTickerAllrK  r^  r_  rL  rM  rU  r{  filter_by_array_tickers)
r  r}  r'  r(  r+  r_  rS  rT  rU  r   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   rU  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 )Nrn  lastr/  datetimehighlowbid	bidVolumeaskvwap	askVolumeopenclosepreviousClosechanger   averager;  )
baseVolumequoteVolumerI  )rs  rR  safe_tickeriso8601)r  r   rU  rn  r  s        r   r{  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!  rd  sincec                 $   |                                   ddi}|||d<   |||d<   | |                     |          }|d         |d<   |                     |                     ||                    }|d         }|                     |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+  )rg  r  privatePostTransferHistoryrr  parse_transactions)	r  rd  r  r  r'  ru  r  r(  itemss	            r   fetch_deposits_withdrawalsz#coinmate.fetch_deposits_withdrawalse  s     	T
 $GG',GO$}}T**H"*4.GJ224;;w3O3OPP &&udE5AAAr!  statusc                 D    dddddddd}|                      |||          S )Nokpendingcanceled)	COMPLETEDWAITINGSENTCREATEDOKNEWCANCELEDrN  r  r  statusess      r   parse_transaction_statusz!coinmate.parse_transaction_status  s=      "
 
 &&999r!  transactionr  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 )Nrn  amountCurrencyrI  r  transactionIdtxidr6  transferTyper  network
walletTyper;  r  transferStatusr  addressdestinationaddressFrom	addressTotagdestinationTagtagFromtagToupdatedfee)r@  r  rate)commentinternalr  )r%  rN  rO  safe_string_2safe_string_lowerrR  r  r  )r  r  r  rn  rc  rd  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;  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

        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   Nz> withdraw() only allows withdrawing the following currencies: z, )r;  r  r  r+  fillResponseFromRequestTr;  r  r  r  
withdrawalr6  r  r  )handle_withdraw_tag_and_paramscheck_addressrg  r  rK  r  rN  r^  r_  r   r  joincurrency_to_precisiongetattrrr  r  	safe_bool)r  rd  r;  r  r  r'  r  withdrawOptionsr   methodallowedCurrenciesru  r(  r+  r  r  s                   r   r   zcoinmate.withdraw  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

        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  rl  r  r+  )rg  rU  privatePostTradeHistoryrr  	safe_listparse_trades)	r  r/  r  r  r'  ru  rU  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!  tradec                    |                      |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 )Nrl  _r<  r;  r6  	tradeType	orderTypeorderIdr  rn  createdTimestampr  r1  )r@  r  feeTypeMAKERr   r   r/  )r  rI  rn  r  r/  r6  sider   takerOrMakerr<  r;  r@  r  )rN  safe_marketsafe_string_lower_2r  safe_integer_2
safe_trader  )r  r  rU  marketIdpriceStringamountStringr  r6  r  r  rn  r  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 )a.  
        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  
   )rl  minutesIntoHistoryr+  )rg  rU  publicGetTransactionsrr  r  r  )	r  r/  r  r  r'  rU  ru  r(  r+  s	            r   fetch_tradeszcoinmate.fetch_tradesd  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 )
ae  
        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>`
        rl  r  r+  r   r   100r/  T)rI  r/  r   r   r   r   )	rg  rU  privatePostTraderFeesrr  rK  rN  r  r   
string_div)r  r/  r'  rU  ru  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

        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>`
        r  r  r+  N)privatePostOpenOrdersrr  parse_orders)r  r/  r  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 )a9  
        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>`
        Nz) fetchOrders() requires a symbol argumentrl  r  r  r+  )r   r  rg  rU  privatePostOrderHistoryrr  r  )r  r/  r  r  r'  rU  ru  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closedr  r  )FILLED	CANCELLEDPARTIALLY_FILLEDOPENr  r  s      r   parse_order_statuszcoinmate.parse_order_status  s4    # &	
 
 &&999r!  r6  c                 :    ddd}|                      |||          S )Nr  rU  )LIMITMARKETr  )r  r6  typess      r   parse_order_typezcoinmate.parse_order_type  s.    
 
 tT222r!  r   c                 P   |                      |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|          S )Nr  rn  r6  r<  originalAmountremainingAmountr;  r  orderTradeTypeavgPricerl  r  clientOrderIdr  lastTradeTimestampr/  r   postOnlyr  r   	stopPricer@  r  filled	remaining)r  tradesrI  r  )
rN  r%  r  r  r  r  safe_symbol
safe_orderr  rR  )r  r   rU  r  rn  r  r  r  remainingStringr  r6  averageStringr  r/  r  s                  r   parse_orderzcoinmate.parse_order  sE   d 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((@@  
" 
] 
  
 Y//	 

 !$ 
 f 
 D 
 4 
  
 D 
 [ 
 D,,UK@@ 
 l 
 D 
 } 
  d! 
" # 
$ + 
  
  
, -  	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

        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>`
        privatePostrl  r  rU  buyr]  r;  Instantr<  r+  )rI  r  )	rg  
capitalizerU  amount_to_precisionprice_to_precisionr  rr  rN  r  )r  r/  r6  r  r;  r<  r'  r  rU  ru  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

        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+  )rg  rU  privatePostOrderByIdrr  rz  r  )r  r  r/  r'  ru  rU  r(  r+  s           r   fetch_orderzcoinmate.fetch_orderf  s     	r
  	)[[((F,,T[[&-I-IJJ~~h//f---r!  c                     d|i}|                      |                     ||                    }|                     |d          }|                     |          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+  )privatePostCancelOrderWithInforr  rz  r  )r  r  r/  r'  ru  r(  r+  s          r   cancel_orderzcoinmate.cancel_order}  sW     #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.  r   r   hmacencoder   hashlibsha256rr  upper)r  pathr   r  r'  r7  r6  r5  r.  authr4  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!  reasonr5  r  r7  r6  c
                     |d S |                      |d          }
|
`| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         |
|           t          |          d S )NerrorMessage r  r  )rN  r  throw_exactly_matched_exceptionr  throw_broadly_matched_exceptionr   )r  rd  rC  r5  r  r7  r6  r(  requestHeadersrequestBodyrE  feedbacks               r   handle_errorszcoinmate.handle_errors  s    4
 ''.AA#w}t+H001I<Yabbb001I<Yabbb)))tr!  r,  )6__name__
__module____qualname__r   r  r   r)  r   r	   rV  r   re  ri  r:  r   rw  r   r|  r   r   r  dictr{  r   r   r  r  r   r  floatr   r  r   r  r  r   r  r   r  r  r  r  r  r   r   r
   r$  r'  r*  r.  rB  intrL  __classcell__)r  s   @r   r!   r!      s       z# z z z z z zx	 !# 9 9s 9 9 9 9" $& X X$v, X X X Xt) ) ) ) ) $& , ,( , , , , :>b p ps p3 pY p p p p, 02 "/ "/3 "/f "/ "/ "/ "/H 04B 'G 'GW 'G7 'G 'G 'G 'GR% %4 % %6 % % % %N 6:[_hj B Bs B# BUX Bost  pA B B B B6
:s 
: 
: 
: 
:E
 E
T E
X E
Q\ E
 E
 E
 E
N KOWY 6 6S 6% 6# 6C 6^i 6 6 6 6p -1tRV_a ; ;c ; ;C ; ; ; ;6< < <v < < < < <| 6:UW $= $=3 $=s $=# $=\`af\g $= $= $= $=L 57 #
 #
 #
;N #
 #
 #
 #
J /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2: : : : :3S 3 3 3 3T T Tv T T T T Tl gksu & &3 &i &y &RW &`c & & & &P 26b . .c .3 . . . .. 37r & &s &C & & & &6# # # &eBSW P P P 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>r\     s   ( ' ' ' ' ' . . . . . .  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v  v       * * * * * * 0 0 0 0 0 0 . . . . . . . . . . . . ) ) ) ) ) ) * * * * * * . . . . . . 4 4 4 4 4 4 % % % % % %g g g g gx g g g g gr!  