
    !:he                         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 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IntMarketNum	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)List)ExchangeError)ArgumentsRequired)	TICK_SIZE)Precisec                   >    e Zd Zdef 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d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i fdede	de	dee   fdZdddi fdede	de	fdZdd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di ddfdZ  xZ!S )coinspotreturnc           #         | j                  t        t        |          dddgddi dd ddd	dd
dddddddddddddddddddddddddddi ddddddddddddddddd dd!dd"dd#dd$dd%dd&dd'dd(di d)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dddd:d;d<d=d>d?d=d@dAdBdCgidDg dEid>| j	                  dFdGdHdIdFdJdddK      | j	                  dLdMdNdIdLdJdddK      | j	                  dOdPdQdIdOdJdddK      | j	                  dRdSdTdIdRdJdddK      | j	                  dUdVdWdIdUdJdddK      | j	                  dXdYdZdIdXdJdddK      | j	                  d[d\d]dId[dJdddK      | j	                  d^d_d`dId^dJdddK      | j	                  dadbdcdIdadJdddK      | j	                  dddedfdIdddJdddK      | j	                  dgdhdidIdgdJdddK      | j	                  djdkdldIdjdJdddK      | j	                  dmdndodIdmdJdddK      | j	                  dpdqdrdIdpdJdddK      dsdtduiddvidddd dddd dddddwddddddddxd dd dydyddzd d d d d d{	d d d|d d d|d}t
        d~      S )Nr   CoinSpotAUi  FCORSspotTmarginswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLeveragefetchLeverageTiersfetchMarginModefetchMarkOHLCVfetchMyTradesfetchOpenInterestHistoryfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesreduceMarginsetLeveragesetMarginMode)setPositionModewszchttps://user-images.githubusercontent.com/1294454/28208429-3cacdf9a-6896-11e7-854e-4c79a772a30f.jpgz"https://www.coinspot.com.au/pubapizhttps://www.coinspot.com.au/api)publicprivatezhttps://www.coinspot.com.auz0https://www.coinspot.com.au/register?code=PJURCU)logoapiwwwdocreferralgetlatestpost)orderszorders/historyzmy/coin/depositzmy/coin/sendz	quote/buyz
quote/sellzmy/balancesz	my/orderszmy/buyzmy/sellzmy/buy/cancelzmy/sell/cancelzro/my/balanceszro/my/balances/{cointype}zro/my/depositszro/my/withdrawalszro/my/transactionszro/my/transactions/{cointype}zro/my/transactions/openz"ro/my/transactions/{cointype}/openzro/my/sendreceivezro/my/affiliatepaymentszro/my/referralpaymentsadaADA/AUDADAAUDaud)idsymbolbasequotebaseIdquoteIdtyper   btcBTC/AUDBTCethETH/AUDETHxrpXRP/AUDXRPltcLTC/AUDLTCdogeDOGE/AUDDOGErfoxRFOX/AUDRFOXpowrPOWR/AUDPOWRneoNEO/AUDNEOtrxTRX/AUDTRXeosEOS/AUDEOSxlmXLM/AUDXLMrhocRHOC/AUDRHOCgasGAS/AUDGAS)r^   rj   rm   rp   rs   rv   ry   r|   r   r   r   r   r   r   DRKDASHprivate_post_my_balances)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergi )r   limitdaysBack	untilDayssymbolRequired)	sandboxr(   createOrdersr=   
fetchOrderfetchOpenOrdersfetchOrdersfetchClosedOrders
fetchOHLCV)linearinverse)r   r    r!   )rb   name	countries	rateLimitprohasurlsrU   marketscommonCurrenciesoptionsfeaturesprecisionMode)deep_extendsuperr   describesafe_market_structurer   )self	__class__s    G/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coinspot.pyr   zcoinspot.describe   s   h > @666 %6 	6
 %6 %6 U6 t6 $U6  6 $U6 t6 (6 '6 (6  "5!6" #6$ +E%6& )%'6( ')6* (+6, &u-6. #E/60 *5162 $U364 "5566 *5768 +E96:  ;6< %e=6> "5?6@ !%A6B  C6D +EE6F !$G6H  I6J 'K6L $UM6N !%O6P *5Q6R (S6T %eU6V )%W6X tY6Z [6\ t]6^ "5_6` #Ea6b c6d ue6f  g6h $)k6p ~B@ 58N	    !F  55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z 66fPZdjuz  GM  Z_  io  y}  8~   66fPZdjuz  GM  Z_  io  y}  8~   66fPZdjuz  GM  Z_  io  y}  8~  55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z55Uiafqv  CH  UZ  dj  tx  7y  z 66fPZdjuz  GM  Z_  io  y}  8~  55Uiafqv  CH  UZ  dj  tx  7y  z" v!  :
  %&+(-,0,1).+06:#(#("'#(	( #($)$)+027/4#()$, %)&+!%$*%+*/& #''+#')-"&I%N ##
 ##W/` '_pC
 p p	    c                    d|i}| j                  |dd      }t        |t              rt        dt	        |            D ]  }||   }t        |j                               }t        dt	        |            D ]G  }||   }||   }	| j                  |      }
| j                         }| j                  |	d      |d<   |||
<   I  nst        |j                               }t        dt	        |            D ]B  }||   }| j                  |      }
| j                         }| j                  ||      |d<   |||
<   D | j                  |      S )Ninfobalancebalancesr   total)
safe_value_2
isinstancelistrangelenkeyssafe_currency_codeaccountsafe_stringsafe_balance)r   responseresultr   i
currenciescurrencyIdsj
currencyIdr   coder   s               r   parse_balancezcoinspot.parse_balance   sK   )$$Xy*Eh%1c(m, 	+%a[
":??#45q#k"23 +A!,QJ(4G22:>D"llnG'+'7'7'KGG$#*F4L+	+ x}}/K1c+./ '(^
..z:,,.#'#3#3Hj#I &t'   ((r   c                     | j                          | j                  | j                  dd      } t        | |      |      }| j	                  |      S )aY  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.coinspot.com.au/api#listmybalance

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r-   r   )load_marketsr   r   getattrr   )r   paramsmethodr   s       r   fetch_balancezcoinspot.fetch_balance   sO     	!!$,,@Z[(74(0" !!(++r   Nrc   r   c           	          | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||d   ddddd      S )	a,  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.coinspot.com.au/api#listopenorders

        :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
        cointyperb   rc   N	buyorders
sellordersrateamount)r   marketprivatePostOrdersextendparse_order_book)r   rc   r   r   r   request	orderbooks          r   fetch_order_bookzcoinspot.fetch_order_book   sp     	V$t
 **4;;w+GH	$$Yx0@$Uaciksttr   tickerr   c                     | j                  d |      }| j                  |d      }| j                  i d|dd dd dd d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 d d |d|      S )Nlastrc   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechange
percentageaverage)
baseVolumequoteVolumer   )safe_symbolr   safe_ticker)r   r   r   rc   r   s        r   parse_tickerzcoinspot.parse_ticker  s7    !!$// !
f!
!
 !
 D	!

 4!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ )!
* + 	r   c                     | j                          | j                  |      }| j                  |      }|d   }|j                         }| j	                  |di       }| j	                  ||      }| j                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.coinspot.com.au/api#latestprices

        :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   prices)r   r   publicGetLatestlower	safe_dictr  )r   rc   r   r   r   rb   r	  r   s           r   fetch_tickerzcoinspot.fetch_ticker2  sy     	V$''/D\XXZ(B7 +  00r   symbolsc                 p   | j                          | j                  |      }i }| j                  |di       }t        |j	                               }t        dt        |            D ]=  }||   }| j                  |      }	|	d   s|	d   }
||   }| j                  ||	      ||
<   ? | j                  |d|      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.coinspot.com.au/api#latestprices

        :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   rc   )
r   r
  r  r   r   r   r   safe_marketr  filter_by_array_tickers)r   r  r   r   r   r	  idsr   rb   r   rc   r   s               r   fetch_tickerszcoinspot.fetch_tickersQ  s     	''/$ (B76;;=!q#c(# 	CAQB%%b)Ff~)!%!2!266!Bv	C ++FHgFFr   sincec                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a  
        get the list of most recent trades for a particular symbol

        https://www.coinspot.com.au/api#orderhistory

        :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   r\   )r   r   privatePostOrdersHistoryr   	safe_listparse_trades)	r   rc   r  r   r   r   r   r   tradess	            r   fetch_tradeszcoinspot.fetch_tradesz  sv     	V$t
 00Wf1MN (B7  >>r   c                    | j                          i }d}|| j                  |      }|| j                  |      |d<   | j                  | j	                  ||            }| j                  |dg       }t        dt        |            D ]
  }	d||	   d<    | j                  |dg       }
t        dt        |
            D ]
  }	d|
|	   d<    | j                  ||
      }| j                  ||||      S )	a  
        fetch all trades made by the user

        https://www.coinspot.com.au/api#rotransaction

        :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>`
        N	startdater   r   buysider   sell)
r   r   yyyymmddprivatePostRoMyTransactionsr   r  r   r   array_concatr  )r   rc   r  r   r   r   r   r   	buyTradesr   
sellTradesr  s               r   fetch_my_tradeszcoinspot.fetch_my_trades  s    	[[(F#'==#7GK 33DKK4PQ6 NN8["=	q#i.) 	)A#(IaL 	)^^HlB?
q#j/* 	+A$*JqM&!	+""9j9  >>r   tradec                 $   d }d }d }| j                  |d      }| j                  |d|      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |
|d      }| j                  |d      }|| j                  |d      }|}nt        j                  ||	      }| j                  |d	      }| j                  |      }| j                  |d
      }| j                  |d      }t        j                  ||      }d}| j                  |      | j                  |      d}| j                  |d ||| j                  |      d d |d | j                  |      | j                  |	      | j                  |      |d|      S )Naudtotalr   r  r   r   /solddater   createdaudfeeExGstaudGstr`   )costcurrency)r   rb   rc   r   r   orderrh   r  takerOrMakerpricer   r.  fee)r   r  safe_integerr   
string_div	parse8601
string_addparse_numberr   
safe_tradeiso8601)r   r&  r   r   priceStringr3  audTotal
costStringr  amountStringmarketIdrc   r*  createdStringr,  r-  feeCostfeeCurrencyIds                     r   parse_tradezcoinspot.parse_trade  s   4 	##E:6%%eWh?
v.''x8##E84!!(FC8$$UJ7**5&9K I!,,ZFK ,,UI>M}5I**5-@K%%eX6F((f=G!M))'2 33MBC "Y/ &&{3''5%%j1 
  	r   rh   r  r   r2  c                     | j                          d| j                  |      z   }|dk(  rt        | j                  dz         | j	                  |      }|d   ||d}	 t        | |      | j                  |	|            S )a  
        create a trade order

        https://www.coinspot.com.au/api#placebuyorder

        :param str symbol: unified symbol of the market to create an order in
        :param str type: must be '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>`
        privatePostMyr   z' createOrder() allows limit orders onlyrb   )r   r   r   )r   
capitalizer   rb   r   r   r   )
r   rc   rh   r  r   r2  r   r   r   r   s
             r   create_orderzcoinspot.create_order  s     	 4??4#888*S STTV$t

 %wtV$T[[&%ABBr   rb   c                 P   | j                  |d      }|dk7  r|dk7  rt        | j                  dz         | j                  |d      }d|i}d}|dk(  r"| j	                  | j                  ||            }n!| j                  | j                  ||            }| j                  d|i      S )a  
        cancels an open order

        https://www.coinspot.com.au/api#cancelbuyorder
        https://www.coinspot.com.au/api#cancelsellorder

        :param str id: order id
        :param str symbol: not used by coinspot 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  r  z9 cancelOrder() requires a side parameter, "buy" or "sell"rb   Nr   )r   r   rb   omitprivatePostMyBuyCancelr   privatePostMySellCancel
safe_order)r   rb   rc   r   r  r   r   s          r   cancel_orderzcoinspot.cancel_order,  s     /5=TV^#DGG.i$ijj66*"
 5=224;;w3OPH33DKK4PQH H 
  	r   rR   GETc                 ~   | j                   d   |   dz   |z   }|dk(  r| j                          | j                         }| j                  | j	                  d|i|            }d| j
                  | j                  | j                  |      | j                  | j                        t        j                        d}||||dS )NrU   r)  rS   noncezapplication/json)zContent-Typekeysign)urlr   bodyheaders)r   check_required_credentialsrP  jsonr   apiKeyhmacencodesecrethashlibsha512)	r   pathrU   r   r   rU  rT  rS  rP  s	            r   rR  zcoinspot.signK  s    iis#c)D0)++-JJLE99T[['5)96BCD 2{{		$++d"3T[[5Mw~~^G
 fdwOOr   )N)"__name__
__module____qualname__r   r   r   r   r   strr   r
   r   dictr   r   r  r  r   r   r  r   r   r  r   r%  rC  r   r   floatr	   rG  rM  rR  __classcell__)r   s   @r   r   r      s   q# qf) )0 $& ,( ,< :>b us u3 uY u&!4 ! !6 !F 02 13 1f 1> 04B 'GW 'G7 'GR 6:UW ?3 ?s ?# ?\`af\g ?: -1tRV_a 5?c 5? 5?C 5?nB Bv B BH gksu C3 Ci Cy CRW C`c C4 37r s C > &eBSW Pr   r   )ccxt.base.exchanger   ccxt.abstract.coinspotr   r\  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>rn     sI    ( .  C  C  C  C  * . 4 %E	Px E	Pr   