
    i                         d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dl m!Z!  G d dee          Z"dS )    )Exchange)ImplicitAPIN)BalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)OrderNotFound)	TICK_SIZE)Precisec                   6    e Zd Z fdZi fdZi fdee         fdZ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fdZdefdZi fdefdZd Zd*d	edefdZdi fdededededef
dZdi fdedefdZdi fdedefdZdddi fdede	de	dee         fdZd*d	ede fdZ!dddi fde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	dee$         fdZ%dddi fdede	de	dee$         fd Z&d*d!Z'd*d"e(de$fd#Z)i fdefd$Z*d% Z+d&d'i ddfd(Z,d) Z- xZ.S )+bitbnsc                 T   |                      t          t          |                                           dddg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	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/d0d1d2d3d4gd5d6d7g d8ig d9g d:d;d<g d=id1d>d?dd	|                     d@          |                     d@          dAit
          t          t          t          t          dBi dCdD          S )ENr   BitbnsINi  Fv2CORSspotTmarginswapfutureoptioncancelAllOrderscancelOrdercreateOrderfetchBalancefetchDepositAddressfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionModefetchPremiumIndexOHLCVfetchStatusfetchTickeremulatedfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransfer)fetchTransfersfetchWithdrawalfetchWithdrawalstransferwithdrawz
bitbns.comzdhttps://user-images.githubusercontent.com/1294454/117201933-e7a6e780-adf5-11eb-9d80-98fc2a21c3d6.jpgzhttps://{hostname}z#https://api.{hostname}/api/trade/v1z#https://api.{hostname}/api/trade/v2)wwwv1r"   zhttps://bitbns.comzhttps://ref.bitbns.com/1090961z'https://bitbns.com/trade/#/api-trading/zhttps://bitbns.com/fees)logoapirK   referraldocfeesget)zorder/fetchMarketszorder/fetchTickerszorder/fetchOrderbookzorder/getTickerWithVolumezexchangeData/ohlczexchangeData/orderBookzexchangeData/tradedetails)zplatform/statustickerszorderbook/sell/{symbol}zorderbook/buy/{symbol})zcurrentCoinBalance/EVERYTHINGzgetApiUsageStatus/USAGEzgetOrderSocketToken/USAGEzcurrentCoinBalance/{symbol}zorderStatus/{symbol}zdepositHistory/{symbol}zwithdrawHistory/{symbol}zwithdrawHistoryAll/{symbol}zdepositHistoryAll/{symbol}zlistOpenOrders/{symbol}zlistOpenStopOrders/{symbol}zgetCoinAddress/{symbol}zplaceSellOrder/{symbol}zplaceBuyOrder/{symbol}zbuyStopLoss/{symbol}zsellStopLoss/{symbol}zcancelOrder/{symbol}zcancelStopLossOrder/{symbol}zlistExecutedOrders/{symbol}zplaceMarketOrder/{symbol}zplaceMarketOrderQnty/{symbol})rR   postrT   )orderscancelgetordersnewmarginOrderstradingquotez0.0025)feeSide	tierBased
percentagetakermaker)400409416417)exactbroad)idname	countries	rateLimit	certifiedversionhashostnameurlsrN   rQ   precisionMode
exceptions)
deep_extendsuperr   describeparse_numberr   r   r   r   r   )self	__class__s    _/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/bitbns.pyrs   zbitbns.describe   s1   fd 3 3 < < > >((( $( 	(
 %( $( "5( t( t( ( &t(  ( &u( #E( *5(  $U!(" "5#( ($ "5%(& '(( !%)(*  +(, e-(. "4/(0 d1(2 !$3(4 $U5(6 )%7(8 t9(: z;(< =(> t?(@ "5A(B #EC(D  E( (F #(#($(!!O( ( (R %~/?? 
 ,<= 2      
     @    W3 3j &!&"&!..x88!..x88  ' &$,(	   }GA
 GA
 G G G	    c                    K   |                      |           d{V }|                     |d          }|                     ddi||          ddd|dS )a  
        the latest known information on the availability of the exchange API
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        Nstatus1ok)rz   updatedetaurlinfo)v1GetPlatformStatussafe_string)ru   paramsresponse	statusRaws       rw   fetch_statuszbitbns.fetch_status   sx       11&99999999 $$Xx88	&&T{IyII
 
 	
rx   returnc                 2  K   |                      |           d{V }g }t          dt          |                    D ]X}||         }|                     |d          }|                     |d          }|                     |d          }|                     |          }	|                     |          }
|                     |di           }|                     |di           }|                     |di           }|                     |d	i           }|                     |d
i           }|dk    }|r|dz   |z   n|}|                    i d|d|d|	dz   |
z   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#           Z|S )$z
        retrieves data on all markets for bitbns
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   rf   baserZ   	precisionlimitsamountpricecostUSDT_uppercaseIdsymbol/settlebaseIdquoteIdsettleIdtyper$   Tr%   Fr&   r'   r(   activecontract)r   r   )minmaxr   r   )leverager   r   r   )linearinversecontractSizeexpiryexpiryDatetimestrike
optionTyper   r   createdr   )
wwwGetOrderFetchMarketsrangelenr   safe_currency_code
safe_valueappendrt   parse_precisionsafe_number)ru   r   r   resultimarketrf   r   r   r   rZ   marketPrecisionmarketLimitsamountLimitspriceLimits
costLimitsusdtr   s                     rw   fetch_marketszbitbns.fetch_markets   s      55f========0 q#h--(( @	 @	Aa[F!!&$//B%%ff55F&&vw77G**622D++G44E"oofk2FFO??68R@@L??<2FFL//,DDKvrBBJv%D6:F6C<'11KMM 1b1{1 $*u,1 	1
 1 $1 &1 71 D1 1 1 %1 1 %1 %1  $!1" E#1$  $"&""//0D0DTEUEUVegoEpEp0q0qrr!..t/C/CDDTDTUdfmDnDn/o/opp   $#! !
  $//eDD#//eDD 
  $//UCC#//UCC 
  $//
EBB#//
EBB  $  a1 1 1 1 1 1 1d rx   Nr   limitc                 J  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||d         |          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :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
        Nr   rf   r   	timestamp)load_marketsr   wwwGetOrderFetchOrderbookextendsafe_integerparse_order_book)ru   r   r   r   r   requestr   r   s           rw   fetch_order_bookzbitbns.fetch_order_book  s       !!!!!!!!!V$$fTl
 $GG77GV8T8TUUUUUUUU$ %%h<<	$$Xvh/?KKKrx   r   c                    |                      |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|          S )Nr   r   lastdatetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechanger]   average
baseVolumequoteVolume)r   r   r   )r   r   safe_symbolsafe_tickeriso8601)ru   tickerr   r   marketIdr   r   s          rw   parse_tickerzbitbns.parse_tickerC  sH   > %%fk::	##FH55!!(F33// !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 ))&+>>!
 4##FE22!
 ))&+>>!
 D$$VV44!
 D$$VV44!
 T!
 D!
 T--foFF!
 d&&vx88!
  $**6<@@!!
" t''	::#!
$ **6<@@++FMBB)!
 !
 !
* +  	rx   symbolsc                    K   |                                   d{V  |                     |           d{V }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :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>`
        N)r   wwwGetOrderFetchTickersparse_tickers)ru   r   r   r   s       rw   fetch_tickerszbitbns.fetch_tickers}  sj       !!!!!!!!!55f========B !!(G444rx   c                 x   d }|||                      |          d}|                     |di           }t          |                                          }t	          dt          |                    D ]}||         }|                    d          }t          |          }	|	dk    r|                     |d          }
|                                 }|                     ||          |d<   |                     |d|
z             |d<   |
d	k    rd
}
| 	                    |
          }|||<   | 
                    |          S )N)r   r   r   datar   availableorder   freeinorderusedMoneyINR)r   r   listkeysr   r   splitr   accountr   safe_balance)ru   r   r   r   r   r   r   keypartsnumParts
currencyIdr   codes                rw   parse_balancezbitbns.parse_balance  s<   	"Y//
 

 x44DIIKK  q#d))$$ 	' 	'Aq'CII.//E5zzH!||!--eQ77
,,.."&"2"24"="="&"2"24Z9O"P"P((!&J..z::&t  (((rx   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )a!  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)r   "v1PostCurrentCoinBalanceEVERYTHINGr   )ru   r   r   s      rw   fetch_balancezbitbns.fetch_balance  sg       !!!!!!!!!@@HHHHHHHH$ !!(+++rx   c                 >    ddddd}|                      |||          S )N	cancelledr   done)z-10r{   2)r   )ru   rz   statusess      rw   parse_statuszbitbns.parse_status  s4    	
 
 &&999rx   c           	         |                      |dd          }|                     |d          }|                     |d          }|                     |d          }|dk    rd}n|dk    rd	}|                     |d
          }|                     |d          }|dk    rd}n|                     |          }|                     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 )"Nrf   entry_idtimet_rater   r   buyr{   sellr   rz   z Successfully cancelled the orderr   r   clientOrderIdr   r   lastTradeTimestampr   timeInForcepostOnlysider   rate	stopPricetriggerPricer   btcr   r   filled)r   currencyr  )	remainingrz   feetrades)safe_string_2r   r   
safe_order	parse8601)	ru   orderr   rf   r   r	  r  r   rz   s	            rw   parse_orderzbitbns.parse_order  s   D tZ88##E622''x88v..3;;DDS[[Dv..!!%22555 FF&&v..F  
E 
" 
 T 
 11	 

  
 !$ 
 d&&vx88 
 4 
  
 D 
 T%%eV44 
  
 L 
 d&&ue44 
 D 
  t! 
" d# 
$   
 3 
  
  
4 5  	rx   r   r  r   r   c                   K   |                                   d{V  |                     |          }|                     |g d          }|                     |d          }	|                     |d          }
|                     |g d          }|                                |d         |                     ||          d}d}|d	k    r|                     ||          |d
<   nd}|d         |d<   ||                     ||          |d<   |	|                     ||	          |d<   |
|                     ||
          |d<    t          | |          | 	                    ||                     d{V }| 
                    ||          S )a  
        create a trade order
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/place-orders
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/market-orders-quantity  # market orders
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at
         *
         * EXCHANGE SPECIFIC PARAMETERS
        :param float [params.target_rate]: *requires params.trail_rate when set, type must be 'limit'* a bracket order is placed when set
        :param float [params.trail_rate]: *requires params.target_rate when set, type must be 'limit'* a bracket order is placed when set
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        N)r	  r  r   target_rate
trail_rate)r	  r  r  r  r   r   )r  r   quantityv2PostOrdersr   r   v1PostPlaceMarketOrderQntySymbolr   r   r   )r   r   safe_string_nr   omitupperamount_to_precisionprice_to_precisiongetattrr   r  )ru   r   r   r  r   r   r   r   r	  
targetRate	trailRater   methodr   s                 rw   create_orderzbitbns.create_order7  s     $ !!!!!!!!!V$$))&2Y2Y2YZZ%%fm<<
$$V\::	6#g#g#ghhJJLL]+00@@
 
  7??"55feDDGFOO7F &y 1GH# $ 7 7 M MGH!%)%<%<VZ%P%PGM" $($;$;FI$N$NGL!.v..t{{7F/K/KLLLLLLLL &111rx   rf   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|                     |dd          }|                     |ddg          }||d         d}d}|rdnd}|d	         d
k    rdnd}	|	|z  }	|	|d<   |                     |                     ||                     d{V }|                     ||          S )aX  
        cancels an open order
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/cancel-orders
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/cancel-stop-loss-orders
        :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
        :param boolean [params.trigger]: True if cancelling a trigger order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz) cancelOrder() requires a symbol argumenttriggerstopr   )r   r   StopLossOrderr
   r   r   
usdtcancelrV   r  )	r   rf   r   r   safe_value_2r  v2PostCancelr   r  )
ru   rf   r   r   r   	isTriggerr   r   tail	quoteSides
             rw   cancel_orderzbitbns.cancel_ordero  s'      >#DG.Y$YZZZ!!!!!!!!!V$$%%fi@@	6Iv#677]+
 
 "+8%+I%6&%@%@LLx	T	#**4;;w+G+GHHHHHHHH&111rx   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         |d}|                     |dd          }|rt          | j        dz             |                     |                     ||                     d{V }|                     |dg           }| 	                    |d	          }	| 
                    |	|          S )
a  
        fetches information on an order made by the user
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-1/order-status
        :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>`
        Nz( fetchOrder() requires a symbol argumentrf   )r   r   r&  r'  z$ fetchOrder cannot fetch stop ordersr   r   )r   rf   r   r   r*  r   v1PostOrderStatusSymbolr   r   	safe_dictr  )
ru   rf   r   r   r   r   r&  r   r   firsts
             rw   fetch_orderzbitbns.fetch_order  s      >#DG.X$XYYY!!!!!!!!!V$$Tl
 
 ##FIv>> 	OTW'MMNNN55dkk'66R6RSSSSSSSS4 x44tQ''v...rx   sincec                   K   |t          | j        dz             |                                  d{V  |                     |          }|                     |dd          }|                     |ddg          }|d         dk    rdnd}|d	         d
|r|dz   n|dz   d}|                     |                     ||                     d{V }	|                     |	dg           }
| 	                    |
|||          S )a  
        fetch all unfilled currently open orders
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/order-status-limit
        :see: https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/order-status-limit/order-status-stop-limit
        :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
        :param boolean [params.trigger]: True if fetching trigger orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentr&  r'  r   r   usdtListOpenlistOpenr   r   
StopOrdersOrders)r   pager  r   )
r   rf   r   r   r*  r  v2PostGetordersnewr   	safe_listparse_orders)ru   r   r5  r   r   r   r,  r.  r   r   r   s              rw   fetch_open_orderszbitbns.fetch_open_orders  s3      >#DG.]$]^^^!!!!!!!!!V$$%%fi@@	6Iv#677'-i'8F'B'BNN	]+2;WY--)hBV
 

 00Wf1M1MNNNNNNNN* ~~h33  vue<<<rx   c                 X   |                      d |          }|                     |dd          }|                     |                     |d                    }|                     |d|          }|                     |dd          }|                     |d          }|                     |d          }|7|                    d	          d
k    rd	}n|                    d          d
k    rd}|                     |d          }d }	|t          j        ||          }n,|                     |d          }|                     |d          }	|d         }
d }|                     |d          }||d         }||d}| 	                    ||| 
                    |          |
||d |d |||	|d|          S )Nrf   tradeIddater   r  r   r   r   r   r   r  factorbase_volumequote_volumer   r  rZ   )r   r  )r   r   r   r   rf   r  r   r  takerOrMakerr   r   r   r  )safe_marketr  r  r   r   safe_string_lowerfindr   
string_div
safe_trader   )ru   trader   orderIdr   priceStringamountStringr  rC  
costStringr   r  feeCostStringfeeCurrencyCodes                 rw   parse_tradezbitbns.parse_trade  s   @ !!$//$$UD)<<NN4#3#3E6#B#BCC	%%e[)DD	((@@''x88%%eV44yy1$$6""a''!!%22
"-lFCCLL++E=AAL))%@@J!((66$$WoO%+ C "Y//  " 
  
   	rx   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d         dd}||                     |          |d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        fetch all trades made by the user
        :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>`
        Nz+ fetchMyTrades() requires a symbol argumentrf   r   r   r;  r5  r   )	r   rf   r   r   r   v1PostListExecutedOrdersSymbolr   r=  parse_trades)	ru   r   r5  r   r   r   r   r   r   s	            rw   fetch_my_tradeszbitbns.fetch_my_trades:  s       >#DG.[$[\\\!!!!!!!!!V$$Tl
 
 #||E22GG<<T[[RX=Y=YZZZZZZZZT ~~h33  vue<<<rx   c                 F  K   |t          | j        dz             |                                  d{V  |                     |          }|d         |d         d}|                     |                     ||                     d{V }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :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>`
        Nz) fetchTrades() requires a symbol argumentr   r   )coinr   )r   rf   r   r   wwwGetExchangeDataTradedetailsr   rW  )ru   r   r5  r   r   r   r   r   s           rw   fetch_tradeszbitbns.fetch_tradesz  s       >#DG.Y$YZZZ!!!!!!!!!V$$8$Y'
 
 <<T[[RX=Y=YZZZZZZZZ   65%@@@rx   r   c                 h  K   |t          | j        dz             |                                  d{V  |                     |          }|d         dd}|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        fetch all deposits made to an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz2 fetchDeposits() requires a currency code argumentrf   r   rU  r   )r   rf   r   r  v1PostDepositHistorySymbolr   r=  parse_transactions	ru   r   r5  r   r   r  r   r   r   s	            rw   fetch_depositszbitbns.fetch_deposits  s       <#DG.b$bccc!!!!!!!!!==&&tn
 
 88Wf9U9UVVVVVVVV0 ~~h33&&tXueDDDrx   c                 h  K   |t          | j        dz             |                                  d{V  |                     |          }|d         dd}|                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a  
        fetch all withdrawals made from an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz5 fetchWithdrawals() requires a currency code argumentrf   r   rU  r   )r   rf   r   r  v1PostWithdrawHistorySymbolr   r=  r_  r`  s	            rw   fetch_withdrawalszbitbns.fetch_withdrawals  s       <#DG.e$efff!!!!!!!!!==&&tn
 
 99$++gv:V:VWWWWWWWW ~~h33&&tXueDDDrx   c           	      ~    dddddddddddd}|                      ||i           }|                     |||          S )Npendingr|   )r   r{   canceledfailed)r   r{   r   3456)deposit
withdrawal)r   r   )ru   rz   r   statusesByTyper   s        rw    parse_transaction_status_by_typez'bitbns.parse_transaction_status_by_type  sp      
  
 
 ??>4<<&&999rx   r  c                    |                      |d          }|                     ||          }|                     |                     |dd                    }|                      |d          }|                      |dd          }d }|R|                    d          dk    rd}d	}n4|                    d
          dk    s|                    d
          dk    r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S )NunitrB  r   r   expTime rm  r   r|   rJ   rn  r   r  )r  r   r   rf   txidr   networkaddress	addressToaddressFromtagtagTotagFromr  rz   r}   )commentinternalr  )r   r   r  r  rI  r   r   )ru   transactionr  r   r   r   r   rs  rz   r   feeCostr  s               rw   parse_transactionzbitbns.parse_transaction  s   . %%k6::
&&z8<<NN4#5#5k6;#W#WXX	V44"";	2>>yy##q(( :&&!++w||J/G/G1/L/L#!!+x88"";66#W55C
K
$
 D
 	

 Y//
 t
 t
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 
 
 	
rx   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     |d          }|                     |d          }|                     |           |||d|dS )a9  
        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr   rf   r   tokenrz  )r  rw  rz  rv  r   )r   r  v1PostGetCoinAddressSymbolr   r   r   check_address)	ru   r   r   r  r   r   r   rw  rz  s	            rw   fetch_deposit_addresszbitbns.fetch_deposit_address,  s       !!!!!!!!!==&&htn
 88Wf9U9UVVVVVVVV x44""411tU++7###
 
 	
rx   c                 *    |                                  S N)milliseconds)ru   s    rw   noncezbitbns.nonceO  s      """rx   rK   GETc                 b   | j         }||d         vrt          | j        dz   |z   dz             |dk    r|                                  d| j        i}|                     | j         d         |                   }|dz   |                     ||          z   }	|                     ||                     |                    }
t          | 
                                          }|dk    r|
r|	d|                     |
          z   z  }	n|d	k    r|
r|                     |
          }nd
}||d}|                     |                     |                    }|                     |                     |          |                     | j                  t"          j                  }||d<   ||d<   d|d<   |	|||dS )NrN   z) does not have a testnet/sandbox URL for z
 endpointsrK   zX-BITBNS-APIKEYr   r  ?POSTz{})timeStamp_noncebodyzX-BITBNS-PAYLOADzX-BITBNS-SIGNATUREz!application/x-www-form-urlencodedzContent-Type)r   r#  r  headers)rn   r   rf   check_required_credentialsapiKeyimplode_hostnameimplode_paramsr  extract_paramsstrr  	urlencodejsonstring_to_base64hmacencodesecrethashlibsha512)ru   pathrN   r#  r   r  r  rn   baseUrlr   queryr  authpayload	signatures                  rw   signzbitbns.signR  s   ytE{""*U UX[ [^j jkkk%<<++---!4;G ''	%(8(=>>md11$???		&$"5"5d";";<<DJJLL!!U?? 3sT^^E2222v yy''#( D ++DIIdOO<<G		$++g"6"6DK8P8PRYR`aaI*1G&',5G()&IGN#fdwOOOrx   c
                    |d S |                      |d          }
|                      |d          }|
d uo|
dk    o|
dk    }|s|| j        dz   |z   }|                     | j        d         |
|           |                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nr   msg200204 rd   re   )r   rf   throw_exactly_matched_exceptionrp   throw_broadly_matched_exceptionr   )ru   httpCodereasonr   r#  r  r  r   requestHeadersrequestBodyr   messageerrorfeedbacks                 rw   handle_errorszbitbns.handle_errorsr  s    4
 &11""8U33T!JJDEM 	*W(w}t+H001I4QYZZZ001I7T\]]]001I7T\]]])))trx   r  )/__name__
__module____qualname__rs   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r
   r  r   r   floatr	   r$  r   r/  r4  r?  r   rS  rX  r\  r   ra  rd  rp  r   r  r  r  r  r  __classcell__)rv   s   @rw   r   r      s       H H H H HT )+ 
 
 
 
8 *, ` `V ` ` ` `D @DB "L "LS "L "LS\ "L "L "L "LH8 86 8V 8 8 8 8t 6:" )5 )57 )5 )5 )5 )5 )5V) ) ) ) )2 *, , , , , , ,6: : :J J J5 J J J JX mqy{ 62 62 62I 62Y 62X] 62fi 62 62 62 62p 9=R 2 2S 2# 2 2 2 2: 8<B 0/ 0/C 0/ 0/ 0/ 0/ 0/d 59tZ^gi .= .=c .= .=TW .=nrsxny .= .= .= .=`J J J5 J J J JX 37TX\eg >= >=C >=s >=RU >= >= >= >=@ <@d[] A A AS A Abfglbm A A A A6 04$UYbd *E *E *EC *Es *Eimnyiz *E *E *E *EX 37TX\eg E EC Es ERU Elpq|l} E E E E0: : : :&>
 >
x >
; >
 >
 >
 >
@ =? !
 !
 !
 !
 !
 !
F# # # #5TPT P P P P@      rx   r   )# ccxt.async_support.base.exchanger   ccxt.abstract.bitbnsr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    rx   rw   <module>r     s   6 5 5 5 5 5 , , , , , ,  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \  \       * * * * * * . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %m m m m mX{ m m m m mrx   