
    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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)AnyBalancesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)OrderNotFound)	TICK_SIZE)Precisec                   j    e Zd Zdef 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d4d	e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d4ded
edefdZdi fde	dedededef
dZdi fde	defdZdi fde	defdZ dddi fdede
de
dee         fdZ!d4de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(d4d$Z)d4d%ed&e*de&fd'Z+i fd!e	de,fd(Z-d) Z.d*d+i ddfd,Z/d-e0d.e	d/e	d0e	d1ed2e	fd3Z1 xZ2S )5bitbnsreturnc                     |                      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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
          ddd	d dddd dddddBddddddddCd dd d d d	dDdddd	dEdd d	dd	dFd d dGdHidI	d d dJd d dJdKt          t          t          t          dLi dMdN          S )ONr    BitbnsINi  Fv2CORSspotTmarginswapfutureoptioncancelAllOrderscancelOrdercreateOrdercreateStopOrdercreateTriggerOrderfechCurrenciesfetchBalancefetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetwork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.comzOhttps://github.com/user-attachments/assets/a5b9a562-cdd8-4bea-9fa7-fd24c1dad3d9z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apirS   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})rZ   postr\   )orderscancelgetordersnewmarginOrderstradingquotez0.0025)feeSide	tierBased
percentagetakermaker)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventioniceberg)rl   limitdaysBack	untilDayssymbolRequired)rl   triggerru   r~   )rl   r{   r   ru   r~   r{   d   )	sandboxr.   createOrdersr?   rB   rA   fetchOrdersfetchClosedOrdersr@   )linearinverse)r'   r)   r*   )400409416417)exactbroad)idname	countries	rateLimit	certifiedversionhashostnameurlsrV   rY   precisionModefeatures
exceptions)
deep_extendsuperr    describeparse_numberr   r   r   r   r   )self	__class__s    I/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/bitbns.pyr   zbitbns.describe   s2   fd 3 3 < < > >--- $- 	-
 %- $- "5- t- t- "4- %d- !%- - &t- (-  1%!-"  #- -$ &u%-& #E'-( *5)-* $U+-, "5--. "5/-0 1-2 !%3-4  5-6 e7-8 "49-: d;-< !$=-> $U?-@ )%A-B tC-D zE- -F !%##($)!&"'#($(!!Y- - -\ %i/?? 
 ,<= 2      
     @    W3 3j &!&"&!..x88!..x88  '  %&+(,,0,1).+06:#(#("'#(	( ( #($)$)27+0/4#()$ $, %)&+!%$(%)*.& & ',#($)*.	# # ',!%#'$)*.( ( $()-  #a3 3l ## 
 ## u> >B &$,(	   EKA
 KA
 K K K	    c                     |                      |          }|                     |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>`
        status1okN)r   updatedetaurlinfo)v1GetPlatformStatussafe_string)r   paramsresponse	statusRaws       r   fetch_statuszbitbns.fetch_status   sb     ++F33 $$Xx88	&&T{IyII
 
 	
r   c                 J   |                      |          }g }t          dt          |                    D ]l}||         }|                     |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#           n|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
        r   r   baserb   	precisionlimitsamountpricecostUSDT_uppercaseIdsymbol/settleNbaseIdquoteIdsettleIdtyper'   Tr(   Fr)   r*   r+   activecontract)r   r   )minmaxr   r   )rv   r   r   r   )r   r   contractSizeexpiryexpiryDatetimestrike
optionTyper   r   createdr   )wwwGetOrderFetchMarketsrangelenr   safe_currency_code	safe_dictappend	safe_boolr   parse_precisionsafe_number)r   r   r   resultimarketr   r   r   r   rb   marketPrecisionmarketLimitsamountLimitspriceLimits
costLimitsusdtr   s                     r   fetch_marketszbitbns.fetch_markets  s    //770 q#h--(( @	 @	Aa[F!!&$//B%%ff55F&&vw77G**622D++G44E"nnV["EEO>>&(B??L>>,"EEL..wCCKfbAAJ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 r   Nr   r{   c                 .   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     |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
        r   r   Nr{   	timestamp)load_marketsr   wwwGetOrderFetchOrderbookextendsafe_integerparse_order_book)r   r   r{   r   r   requestr   r   s           r   fetch_order_bookzbitbns.fetch_order_bookc  s     	V$$fTl
 $GG11$++gv2N2NOO$ %%h<<	$$Xvh/?KKKr   tickerr   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changere   average
baseVolumequoteVolume)r   r   r   )r   r   safe_symbolsafe_tickeriso8601)r   r   r   r   marketIdr   r   s          r   parse_tickerzbitbns.parse_ticker  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)!
 !
 !
* +  	r   symbolsc                     |                                   |                     |          }|                     ||          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>`
        )r   wwwGetOrderFetchTickersparse_tickers)r   r   r   r   s       r   fetch_tickerszbitbns.fetch_tickers  sB     	//77B !!(G444r   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)r   r   r   r   r  r  r   keypartsnumParts
currencyIdr  codes                r   parse_balancezbitbns.parse_balance  s<   	"Y//
 

 ~~h33DIIKK  q#d))$$ 	' 	'Aq'CII.//E5zzH!||!--eQ77
,,.."&"2"24"="="&"2"24Z9O"P"P((!&J..z::&t  (((r   c                 ~    |                                   |                     |          }|                     |          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>`
        )r   "v1PostCurrentCoinBalanceEVERYTHINGr  )r   r   r   s      r   fetch_balancezbitbns.fetch_balance  s?     	::6BB$ !!(+++r   c                 >    ddddd}|                      |||          S )N	cancelledr   done)z-10r   2)r   )r   r   statusess      r   parse_statuszbitbns.parse_status   s4    	
 
 &&999r   orderc                    |                      |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 )"Nr   entry_idtimet_rater   r  buyr   sellr  r   z Successfully cancelled the orderr  r   clientOrderIdr   r   lastTradeTimestampr   rs   postOnlysider   raterm   r   btcr   r   filled	remaining)r   currencyr+  )r   feetrades)safe_string_2r   r  
safe_order	parse8601)	r   r   r   r   r   rm   r*  r  r   s	            r   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! 
" # 
$   
 1 
  
  
2 3  	r   r   r*  r   r   c                    |                                   |                     |          }|                     |g d          }|                     |d          }	|                     |d          }
|                     |g d          }|                                |d         |                     ||          d}d}|dk    r|                     ||          |d	<   nd
}|d         |d<   ||                     ||          |d<   |	|                     ||	          |d<   |
|                     ||
          |d<    t          | |          | 	                    ||                    }| 
                    ||          S )a  
        create a trade order

        https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/place-orders
        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 fulfilled, 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>`
        )rm   	stopPricer$  target_rate
trail_rate)rm   r7  r9  r8  r$  r   )r*  r   quantityv2PostOrdersr{   r+   v1PostPlaceMarketOrderQntySymbolr   r   Nr$  )r   r   safe_string_nr   omitupperamount_to_precisionprice_to_precisiongetattrr   r5  )r   r   r   r*  r   r   r   r   rm   
targetRate	trailRater   methodr   s                 r   create_orderzbitbns.create_orderz  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!(74((Wf)E)EFF &111r   r   c                    |t          | j        dz             |                                  |                     |          }|                     |dd          }|                     |ddg          }||d         d}d}|rdnd}|d	         d
k    rdnd}	|	|z  }	|	|d<   |                     |                     ||                    }|                     ||          S )aL  
        cancels an open order

        https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/cancel-orders
        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 argumentr   stopr   )r"  r   StopLossOrderr   r   r   
usdtcancelr^   r*  )	r   r   r   r   safe_bool_2r>  v2PostCancelr   r5  )
r   r   r   r   r   	isTriggerr   r   tail	quoteSides
             r   cancel_orderzbitbns.cancel_order  s     >#DG.Y$YZZZV$$$$VY??	6Iv#677]+
 
 "+8%+I%6&%@%@LLx	T	#$$T[[&%A%ABB&111r   c                    |t          | j        dz             |                                  |                     |          }|d         |d}|                     |dd          }|rt          | j        dz             |                     |                     ||                    }|                     |dg           }| 	                    |d	          }	| 
                    |	|          S )
a  
        fetches information on an order made by the user

        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 argumentr   )r   r"  r   rH  z$ fetchOrder cannot fetch stop ordersr  r   )r   r   r   r   rK  r   v1PostOrderStatusSymbolr   	safe_listr   r5  )
r   r   r   r   r   r   r   r   r  firsts
             r   fetch_orderzbitbns.fetch_order  s     >#DG.X$XYYYV$$Tl
 
 ""69f== 	OTW'MMNNN//GV0L0LMM4 ~~h33tQ''v...r   sincec                    |t          | j        dz             |                                  |                     |          }|                     |dd          }|                     |ddg          }|d         dk    rdnd}|d	         d
|r|dz   n|dz   d}|                     |                     ||                    }	|                     |	dg           }
| 	                    |
|||          S )a  
        fetch all unfilled currently open orders

        https://docs.bitbns.com/bitbns/rest-endpoints/order-apis/version-2/order-status-limit
        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   rH  r   r   usdtListOpenlistOpenr   r   
StopOrdersOrders)r   pager*  r  )
r   r   r   r   rK  r>  v2PostGetordersnewr   rS  parse_orders)r   r   rV  r{   r   r   rM  rO  r   r   r  s              r   fetch_open_orderszbitbns.fetch_open_orders  s    >#DG.]$]^^^V$$$$VY??	6Iv#677'-i'8F'B'BNN	]+2;WY--)hBV
 

 **4;;w+G+GHH* ~~h33  vue<<<r   tradec                 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 )Nr   tradeIddater   r+  r   r   r   r%  r   r&  factorbase_volumequote_volumer   r0  rb   )r   r/  )r   r   r   r   r   r   r   r*  takerOrMakerr   r   r   r0  )safe_marketr2  r4  r   r   safe_string_lowerfindr   
string_div
safe_trader   )r   r`  r   orderIdr   priceStringamountStringr*  rd  
costStringr   r0  feeCostStringfeeCurrencyCodes                 r   parse_tradezbitbns.parse_trade9  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//  " 
  
   	r   c                    |t          | j        dz             |                                  |                     |          }|d         dd}||                     |          |d<   |                     |                     ||                    }|                     |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 argumentr   r   r   r\  rV  r  )	r   r   r   r   r   v1PostListExecutedOrdersSymbolr   rS  parse_trades)	r   r   rV  r{   r   r   r   r   r  s	            r   fetch_my_tradeszbitbns.fetch_my_trades  s     >#DG.[$[\\\V$$Tl
 
 #||E22GG66t{{7F7S7STTT ~~h33  vue<<<r   c                 *   |t          | j        dz             |                                  |                     |          }|d         |d         d}|                     |                     ||                    }|                     ||||          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   r   r   r   wwwGetExchangeDataTradedetailsr   rw  )r   r   rV  r{   r   r   r   r   s           r   fetch_tradeszbitbns.fetch_trades  s     >#DG.Y$YZZZV$$8$Y'
 
 66t{{7F7S7STT   65%@@@r   r  c                 L   |t          | j        dz             |                                  |                     |          }|d         dd}|                     |                     ||                    }|                     |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 argumentr   r   ru  r  )r   r   r   r/  v1PostDepositHistorySymbolr   rS  parse_transactions	r   r  rV  r{   r   r/  r   r   r  s	            r   fetch_depositszbitbns.fetch_deposits  s     <#DG.b$bccc==&&tn
 
 224;;w3O3OPP0 ~~h33&&tXueDDDr   c                 L   |t          | j        dz             |                                  |                     |          }|d         dd}|                     |                     ||                    }|                     |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 argumentr   r   ru  r  )r   r   r   r/  v1PostWithdrawHistorySymbolr   rS  r  r  s	            r   fetch_withdrawalszbitbns.fetch_withdrawals  s     <#DG.e$efff==&&tn
 
 33DKK4P4PQQ ~~h33&&tXueDDDr   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   )r   r   r   statusesByTyper  s        r    parse_transaction_status_by_typez'bitbns.parse_transaction_status_by_type$  sp      
   
  
 >>.$;;&&999r   transactionr/  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unitrc  r   r   expTime r  r   r   rR   r  r   r0  )r/  r   r   r   txidr   networkaddress	addressToaddressFromtagtagTotagFromr/  r   r   )commentinternalr0  )r   r   r4  r2  rj  r   r   )r   r  r/  r  r  r   r   r  r   r   feeCostr0  s               r   parse_transactionzbitbns.parse_transaction7  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#
$ )
 
 
 	
r   c                 z   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |di           }|                     |d          }|                     |d          }|                     |           ||d||dS )a7  
        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>`
        r   r   r  tokenr  N)r   r/  r  r  r  )r   r/  v1PostGetCoinAddressSymbolr   r   r   check_address)	r   r  r   r/  r   r   r  r  r  s	            r   fetch_deposit_addresszbitbns.fetch_deposit_addressw  s     	==&&htn
 224;;w3O3OPP ~~h33""411tU++7###
 
 	
r   c                 *    |                                  S N)milliseconds)r   s    r   noncezbitbns.nonce  s      """r   rS   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 )NrV   z) does not have a testnet/sandbox URL for z
 endpointsrS   zX-BITBNS-APIKEYr   r  ?POSTz{})timeStamp_noncebodyzX-BITBNS-PAYLOADzX-BITBNS-SIGNATUREz!application/x-www-form-urlencodedzContent-Type)r   rE  r  headers)r   r   r   check_required_credentialsapiKeyimplode_hostnameimplode_paramsr>  extract_paramsstrr  	urlencodejsonstring_to_base64hmacencodesecrethashlibsha512)r   pathrV   rE  r   r  r  r   baseUrlr   queryr  authpayload	signatures                  r   signzbitbns.sign  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Or   httpCodereasonr   rE  r  r  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 r   r   )r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r  r   rE  r  r  r   requestHeadersrequestBodyr  messageerrorfeedbacks                 r   handle_errorszbitbns.handle_errors  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\]]])))tr   r  )3__name__
__module____qualname__r   r   r   r   r
   r   r  r	   r   r   dictr   r   r   r   r  r   r  r  r  r   r5  r   r   floatr   rF  r   rP  rU  r_  r   rs  rx  r|  r   r  r  r  r   r  r   r  r  r  intr  __classcell__)r   s   @r   r    r       s       L# L L L L L L\ #% 
 
 
 
8 $& ` `$v, ` ` ` `D :>b "L "Ls "L3 "LY "L "L "L "LH8 84 8 86 8 8 8 8t 04B )5 )5W )57 )5 )5 )5 )5V) ) ) ) )2 $& , ,( , , , ,6: : :I I Iv I I I I IV gksu 82 823 82i 82y 82RW 82`c 82 82 82 82t 37r 2 2s 2C 2 2 2 2> 26b 2/ 2/c 2/3 2/ 2/ 2/ 2/h /3TXac 0= 0= 0=3 0=c 0=hlmrhs 0= 0= 0= 0=dJ J Jv J J J J JX -1tRV_a >= >=c >= >=C >= >= >= >=@ 6:UW A A3 As A# A\`af\g A A A A6 *.Dt\^ *E *E3 *Ec *E *Ecghsct *E *E *E *EX -1tRV_a E Ec E EC Efjkvfw E E E E0: : : :&>
 >
T >
X >
Q\ >
 >
 >
 >
@ 79 !
 !
# !
^ !
 !
 !
 !
F# # # #5TPT P P P P@c 3 S # X\ dg        r   r    )%ccxt.base.exchanger   ccxt.abstract.bitbnsr   r  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>r     s   ( ' ' ' ' ' , , , , , ,  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q  q       * * * * * * . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %x x x x xX{ x x x x xr   