
    !:h                         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$y)    )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                   L    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                     | j                  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/d0d1d2d3d4gd5d6d7g d8ig d9g d:d;d<g d=id1d>d?dd	| j	                  d@      | j	                  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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apirR   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})rY   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)rk   limitdaysBack	untilDayssymbolRequired)rk   triggerrt   r}   )rk   rz   r~   rt   r}   rz   d   )	sandboxr.   createOrdersr>   rA   r@   fetchOrdersfetchClosedOrdersr?   )linearinverse)r'   r)   r*   )400409416417)exactbroad)idname	countries	rateLimit	certifiedversionhashostnameurlsrU   rX   precisionModefeatures
exceptions)
deep_extendsuperr    describeparse_numberr   r   r   r   r   )self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/bitbns.pyr   zbitbns.describe   s   fd < >,,, $, 	,
 %, $, "5, t, t, "4, %d, , &t, (, 1%,   !," &u#,$ #E%,& *5',( $U),* "5+,, "5-,. /,0 !%1,2  3,4 e5,6 "47,8 d9,: !$;,< $U=,> )%?,@ tA,B zC,D E,F  $#($)!&"'#($(!!W,Z %i/??
 ,<= 2   
@  W3j &!&"&!..x8!..x8 '  %&+(,,0,1).+06:#(#("'#(	( #($)$)27+0/4#()$, %)&+!%$(%)*.& ',#($)*.	# ',!%#'$)*.( $()-  #a3l ##
 ##u>B &$,(	 CJA
 J J	    c                 ~    | j                  |      }| j                  |d      }| j                  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   sT     ++F3 $$Xx8	&&T{IyI
 	
r   c                 n   | j                  |      }g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j                  |d      }| j	                  |      }	| j	                  |      }
| j                  |di       }| j                  |di       }| j                  |di       }| j                  |di       }| j                  |d	i       }|d
k(  }|r|dz   |z   n|}|j                  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| j                  |d      ddddddddd| j                  | j                  | j                  |d                  | j                  | j                  | j                  |d                  dddd| j                  |d       | j                  |d!      d| j                  |d       | j                  |d!      d| j                  |d       | j                  |d!      dd"d|d#        |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   basera   	precisionlimitsamountpricecostUSDT_uppercaseIdsymbol/settleNbaseIdquoteIdsettleIdtyper'   Tr(   Fr)   r*   r+   activecontract)r   r   )minmaxr   r   )ru   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   ra   marketPrecisionmarketLimitsamountLimitspriceLimits
costLimitsusdtr   s                     r   fetch_marketszbitbns.fetch_markets   s    //70 q#h-( @	Aa[F!!&$/B%%ff5F&&vw7G**62D++G4E"nnV["EO>>&(B?L>>,"EL..wCKfbAJv%D6:6C<'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$  $"&""//0D0DTEUEUVegoEp0qr!..t/C/CDDTDTUdfmDn/op  $#!
  $//eD#//eD
  $//UC#//UC
  $//
EB#//
EB$  a1 1@	B r   Nr   rz   c                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |d      }| j                  ||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   rz   	timestamp)load_marketsr   wwwGetOrderFetchOrderbookextendsafe_integerparse_order_book)r   r   rz   r   r   requestr   r   s           r   fetch_order_bookzbitbns.fetch_order_bookb  s     	V$fTl
 $GG11$++gv2NO$ %%h<	$$Xvh/?KKr   tickerr   c                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  i d|d|d| j	                  |      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d	| j                  |d	      d
| j                  |d
      d| j                  |d      d| j                  |d      d|d|d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      | j                  |d      | j                  |d      |d|      S )Nr   r   lastdatetimehighlowbid	bidVolumeask	askVolumevwapopenclosepreviousClosechangerd   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  s    > %%fk:	##FH5!!(F3/ !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4##FE2!
 ))&+>!
 4##FE2!
 ))&+>!
 D$$VV4!
 D$$VV4!
 T!
 D!
 T--foF!
 d&&vx8!
  $**6<@!!
" t''	:#!
$ **6<@++FMB)!
* + 	r   symbolsc                 h    | j                          | j                  |      }| j                  ||      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  s6     	//7B !!(G44r   c                    d }||| j                  |      d}| j                  |di       }t        |j                               }t	        dt        |            D ]  }||   }|j                  d      }t        |      }	|	dkD  s*| j                  |d      }
| j                         }| j                  ||      |d<   | j                  |d|
z         |d<   |
d	k(  rd
}
| j                  |
      }|||<    | j                  |      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DIIK q#d)$ 	'Aq'CII./E5zH!|!--eQ7
,,."&"2"24"="&"2"24Z9O"P(!&J..z:&t	'   ((r   c                 f    | j                          | j                  |      }| j                  |      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  s3     	::6B$ !!(++r   c                 6    ddddd}| j                  |||      S )N	cancelledr   done)z-10r   2)r   )r   r   statusess      r   parse_statuszbitbns.parse_status  s,    	
 &&99r   orderc                 H   | j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }|dk(  rd}n|dk(  rd	}| j                  |d
      }| j                  |d      }|dk(  rd}n| j                  |      }| j                  i d|d|dd d| j	                  |      d|dd d| j                  |d      dd dd d|d| j                  |d      d|d| j                  |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   rr   postOnlysider   raterl   r   btcr   r   filled	remaining)r   currencyr*  )r   feetrades)safe_string_2r   r  
safe_order	parse8601)	r   r  r   r   r   rl   r)  r  r   s	            r   parse_orderzbitbns.parse_order.  s   D tZ8##E62''x8v.3;DS[Dv.!!%255 F&&v.F  
E 
" 
 T 
 1	 

  
 !$ 
 d&&vx8 
 4 
  
 D 
 T%%eV4 
 L 
 d&&ue4 
 D 
 t 
  d! 
" # 
$  
 1 
2 3 	r   r   r)  r   r   c                 j   | j                          | j                  |      }| j                  |g d      }| j                  |d      }	| j                  |d      }
| j	                  |g d      }|j                         |d   | j                  ||      d}d}|dk(  r| j                  ||      |d	<   n
d
}|d   |d<   || j                  ||      |d<   |	| j                  ||	      |d<   |
| j                  ||
      |d<    t        | |      | j                  ||            }| j                  ||      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>`
        )rl   	stopPricer#  target_rate
trail_rate)rl   r6  r8  r7  r#  r   )r)  r   quantityv2PostOrdersrz   r*   v1PostPlaceMarketOrderQntySymbolr   r   r#  )r   r   safe_string_nr   omitupperamount_to_precisionprice_to_precisiongetattrr   r4  )r   r   r   r)  r   r   r   r   rl   
targetRate	trailRater   methodr   s                 r   create_orderzbitbns.create_ordery  sP   ( 	V$))&2YZ%%fm<
$$V\:	6#ghJJL]+00@
  7?"55feDGFO7F &y 1GH# $ 7 7 MGH!%)%<%<VZ%PGM" $($;$;FI$NGL!(74(Wf)EF &11r   r   c                 x   |t        | j                  dz         | j                          | j                  |      }| j	                  |dd      }| j                  |ddg      }||d   d}d}|rdnd}|d	   d
k(  rdnd}	|	|z  }	|	|d<   | j                  | j                  ||            }| j                  ||      S )aN  
        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   r4  )
r   r   r   r   r   	isTriggerr   r   tail	quoteSides
             r   cancel_orderzbitbns.cancel_order  s     >#DGG.Y$YZZV$$$VY?	6Iv#67]+
 "+%+I%6&%@Lx	T	#$$T[[&%AB&11r   c                    |t        | j                  dz         | j                          | j                  |      }|d   |d}| j	                  |dd      }|rt        | j                  dz         | j                  | j                  ||            }| j                  |dg       }| j                  |d      }	| j                  |	|      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>`
        z( fetchOrder() requires a symbol argumentr   )r   r!  r~   rG  z$ fetchOrder cannot fetch stop ordersr  r   )r   r   r   r   rJ  r   v1PostOrderStatusSymbolr   	safe_listr   r4  )
r   r   r   r   r   r   r~   r   r  firsts
             r   fetch_orderzbitbns.fetch_order  s     >#DGG.X$XYYV$Tl
 ""69f=TWW'MMNN//GV0LM4 ~~h3tQ'v..r   sincec                    |t        | j                  dz         | j                          | j                  |      }| j	                  |dd      }| j                  |ddg      }|d   dk(  rdnd}|d   d	|r|d
z   n|dz   d}| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
|||      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>`
        z- fetchOpenOrders() requires a symbol argumentr~   rG  r   r   usdtListOpenlistOpenr   r   
StopOrdersOrders)r   pager)  r  )
r   r   r   r   rJ  r=  v2PostGetordersnewr   rR  parse_orders)r   r   rU  rz   r   r   rL  rN  r   r   r  s              r   fetch_open_orderszbitbns.fetch_open_orders  s     >#DGG.]$]^^V$$$VY?	6Iv#67'-i'8F'BN	]+2;Y-)hBV

 **4;;w+GH* ~~h3  vue<<r   tradec                    | j                  d |      }| j                  |dd      }| j                  | j                  |d            }| j	                  |d|      }| j                  |dd      }| j                  |d      }| j                  |d      }|-|j                  d	      d
k\  rd	}n|j                  d      d
k\  rd}| j                  |d      }d }	|t        j                  ||      }n$| j                  |d      }| j                  |d      }	|d   }
d }| j                  |d      }|
|d   }||d}| j                  ||| j                  |      |
||d |d |||	|d|      S )Nr   tradeIddater   r*  r   r   r   r$  r   r%  factorbase_volumequote_volumer   r/  ra   )r   r.  )r   r   r   r   r   r  r   r)  takerOrMakerr   r   r   r/  )safe_marketr1  r3  r   r   safe_string_lowerfindr   
string_div
safe_trader   )r   r_  r   orderIdr   priceStringamountStringr)  rc  
costStringr   r/  feeCostStringfeeCurrencyCodes                 r   parse_tradezbitbns.parse_trade8  s   @ !!$/$$UD)<NN4#3#3E6#BC	%%e[)D	((@''x8%%eV4yy1$6"a'!!%2
"--lFCL++E=AL))%@J!((6$$WoO%+C "Y/  " 
  	r   c                 D   |t        | j                  dz         | j                          | j                  |      }|d   dd}|| j	                  |      |d<   | j                  | j                  ||            }| j                  |dg       }| j                  ||||      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>`
        z+ fetchMyTrades() requires a symbol argumentr   r   r   r[  rU  r  )	r   r   r   r   r   v1PostListExecutedOrdersSymbolr   rR  parse_trades)	r   r   rU  rz   r   r   r   r   r  s	            r   fetch_my_tradeszbitbns.fetch_my_trades  s     >#DGG.[$[\\V$Tl
 #||E2GG66t{{7F7STT ~~h3  vue<<r   c                     |t        | j                  dz         | j                          | j                  |      }|d   |d   d}| j	                  | j                  ||            }| j                  ||||      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>`
        z) fetchTrades() requires a symbol argumentr   r   )coinr   )r   r   r   r   wwwGetExchangeDataTradedetailsr   rv  )r   r   rU  rz   r   r   r   r   s           r   fetch_tradeszbitbns.fetch_trades  s     >#DGG.Y$YZZV$8$Y'
 66t{{7F7ST   65%@@r   r  c                    |t        | j                  dz         | j                          | j                  |      }|d   dd}| j	                  | j                  ||            }| j                  |dg       }| j                  ||||      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>`
        z2 fetchDeposits() requires a currency code argumentr   r   rt  r  )r   r   r   r.  v1PostDepositHistorySymbolr   rR  parse_transactions	r   r  rU  rz   r   r.  r   r   r  s	            r   fetch_depositszbitbns.fetch_deposits  s     <#DGG.b$bcc==&tn
 224;;w3OP0 ~~h3&&tXueDDr   c                    |t        | j                  dz         | j                          | j                  |      }|d   dd}| j	                  | j                  ||            }| j                  |dg       }| j                  ||||      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>`
        z5 fetchWithdrawals() requires a currency code argumentr   r   rt  r  )r   r   r   r.  v1PostWithdrawHistorySymbolr   rR  r~  r  s	            r   fetch_withdrawalszbitbns.fetch_withdrawals  s     <#DGG.e$eff==&tn
 33DKK4PQ ~~h3&&tXueDDr   c           	      n    dddddddddddd}| j                  ||i       }| j                  |||      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#  s[     
  
 >>.$;&&99r   transactionr.  c                 T   | j                  |d      }| j                  ||      }| j                  | j                  |dd            }| j                  |d      }| j                  |dd      }d }|C|j	                  d      dk\  rd}d	}n*|j	                  d
      dk\  s|j	                  d
      dk\  rd}| j                  |d      }	| j                  |d      }
d }|
||
d}i d|dd dd d|d| j                  |      dd dd dd dd dd dd dd d|d|	d|d|dd d d |dS )Nunitrb  r   r   expTime r  r   r   rQ   r  r   r/  )r.  r   r   r   txidr   networkaddress	addressToaddressFromtagtagTotagFromr.  r   r   )commentinternalr/  )r   r   r3  r1  ri  r   r   )r   r  r.  r  r  r   r   r  r   r   feeCostr/  s               r   parse_transactionzbitbns.parse_transaction6  s   . %%k6:
&&z8<NN4#5#5k6;#WX	V4"";	2>yy#q( :&!+w||J/G1/L#!!+x8"";6#W5C
K
$
 D
 	

 Y/
 t
 t
 
 4
 4
 T
 t
 D
 f
 
  f!
" t#
$ )
 	
r   c                 4   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  |d      }| j                  |d      }| j                  |       ||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>`
        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_addressv  s     	==&htn
 224;;w3OP ~~h3""41tU+7#
 	
r   c                 "    | j                         S N)milliseconds)r   s    r   noncezbitbns.nonce  s      ""r   rR   GETc                    | j                   }||d   vrt        | j                  dz   |z   dz         |dk7  r| j                          d| j                  i}| j                  | j                   d   |         }|dz   | j                  ||      z   }	| j                  || j                  |            }
t        | j                               }|dk(  r|
r|	d| j                  |
      z   z  }	n|d	k(  r|
r| j                  |
      }nd
}||d}| j                  | j                  |            }| j                  | j                  |      | j                  | j                         t"        j$                        }||d<   ||d<   d|d<   |	|||dS )NrU   z) does not have a testnet/sandbox URL for z
 endpointsrR   zX-BITBNS-APIKEYr   r  ?POSTz{})timeStamp_noncebodyzX-BITBNS-PAYLOADzX-BITBNS-SIGNATUREz!application/x-www-form-urlencodedzContent-Type)r   rD  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   pathrU   rD  r   r  r  r   baseUrlr   queryr  authpayload	signatures                  r   signzbitbns.sign  s   yytE{"*U UX[ [^j jkk%<++-!4;;G ''		%(8(=>md11$??		&$"5"5d";<DJJL!U?sT^^E222vyy'#(D ++DIIdO<G		$++g"6DKK8PRYR`R`aI*1G&',5G()&IGN#fdwOOr   httpCodereasonr   rD  r  r  c
                 x   |y | j                  |d      }
| j                  |d      }|
d uxr |
dk7  xr |
dk7  }|s|}| j                  dz   |z   }| j                  | j                  d   |
|       | j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )Nr  msg200204 r   r   )r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r  r  r   rD  r  r  r   requestHeadersrequestBodyr  messageerrorfeedbacks                 r   handle_errorszbitbns.handle_errors  s    
 &1""8U3T!JJDEMW(ww}t+H001I4QYZ001I7T\]001I7T\]))r   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   r4  r   r   floatr   rE  r   rO  rT  r^  r   rr  rw  r{  r   r  r  r  r   r  r   r  r  r  intr  __classcell__)r   s   @r   r    r       s   K# KZ #% 
8 $& `$v, `D :>b "Ls "L3 "LY "LH84 8 86 8t 04B )5W )57 )5V) )2 $& ,( ,6:I Iv I IV gksu 823 82i 82y 82RW 82`c 82t 37r 2s 2C 2> 26b 2/c 2/3 2/h /3TXac 0= 0=3 0=c 0=hlmrhs 0=dJ Jv J JX -1tRV_a >=c >= >=C >=@ 6:UW A3 As A# A\`af\g A6 *.Dt\^ *E3 *Ec *E *Ecghsct *EX -1tRV_a Ec E EC Efjkvfw E0:&>
T >
X >
Q\ >
@ 79 !
# !
^ !
F# #5TPT 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     sY    ( ,  q  q  q  q  q  * . ' & . * 4 %wX{ wr   