
    ei,|                         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dS )    )Exchange)ImplicitAPIN)AnyBalancesIntMarketNum	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)List)ExchangeError)ArgumentsRequired)	TICK_SIZE)Precisec                   D    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                 |   |                      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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dUddVddWddXddYddZdd[dddd\d]d^d_d`dad_dbdcdddegidfg dgiddg dhidfg diid`dji dk|                     dldkdmdndldodddp          dq|                     dldqdmdrdldsdddp          dt|                     dsdtdrdndsdodddp          du|                     dvdudwdndvdodddp          dx|                     dydxdzdndydodddp          d{|                     d|d{d}dnd|dodddp          d~|                     dd~ddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          d|                     ddddnddodddp          ddiddidddd dddd dddddddddddddd dd dddd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borrowCrossMarginborrowIsolatedMarginborrowMargincancelOrdercloseAllPositionsclosePositioncreateMarketOrdercreateOrder$createOrderWithTakeProfitAndStopLoss&createOrderWithTakeProfitAndStopLossWscreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchCrossBorrowRatefetchCrossBorrowRatesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarkOHLCVfetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTradesfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOptionfetchOptionChainfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginrepayMarginsetLeverage	setMargin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/historymy/coin/depositzmy/coin/sendz	quote/buyz
quote/sellzmy/balancesz	my/ordersmy/buymy/sellmy/buy/cancelmy/sell/cancelro/my/balanceszro/my/balances/{cointype}ro/my/depositsro/my/withdrawalszro/my/transactionszro/my/transactions/{cointype}zro/my/transactions/openz"ro/my/transactions/{cointype}/openro/my/sendreceivero/my/affiliatepaymentsro/my/referralpayments)r|   zlatest/{cointype}zlatest/{cointype}/{markettype}zbuyprice/{cointype}z buyprice/{cointype}/{markettype}zsellprice/{cointype}z!sellprice/{cointype}/{markettype}zorders/open/{cointype}z#orders/open/{cointype}/{markettype}zorders/completed/{cointype}z(orders/completed/{cointype}/{markettype}z#orders/summary/completed/{cointype}z0orders/summary/completed/{cointype}/{markettype}) statusr   zquote/buy/nowzquote/sell/nowzquote/swap/nowr   zmy/buy/editr   zmy/sell/editz
my/buy/nowzmy/sell/nowzmy/swap/nowr   zmy/buy/cancel/allr   zmy/sell/cancel/allzmy/coin/withdraw/senddetailszmy/coin/withdraw/sendz	ro/statuszro/orders/market/openzro/orders/market/completedr   zro/my/balance/{cointype}zro/my/orders/market/openzro/my/orders/limit/openzro/my/orders/completedzro/my/orders/market/completedr   r   r   r   r   )rt   ru   v2zBTC/AUDbtcBTCAUDaud)idsymbolbasequotebaseIdquoteIdtyper   zBTC/USDTUSDTusdtzUSDT/AUDzETH/AUDethETHzADA/AUDadaADAzSOL/AUDsolSOLzXRP/AUDxrpXRPzDOGE/AUDdogeDOGEzLTC/AUDltcLTCzXLM/AUDxlmXLMzTRX/AUDtrxTRXzEOS/AUDeosEOSzA/AUDAzNEO/AUDneoNEOanszPOWR/AUDpowrPOWRzGAS/AUDgasGASzRHOC/AUDrhocRHOC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+   createOrdersrU   
fetchOrderfetchOpenOrdersfetchOrdersfetchClosedOrders
fetchOHLCV)linearinverse)r   r    r!   )r   name	countries	rateLimitprohasurlsrw   marketscommonCurrenciesoptionsfeaturesprecisionMode)deep_extendsuperr   describesafe_market_structurer   )self	__class__s    Y/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/coinspot.pyr   zcoinspot.describe   s3   h 5 5 > > @ @XXX %X 	X
 %X %X UX $UX 'X X tX $UX  X $UX tX  7!X" 9%#X X$ &u%X& ('X( ')X* (+X, "5-X. /X0 &u1X2 "53X4 +E5X6 )%7X8 #E9X: ,U;X< '=X> (?X@ &uAXB 'CXD (EX X XF #EGXH *5IXJ $UKXL uMXN "5OXP *5QXR +ESXT )%UXV  WXX !%YXZ %e[X\ $U]X^ &u_X` -eaXb /cXd "5eXf #EgX X Xh +EiXj !%kXl "5mXn &uoXp +EqXr  sXt $UuXv +EwXx %eyXz u{X| #E}X~ !$X@  AXB 'CXD $UEXF !%GXH *5IX X XJ (KXL %eMXN )%OXP )%QXR tSXT UXV tWXX "5YXZ #E[X\ )%]X^ _X` #EaXb &ucXd ueXf ugXh UiXj  kX Xl $)oX X Xt ~B@  58N	 	      :       $  -! -! -!/ %B BCd dJ455Uiafqv  CH  UZ  dj  tx  7y  7y  z  zD66ezchsy  FK  X^  hn  x|  8}  8}  ~  ~ D66fPZdjuz  GM  Z_  io  y}  8~  8~     455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z	
 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z D66fPZdjuz  GM  Z_  io  y}  8~  8~     455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z 335G]`kp  }B  OT  ^d  nr  5s  5s  t  t 455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z D66fPZdjuz  GM  Z_  io  y}  8~  8~      455Uiafqv  CH  UZ  dj  tx  7y  7y  z  z!" D66fPZdjuz  GM  Z_  io  y}  8~  8~    #( v!  :
  %&+(-,0,1).+06:#(#("'#(	( ( #($)$)+027/4#()$ $, %)&+!%$*%+*/& & #''+#')-"&I% %N ## 
 ## W/ /` 'oXC
 XC
 X X X	    c                 .   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                    K   |                                   d{V  |                     | j        dd          } t          | |          |           d{V }|                     |          S )aW  
        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>`
        Nr3   r   )load_marketsr   r   getattrr  )r   paramsmethodr   s       r   fetch_balancezcoinspot.fetch_balanceF  s       !!!!!!!!!!!$,@Z[[.v..v66666666" !!(+++r   Nr   r   c           	        K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||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
        Ncointyper   r   	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_bookd  s       !!!!!!!!!V$$t
 00Wf1M1MNNNNNNNN	$$Yx0@$Uacikstttr   tickerr  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   r  r  r   r  s        r   parse_tickerzcoinspot.parse_tickerw  sR    !!$//// !
f!
!
 !
 D	!

 4!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ )!
 !
 !
* +  	r   c                 X  K   |                                   d{V  |                     |          }|                     |           d{V }|d         }|                                }|                     |di           }|                     ||          }|                     ||          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>`
        Nr   prices)r  r  publicGetLatestlower	safe_dictr,  )r   r   r  r  r   r   r.  r  s           r   fetch_tickerzcoinspot.fetch_ticker  s       !!!!!!!!!V$$--f55555555D\XXZZ(B77 ++  000r   symbolsc                   K   |                                   d{V  |                     |           d{V }i }|                     |di           }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

        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>`
        Nr.  r   r   r   )
r  r/  r1  r   r   r   r   safe_marketr,  filter_by_array_tickers)r   r3  r  r   r   r.  idsr   r   r  r   r  s               r   fetch_tickerszcoinspot.fetch_tickers  s      !!!!!!!!!--f55555555$ (B776;;==!!q#c((## 	C 	CAQB%%b))Ff~ C)!%!2!266!B!Bv++FHgFFFr   sincec                 4  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     ||||          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>`
        Nr
  r   r~   )r  r  privatePostOrdersHistoryr  	safe_listparse_trades)	r   r   r9  r   r  r  r  r   tradess	            r   fetch_tradeszcoinspot.fetch_trades  s       !!!!!!!!!V$$t
 66t{{7F7S7STTTTTTTT (B77  >>>r   c                 f  K   |                                   d{V  i }d}||                     |          }||                     |          |d<   |                     |                     ||                     d{V }|                     |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

        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   r9  r   r  r  r  r   	buyTradesr   
sellTradesr>  s               r   fetch_my_tradeszcoinspot.fetch_my_trades  sW      !!!!!!!!![[((F#'==#7#7GK 99$++gv:V:VWWWWWWWW6 NN8["==	q#i..)) 	) 	)A#(IaL  ^^HlB??
q#j//** 	+ 	+A$*JqM&!!""9j99  >>>r   tradec                    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   rC  r  r  /solddater  createdaudfeeExGstaudGstr   )costcurrency)r   r   r   r  r  orderr   rC  takerOrMakerpricer  rS  fee)r   r*  safe_integerr   
string_div	parse8601
string_addparse_numberr   
safe_tradeiso8601)r   rK  r  r  priceStringrX  audTotal
costStringrC  amountStringmarketIdr   rO  createdStringrQ  rR  feeCostfeeCurrencyIds                     r   parse_tradezcoinspot.parse_trade6  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   r   rC  r  rW  c                 v  K   |                                   d{V  d|                     |          z   }|dk    rt          | j        dz             |                     |          }|d         ||d}	 t          | |          |                     |	|                     d{V }
|                     |
          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>`
        NprivatePostMyr  z' createOrder() allows limit orders onlyr   )r
  r  r  )r  
capitalizer   r   r  r  r  parse_order)r   r   r   rC  r  rW  r  r  r  r  r   s              r   create_orderzcoinspot.create_orderz  s       !!!!!!!!! 4??4#8#888*S STTTV$$t
 

 /v..t{{7F/K/KLLLLLLLL)))r   r   c                   K   |                      |d          }|dk    r|dk    rt          | j        dz             |                     |d          }d|i}d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     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>`
        rC  rB  rD  z9 cancelOrder() requires a side parameter, "buy" or "sell"r   Nr   )r   r   r   omitprivatePostMyBuyCancelr  privatePostMySellCancel
safe_order)r   r   r   r  rC  r  r   s          r   cancel_orderzcoinspot.cancel_order  s       //5==TV^^#DG.i$ijjj66**"
 5==!88Wf9U9UVVVVVVVVHH!99$++gv:V:VWWWWWWWWH H 
   	r   rt   GETc                 <   t          |t                    }|r|d         nd }|r|d         n|}	d|                     ||          z   }
|d|z   |
z   n|
}| j        d         |	         |z   }|	dk    r|                                  |                                 }|                     |                     d|i|                    }d| j        | 	                    | 
                    |          | 
                    | j                  t          j                  d}||||d	S )
Nr      rN  rw   ru   noncezapplication/json)zContent-Typekeysign)urlr  bodyheaders)r   r   implode_paramsr   check_required_credentialsrw  jsonr  apiKeyhmacencodesecrethashlibsha512)r   pathrw   r  r  r|  r{  isVersionedApiversion
accessTypeendpointfullPathrz  rw  s                 r   ry  zcoinspot.sign  s"   #C..*4#a&&-6SVV3
,,T6:::070C3=8++(iz*X5""++---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  r  strr   r
   r  dictr   r   r,  r2  r   r   r8  r   r   r?  r   rJ  rh  r   r   floatr	   rm  rs  ry  __classcell__)r   s   @r   r   r      s       Y# Y Y Y Y Y Yv) ) ) ) )0 *, , , , , , ,< @DB u uS u uS\ u u u u&! !4 ! !6 ! ! ! !F 68 1 1 1F 1 1 1 1> 6:" 'G 'G7 'G 'G 'G 'G 'GR <@d[] ? ? ?S ? ?bfglbm ? ? ? ?: 37TX\eg 5? 5?C 5?s 5?RU 5? 5? 5? 5?nB B Bv B B B B BH mqy{ * * *I *Y *X] *fi * * * *6 9=R  S #    > &eBSW P P P P P P P Pr   r   ) ccxt.async_support.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>r     s   6 5 5 5 5 5 . . . . . .  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C  C       * * * * * * . . . . . . 4 4 4 4 4 4 % % % % % %s
P s
P s
P s
P s
Px s
P s
P s
P s
P s
Pr   