
    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 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IntMarketNum	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)List)ExchangeError)ArgumentsRequired)	TICK_SIZE)Precisec                   6    e Zd Z 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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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 )coinspotc           #      0   |                      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@dAgidBg dCid<|                     dDdEdFdGdDdHdddI          |                     dJdKdLdGdJdHdddI          |                     dMdNdOdGdMdHdddI          |                     dPdQdRdGdPdHdddI          |                     dSdTdUdGdSdHdddI          |                     dVdWdXdGdVdHdddI          |                     dYdZd[dGdYdHdddI          |                     d\d]d^dGd\dHdddI          |                     d_d`dadGd_dHdddI          |                     dbdcdddGdbdHdddI          |                     dedfdgdGdedHdddI          |                     dhdidjdGdhdHdddI          |                     dkdldmdGdkdHdddI          |                     dndodpdGdndHdddI          dqdrdsiddtit
          du          S )vNr   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fetchPositionModefetchPositions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)rY   re   rh   rk   rn   rq   rt   rw   rz   r}   r   r   r   r   DRKDASHprivate_post_my_balances)r]   name	countries	rateLimitprohasurlsrP   marketscommonCurrenciesoptionsprecisionMode)deep_extendsuperr   describesafe_market_structurer   )self	__class__s    S/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/coinspot.pyr   zcoinspot.describe   s[   h 5 5 > > @ @333 %3 	3
 %3 %3 U3 t3 $U3  3 $U3 t3 (3 '3 (3  "5!3" #3 3$ +E%3& )%'3( ')3* (+3, &u-3. #E/30 *5132 $U334 "5536 *5738 +E93:  ;3< %e=3> "5?3@ !%A3B  C3D +EE3 3 3F !$G3H  I3J $UK3L !%M3N %eO3P )%Q3R tS3T U3V tW3X "5Y3Z #E[3\ ]3^ u_3`  a3b "5c3d ee3 3j ~B@  58N	 	      ! !F  55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 66fPZdjuz  GM  Z_  io  y}  8~  8~     66fPZdjuz  GM  Z_  io  y}  8~  8~     66fPZdjuz  GM  Z_  io  y}  8~  8~    55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 66fPZdjuz  GM  Z_  io  y}  8~  8~    55Uiafqv  CH  UZ  dj  tx  7y  7y  z  z " v!  : 'y}C
 }C
 } } }	    returnc                 .   d|i}|                      |dd          }t          |t                    rt          dt	          |                    D ]}||         }t          |                                          }t          dt	          |                    D ]Y}||         }||         }	|                     |          }
|                                 }|                     |	d          |d<   |||
<   Znt          |                                          }t          dt	          |                    D ]Q}||         }|                     |          }
|                                 }|                     ||          |d<   |||
<   R| 	                    |          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   s   (#$$Xy*EEh%% 	'1c(mm,, 	+ 	+%a[
":??#4#455q#k"2"233 + +A!,QJ(4G22:>>D"llnnG'+'7'7'K'KGG$#*F4LL+	+ x}}//K1c+..// ' '(^
..z::,,..#'#3#3Hj#I#I &t  (((r   c                     |                                   |                     | j        dd          } t          | |          |          }|                     |          S )a]  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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   s_     	!!$,@Z[[(74((00" !!(+++r   Nr^   limitc           	          |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||d         ddddd          S )	a0  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        cointyper]   r^   N	buyorders
sellordersrateamount)r   marketprivatePostOrdersextendparse_order_book)r   r^   r   r   r   request	orderbooks          r   fetch_order_bookzcoinspot.fetch_order_book   s     	V$$t
 **4;;w+G+GHH	$$Yx0@$Uacikstttr   r   c                 H   |                      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|          S )Nlastr^   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechange
percentageaverage)
baseVolumequoteVolumer   )safe_symbolr   safe_ticker)r   tickerr   r^   r   s        r   parse_tickerzcoinspot.parse_ticker   sR    !!$//// !
f!
!
 !
 D	!

 4!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ )!
 !
 !
* +  	r   c                 :   |                                   |                     |          }|                     |          }|d         }|                                }|                     |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://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>`
        r]   prices)r   r   publicGetLatestlower
safe_value	safe_dictr   )r   r^   r   r   r   r]   r   r   s           r   fetch_tickerzcoinspot.fetch_ticker   s     	V$$''//D\XXZZ844 ++  000r   symbolsc                    |                                   |                     |          }i }|                     |d          }t          |                                          }t          dt          |                    D ]P}||         }|                     |          }	|	d         r)|	d         }
||         }|                     ||	          ||
<   Q| 	                    |d|          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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   r^   )
r   r   r   r   r   r   r   safe_marketr   filter_by_array_tickers)r   r   r   r   r   r   idsr   r]   r   r^   r   s               r   fetch_tickerszcoinspot.fetch_tickers  s     	''//$ 8446;;==!!q#c((## 	C 	CAQB%%b))Ff~ C)!%!2!266!B!Bv++FHgFFFr   sincec                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |dg           }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :see: 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   r]   rW   )r   r   privatePostOrdersHistoryr   	safe_listparse_trades)	r   r^   r   r   r   r   r   r   tradess	            r   fetch_tradeszcoinspot.fetch_trades?  s     	V$$t
 00Wf1M1MNN (B77  >>>r   c                 J   |                                   i }d}||                     |          }||                     |          |d<   |                     |                     ||                    }|                     |dg           }t          dt          |                    D ]}	d||	         d<   |                     |dg           }
t          dt          |
                    D ]}	d|
|	         d<   |                     ||
          }| 	                    ||||          S )	a  
        fetch all trades made by the user
        :see: 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   r^   r   r   r   r   r   r   	buyTradesr   
sellTradesr   s               r   fetch_my_tradeszcoinspot.fetch_my_tradesZ  s/    	[[((F#'==#7#7GK 33DKK4P4PQQ6 OOHk2>>	q#i..)) 	) 	)A#(IaL  __X|R@@
q#j//** 	+ 	+A$*JqM&!!""9j99  >>>r   c                    d }d }d }|                      |d          }|                      |d|          }|                      |d          }|                      |d          }	|                      |d          }
|                     |
|d          }|                     |d          }||                      |d          }|}nt          j        ||	          }|                      |d	          }|                     |          }|                      |d
          }|                      |d          }t          j        ||          }d}|                     |          |                     |          d}| 	                    |d ||| 
                    |          d d |d |                     |          |                     |	          |                     |          |d|          S )Naudtotalr   r   r   r   /solddater   createdaudfeeExGstaudGstr[   )costcurrency)r   r]   r^   r   r   orderrc   r   takerOrMakerpricer   r
  fee)r   r   safe_integerr   
string_div	parse8601
string_addparse_numberr   
safe_tradeiso8601)r   trader   r   priceStringr  audTotal
costStringr   amountStringmarketIdr^   r  createdStringr  r	  feeCostfeeCurrencyIds                     r   parse_tradezcoinspot.parse_trade  s   4 	##E:66%%eWh??
v..''x88##E844!!(FC88$$UJ77**5&99K II!,ZFFK ,,UI>>M}55I**5-@@K%%eX66F(f==G!M))'22 33MBB C "Y// &&{33''55%%j11 
  
   	r   rc   r   r   r  c                 0   |                                   d|                     |          z   }|dk    rt          | j        dz             |                     |          }|d         ||d}	 t          | |          |                     |	|                    S )a  
        create a trade order
        :see: 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 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>`
        privatePostMyr   z' createOrder() allows limit orders onlyr]   )r   r   r   )r   
capitalizer   r]   r   r   r   )
r   r^   rc   r   r   r  r   r   r   r   s
             r   create_orderzcoinspot.create_order  s     	 4??4#8#888*S STTTV$$t
 

 %wtV$$T[[&%A%ABBBr   r]   c                 8   |                      |d          }|dk    r|dk    rt          | j        dz             |                     |d          }d|                     |          z   dz   }d|i} t          | |          |                     ||                    S )a  
        cancels an open order
        :see: https://www.coinspot.com.au/api#cancelbuyorder
        :see: 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"r"  Cancelr]   )r   r   r]   omitr#  r   r   )r   r]   r^   r   r   r   r   s          r   cancel_orderzcoinspot.cancel_order  s     //5==TV^^#DG.i$ijjj66** 4??4#8#888C"
 %wtV$$T[[&%A%ABBBr   rM   GETc                    | j         d         |         dz   |z   }|dk    r|                                  |                                 }|                     |                     d|i|                    }d| j        |                     |                     |          |                     | j                  t          j
                  d}||||dS )NrP   r  rN   noncezapplication/json)zContent-Typekeysign)urlr   bodyheaders)r   check_required_credentialsr+  jsonr   apiKeyhmacencodesecrethashlibsha512)	r   pathrP   r   r   r0  r/  r.  r+  s	            r   r-  zcoinspot.sign  s    is#c)D0)++---JJLLE99T[['5)96BBCCD 2{		$++d"3"3T[[5M5Mw~^^ G
 fdwOOOr   )N) __name__
__module____qualname__r   r   r   r   strr   r	   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r
   floatr   r$  r(  r-  __classcell__)r   s   @r   r   r      s       ~ ~ ~ ~ ~@) ) ) ) )0 $& , ,( , , , ,8 :>b u us u3 uY u u u u"! !6 !V ! ! ! !F 02 1 13 1f 1 1 1 1: 04B %G %GW %G7 %G %G %G %GN 6:UW ? ?3 ?s ?# ?\`af\g ? ? ? ?6 -1tRV_a 3? 3?c 3? 3?C 3? 3? 3? 3?jB B B5 B B B BH gksu C C3 Ci Cy CRW C`c C C C C0 37r C Cs CC C C C C( &eBSW P P P P P P P Pr   r   )ccxt.base.exchanger   ccxt.abstract.coinspotr   r7  ccxt.base.typesr   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>rH     s,   ( ' ' ' ' ' . . . . . .  } } } } } } } } } } } } } } } } } } } } } } } } } } } }       * * * * * * . . . . . . 4 4 4 4 4 4 % % % % % %yP yP yP yP yPx yP yP yP yP yPr   