
    i                         d dl mZ d dlm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 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)ImplicitAPI)BalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransaction)List)ExchangeError)AuthenticationError)ArgumentsRequired)InsufficientFunds)OrderNotFound)	TICK_SIZE)Precisec                       e Zd Z fdZi fdee         fdZdi f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d1d
edefdZi fdedefdZdi fdedefdZd Zd1d
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fdZi fdefdZdddi fde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di fdedededee         fdZ"dddi fdededefdZ#d1d
ede$fdZ%dddi fdededefd Z&i fd!efd"Z'd# Z(d1d$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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i fded!efd*Z0i fde1fd+Z2di fdedefd,Z3d-d.i ddfd/Z4d0 Z5 xZ6S )2blockchaincomc                 
   |                      t          t          |                                           i dddd ddddgdd	d
ddddi dddddd ddddddddddddddddddddddddddd di d!dd"dd#dd$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1ddddddddddddddddd2d3d d4d5d6d6d7d8d8d7d9d:g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?dAd?d?d?dBd?d?dCdDd7dEdFd>dd|                     dG          |                     dH          g|                     dI          |                     dJ          g|                     dK          |                     dL          g|                     dM          |                     dN          g|                     dO          |                     dN          g|                     dP          |                     dN          g|                     dQ          |                     dN          g|                     dR          |                     dS          g|                     dT          |                     dU          g|                     dV          |                     dW          g|                     dX          |                     dY          g|                     dZ          |                     d[          gg|                     dG          |                     dL          g|                     dI          |                     d\          g|                     dK          |                     d]          g|                     dM          |                     dY          g|                     dO          |                     d^          g|                     dP          |                     d[          g|                     dQ          |                     d_          g|                     dR          |                     d`          g|                     dT          |                     da          g|                     dV          |                     db          g|                     dX          |                     dc          g|                     dZ          |                     dG          ggdddeidfdddgdhdii djdkdldmdndndododpdpdqdqdrdsdtdtdududvdvdwdwdxdxdydydzdzd{d{d|d|d}d}i d~d~ddddddddddddddddddddddddddddddidt
          dt          t          di d          S )Nidr   secretnamezBlockchain.com	countriesLX	rateLimiti  versionv3proThasCORSFspotmarginswapfutureoptioncancelAllOrderscancelOrdercreateOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchCanceledOrdersfetchClosedOrdersfetchDepositfetchDepositAddressfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchL2OrderBookfetchL3OrderBookfetchLedgerfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrder)fetchOrderBookfetchPositionModefetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFeesfetchTransferfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelisttransferwithdraw
timeframesurlszehttps://user-images.githubusercontent.com/1294454/147515585-1296e91b-7398-45e5-9d32-f6121538533f.jpegz"https://testnet-api.delta.exchange)publicprivatez&https://api.blockchain.com/v3/exchangezhttps://blockchain.comzhttps://api.blockchain.com/v3z$https://exchange.blockchain.com/fees)logotestapiwwwdocfeesra   get   )tickersztickers/{symbol}symbolszsymbols/{symbol}zl2/{symbol}zl3/{symbol})rd   ordersorders/{orderId}tradesfillsdepositszdeposits/{depositId}accountszaccounts/{account}/{currency}	whitelistzwhitelist/{currency}withdrawalszwithdrawals/{withdrawalId})ri   zdeposits/{currency}rp   )ri   rj   )re   postdeleterd   trading0z0.00410000z0.002250000z0.002100000z0.0018500000100000025000005000000z0.001625000000z0.0014	100000000z0.0011	500000000z0.0008
1000000000z0.0006z0.0012z0.001z0.0007000000000000001z0.0005z0.0004z0.0003z0.0002z0.0001)takermaker)feeSide	tierBased
percentagetiersrequiredCredentials)apiKeyr!   optionsnetworksERC20ETHTRC20TRXALGOADAARATOMAVAXCAVAXBCHBSVBTCDCRDESODASHCELOCHZMATICSOLDOGEDOTEOSETCFILKAVALTCIOTAMIOTANEARSTXXLMXMRXRPXTZZECZILprecisionMode
exceptions)401404)exactbroad)deep_extendsuperr   describeparse_numberr   r   r   )self	__class__s    X/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/blockchaincom.pyr   zblockchaincom.describe   sE	   mT : : C C E E NH
/NH
dNH
 $NH
 $	NH

 NH
 tNH
 4NH
  222 $2 	2
 %2 %2 "42 t2 t2 '2 (2 "42 2 &t2 $T2  !2" &t#2 2$  %2& &u'2( #E)2* *5+2, $U-2. "5/20 #D122 #D324 u526 "5728 92: !%;2<  =2> e?2@ +EA2B "4C2D dE2 2F #'%**/# $$#($(!&"'#'$(,0! c2 2 2NH
v $wNH
x BC 
 GG  03 ? yNH
X #$,-#$,-'('( 	 !""#,-"#!"$%01$%9:%&01'(67   #$/0'(  #$,- + % %YNH
d $!%"& "..s33T5F5Fw5O5OP!..w779J9J89T9TU!..w779J9J79S9ST!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPX>Y>YZ" "..s33T5F5Fw5O5OP!..w779J9J89T9TU!..w779J9J79S9ST!..x88$:K:KH:U:UV!..x88$:K:KLc:d:de!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY!..{;;T=N=Nx=X=XY!..|<<d>O>OPS>T>TU" 	" "$eNH
n "$ $oNH
v  (U(U( F( 5	(
 $( F( V( 5( 5( 5( 5( F( F( F(  5!(" W#($ 5%( (& F'(( 5)(* 5+(, 5-(. 5/(0 F1(2 53(4 G5(6 F7(8 59(: 5;(< 5=(> 5?(@ 5A(B 5C(D 5E( (*wNH
L YMNH
N .(   ONH
 N N N	    returnc                 Z   |                      |          }t          |                                          }g }t          dt	          |                    D ]}||         }|                     ||          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|                     |d          }d}|                     |d          }|dk    rd}nd	}|                     |d
          }|                     |d          }| 	                    |          }t          j        ||          }|                     |d          }|                     |d          }| 	                    |          }t          j        ||          }|                     |d          }|                     |d          }| 	                    |          }t          j        ||          }|                     |          }d}|                     |d          }|dk    rV|                     |d          }| 	                    |          }t          j        ||          }|                     |          }nd}|                    i d|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'           |S )(a%  
        retrieves data on all markets for blockchaincom
        :see: https://api.blockchain.com/v3/#/unauthenticated/getSymbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   base_currencycounter_currencyr    NstatusopenTFmin_price_incrementmin_price_increment_scalelot_sizelot_size_scalemin_order_sizemin_order_size_scalemax_order_sizert   max_order_size_scaleinfo	numericIdsymbol/basequotesettlebaseIdquoteIdsettleIdtyper+   r,   r-   r.   r/   active)amountprice)minmax)leverager   r   cost)contractlinearinversecontractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreated)publicGetSymbolslistkeysrangelen
safe_valuesafe_stringsafe_currency_codesafe_numberparse_precisionr   
string_mulr   append) r   paramsmarkets	marketIdsresultimarketIdmarketr   r   r   r   r   r   marketStateminPriceIncrementStringminPriceIncrementScaleStringminPriceScalePrecisionStringpricePrecisionStringlotSizeStringlotSizeScaleStringlotSizeScalePrecisionStringamountPrecisionStringminOrderSizeStringminOrderSizeScaleString minOrderSizeScalePrecisionStringminOrderSizePreciseStringminOrderSizemaxOrderSizemaxOrderSizeScaleString maxOrderSizeScalePrecisionStringmaxOrderSizeStrings                                    r   fetch_marketszblockchaincom.fetch_markets   sG   : ''//((	q#i..)) Y	 Y	A |H__Wh77F%%fo>>F&&v/ABBG**622D++G44E((66IF**68<<Kf$$&*&6&6v?T&U&U#+/+;+;FD_+`+`(+/+?+?@\+]+](#*#56MOk#l#l  ,,VZ@@M!%!1!1&:J!K!K*.*>*>?Q*R*R'$+$6}Fa$b$b!!%!1!1&:J!K!K&*&6&6v?U&V&V#/3/C/CD[/\/\,(/(:;MOo(p(p%,,-FGGLL++F4DEELs""*.*:*:6CY*Z*Z'373G3GH_3`3`0%,%7Ff%g%g"#001CDD#MM 11h1 Y1 $*u,	1
 1 1 $1 &1 71 D1 1 1 %1 1 %1  %!1" &#1$ " $"&""//0EFF!../CDD   $#! !
  ,+ 
  $# 
  $#  $  a1 1 1 1 1 1 1d r   Nr   limitc                 0    |                      |||          S )a@  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://api.blockchain.com/v3/#/unauthenticated/getL3OrderBook
        :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
        )fetch_l3_order_book)r   r   r  r   s       r   fetch_order_bookzblockchaincom.fetch_order_bookb  s     ''v>>>r   c           	      
   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||d         ddddd          S )	a  
        fetches level 3 information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://api.blockchain.com/v3/#/unauthenticated/getL3OrderBook
        :param str symbol: unified market symbol
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order book structure <https://docs.ccxt.com/#/?id=order-book-structure>`
        r   r    Ndepthbidsaskspxqty)load_marketsr   publicGetL3Symbolextendparse_order_bookr   r   r  r   r   requestresponses          r   r  z!blockchaincom.fetch_l3_order_bookm  s     	V$$fTl
 $GG))$++gv*F*FGG$$Xvh/?vvW[]bcccr   c           	      
   |                                   |                     |          }d|d         i}|||d<   |                     |                     ||                    }|                     ||d         d dddd          S )Nr   r    r  r  r  r  r  )r  r   publicGetL2Symbolr  r  r  s          r   fetch_l2_order_bookz!blockchaincom.fetch_l2_order_book  s    V$$fTl
 $GG))$++gv*F*FGG$$Xvh/?vvW[]bcccr   r   c                 ~   |                      |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|          S )Nr   -last_trade_price
volume_24h	price_24h	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapr   closelastpreviousClosechanger   average)
baseVolumequoteVolumer   )r   safe_symbolsafe_ticker)r   tickerr   r   r   r1  r5  r   s           r   parse_tickerzblockchaincom.parse_ticker  st    ##FH55!!(FC88(:;;%%fl;;
44 !
f!
!
 !
 D	!

 4!
 4!
 !
 4!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %)!
 !
 !
* +  	r   c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://api.blockchain.com/v3/#/unauthenticated/getTickerBySymbol
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r   r    )r  r   publicGetTickersSymbolr  r:  )r   r   r   r   r  r  s         r   fetch_tickerzblockchaincom.fetch_ticker  sp     	V$$fTl
 ..t{{7F/K/KLL  6222r   rh   c                     |                                   |                     |          }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://api.blockchain.com/v3/#/unauthenticated/getTickers
        :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  publicGetTickersparse_tickers)r   rh   r   rg   s       r   fetch_tickerszblockchaincom.fetch_tickers  s?     	''//!!'7333r   c                 B    ddddddd}|                      |||          S )Nr   rejectedclosedcanceledexpired)OPENREJECTEDFILLEDCANCELEDPART_FILLEDEXPIREDr   r   statestatess      r   parse_order_statezblockchaincom.parse_order_state  s:    ""! 
 
 u555r   c                    |                      |d          }|                     |d          }|                      |d          }|                     |          }|                     |d          }|                      |d          }|                     ||d          }	|                      |d          }
|dk    r|                      |d	          n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g g |d          }|S )NclOrdIdordType	ordStatussider   r#  exOrdIdr   r   avgPxr'  cumQty	leavesQtyr    clientOrderIdr(  lastTradeTimestampr   r   timeInForcer4  r   filled	remainingr   rk   )rd   r   )r   safe_string_lowerrQ  r7  r   safe_integeriso8601
safe_order)r   orderr   r[  r   statusIdrO  rV  r   r   exchangeOrderIdr   r4  r'  r(  r^  r_  r   s                     r   parse_orderzblockchaincom.parse_order  s3   & ((	::%%eY77##E;77&&x00%%eV44##E844!!(FC88**5)<<59X5E5E  000D""5'22%%e[99	<<	**!!%22$$UK88	 "
/"
]"
 "
 	"

 !$"
 e"
 f"
 D"
 4"
 D"
 U"
 w"
 d"
 f"
 "
  D!"
" b#"
$ '"
 "
 "
  * r   r   rV  r   r   c                    |                                   |                     |          }|                     |d|          }|                                }	|                     |dd|                                           }
|                     |g d          }|	|d         |                                |                     ||          |
d}|                     |dd          }|                     |ddg          }|	d	k    s|	d
k    r|t          | j
        dz   |	z   dz             ||	dk    rd	|d<   n|	dk    rd
|d<   d}d}|d         dk    s|d         d
k    rd}|d         d	k    s|d         d
k    rd}|r|                     ||          |d<   |r|                     ||          |d<   |                     |                     ||                    }|                     ||          S )a  
        create a trade order
        :see: https://api.blockchain.com/v3/#/trading/createOrder
        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rT  r[  rS  )rT  r[  rS  r    )rT  r   rV  orderQtyrS  stopPx	stopPriceSTOP	STOPLIMITNz: createOrder() requires a stopPx or stopPrice param for a z orderMARKETLIMITFTr   )r  r   r   uppersafe_string_2uuid16omitamount_to_precisionsafe_value_2r   r    price_to_precisionprivatePostOrdersr  rg  )r   r   r   rV  r   r   r   r   	orderTypeuppercaseOrderTyper[  r  rk  priceRequiredstopPriceRequiredr  s                   r   create_orderzblockchaincom.create_order  sL    	V$$$$VY==	&__..**6?It{{}}]]6#J#J#JKK *TlJJLL00@@$

 

 %%fhDD	6Hk#:;;''+=+L+L '2n(n  rD  )D  GO  )O  P  P  P !X--%+	""#w..%0	"!9((GI,>+,M,M M9''79+=+L+L $ 	F#66vuEEGG 	K $ 7 7	 J JGH))$++gv*F*FGG&111r   r    c                 f    d|i}|                      |                     ||                    }||dS )a  
        cancels an open order
        :see: https://api.blockchain.com/v3/#/trading/deleteOrder
        :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>`
        orderId)r    r   )privateDeleteOrdersOrderIdr  r   r    r   r   r  r  s         r   cancel_orderzblockchaincom.cancel_orderC  sH     r
 224;;w3O3OPP
 
 	
r   c                     |                                   i }||                     |          }||d<   |                     |                     ||                    }||dS )a  
        cancel all open orders
        :see: https://api.blockchain.com/v3/#/trading/deleteAllOrders
        :param str symbol: unified market symbol of the market to cancel orders in, all markets are used if None, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   )r   r   )r  	market_idprivateDeleteOrdersr  )r   r   r   r  r   r  s         r   cancel_all_orderszblockchaincom.cancel_all_ordersU  sv     	
 ~~f--H (GH++DKK,H,HII
 
 	
r   c                 ,   |                                   |                     |          }|                     |d          }|                     |d          }i }t          dt	          | j                            D ]}| j        |         }||||d||<   |S )aN  
        fetch the trading fees for multiple markets
        :see: https://api.blockchain.com/v3/#/trading/getFees
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        	makerRate	takerRater   )r   r   r   r   )r  privateGetFeesr   r   r   rh   )r   r   r  makerFeetakerFeer   r   r   s           r   fetch_trading_feesz blockchaincom.fetch_trading_feesl  s     	&&v.. ##Hk::##Hk::q#dl++,, 	 	A\!_F  !!	 F6NN r   sincec                 8    d}|                      |||||          S )a;  
        fetches information on multiple canceled orders made by the user
        :see: https://api.blockchain.com/v3/#/trading/getOrders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: max number of orders to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rJ  fetch_orders_by_stater   r   r  r  r   rO  s         r   fetch_canceled_ordersz#blockchaincom.fetch_canceled_orders  s%     ))%vNNNr   c                 8    d}|                      |||||          S )a4  
        fetches information on multiple closed orders made by the user
        :see: https://api.blockchain.com/v3/#/trading/getOrders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rI  r  r  s         r   fetch_closed_ordersz!blockchaincom.fetch_closed_orders  s%     ))%vNNNr   c                 8    d}|                      |||||          S )a  
        fetch all unfilled currently open orders
        :see: https://api.blockchain.com/v3/#/trading/getOrders
        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        rG  r  r  s         r   fetch_open_orderszblockchaincom.fetch_open_orders  s%     ))%vNNNr   c                     |                                   |dd}d }| |                     |          }|d         |d<   |                     |                     ||                    }|                     ||||          S )Nd   )r   r  r    r   )r  r   privateGetOrdersr  parse_orders)	r   rO  r   r  r  r   r  r   r  s	            r   r  z#blockchaincom.fetch_orders_by_state  s     	
 
 [[((F &tGH((Wf)E)EFF  65%@@@r   c                 X   |                      |d          }|                      |d          }|                      |d                                          }|                      |d          }|                      |d          }|                      |d          }|                     |d          }	|                     |	          }
|                     ||d          }|d         }d }|                      |d	          }||d
         }||d}|                     ||	|
||d |d ||d ||d|          S )NrW  tradeIdrV  r   r   r  r'  r#  feer   )r   currency)r    r'  r(  r   rd  r   rV  takerOrMakerr   r   r   r  r   )r   lowerra  rb  safe_market
safe_trade)r   trader   r~  r  rV  r   priceStringamountStringr'  r(  r   r  feeCostStringfeeCurrencys                  r   parse_tradezblockchaincom.parse_trade  sW    ""5)44""5)44v..4466##E844&&ug66''u55%%e[99	<<	**!!(FC88!((66$ /K(kBBC"   " 
  
   	r   c                 "   |                                   i }|||d<   d}|-|                     |          |d<   |                     |          }|                     |                     ||                    }|                     |||||          S )a  
        fetch all trades made by the user
        :see: https://api.blockchain.com/v3/#/trading/getFills
        :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>`
        Nr  r   )r  r  r   privateGetFillsr  parse_trades)r   r   r  r  r   r  r   rk   s           r   fetch_my_tradeszblockchaincom.fetch_my_trades  s     	$GG $v 6 6GH[[((F%%dkk'6&B&BCC  vFFFr   codec                    |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |d          }d}d}|A|                    d          }	|                     |	d          }|                     |	d          }d|i}
|d	         |
d<   ||
d<   |||
d
<   |
S )a  
        fetch the deposit address for a currency associated with self account
        :see: https://api.blockchain.com/v3/#/payments/getDepositAddress
        :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    addressN;r   rf   r   r  tag)r  r  privatePostDepositsCurrencyr  r   split)r   r  r   r  r  r  
rawAddressr  r  addressPartsr   s              r   fetch_deposit_addressz#blockchaincom.fetch_deposit_address  s     	==&&
 33DKK4P4PQQ%%h	::
!%++C00L""<33C&&|Q77G(#%f-z#y?F5Mr   c                 @    dddddd}|                      |||          S )Nokfailedpendingrefunded)	COMPLETEDrH  PENDINGFAILEDREFUNDEDrM  rN  s      r   parse_transaction_statez%blockchaincom.parse_transaction_state  s7      "
 
 u555r   r  c                    d }d }|                      |d          }|                     |d          }|                     |d          }|                     ||          }|                     |d          }	d|v rd}|                     |d          }nd|v rd}|                     |d          }|dk    r|                      |d	          n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S )Nr   r'  r  rO  	depositIddepositwithdrawalId
withdrawalr  )r  r   r  txhashr   r    txidr(  networkaddressFrom	addressTotagFromr  tagTor   r   updated)commentinternalr  )r   ra  r   r   rb  r  )r   transactionr  r   r    r   r'  
currencyIdr  rO  feeCostr  r  r  s                 r   parse_transactionzblockchaincom.parse_transaction(  s0   4 !!+x88%%k;??	%%k:>>
&&z8<<  g66+%%D!!+{;;BB{**D!!+~>>B;?<;O;O$"";666VZ#W55C"";	::X66
K
"
 D
 	

 Y//
 t
 4
 w
 
 t
 4
 T
 D
 f
 
  d22599!
" t#
$ )
 
 
 	
r   c                     |                                   |                     |          }||d         |dd}|                     |                     ||                    }|                     ||          S )a  
        make a withdrawal
        :see: https://api.blockchain.com/v3/#/payments/createWithdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r    F)r   r  beneficiarysendMax)r  r  privatePostWithdrawalsr  r  )	r   r  r   r  r  r   r  r  r  s	            r   rZ   zblockchaincom.withdrawl  s~     	==&& "	
 
 ..t{{7F/K/KLL %%h999r   c                     |                                   i }|||d<   d}||                     |          }|                     |                     ||                    }|                     ||||          S )a  
        fetch all withdrawals made from an account
        :see: https://api.blockchain.com/v3/#/payments/getWithdrawals
        :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>`
        Nfrom)r  r  privateGetWithdrawalsr  parse_transactionsr   r  r  r  r   r  r  r  s           r   fetch_withdrawalszblockchaincom.fetch_withdrawals  s     	
 #GFO}}T**H--dkk'6.J.JKK&&x5%HHHr   c                     |                                   d|i}|                     |                     ||                    }|                     |          S )a  
        fetch data on a currency withdrawal via the withdrawal id
        :see: https://api.blockchain.com/v3/#/payments/getWithdrawalById
        :param str id: withdrawal id
        :param str code: not used by blockchaincom.fetchWithdrawal
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  )r  !privateGetWithdrawalsWithdrawalIdr  r  )r   r    r  r   r  r  s         r   fetch_withdrawalzblockchaincom.fetch_withdrawal  sY     	B
 99$++gv:V:VWW%%h///r   c                     |                                   i }|||d<   d}||                     |          }|                     |                     ||                    }|                     ||||          S )a
  
        fetch all deposits made to an account
        :see: https://api.blockchain.com/v3/#/payments/getDeposits
        :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>`
        Nr  )r  r  privateGetDepositsr  r  r  s           r   fetch_depositszblockchaincom.fetch_deposits  s     	
 #GFO}}T**H**4;;w+G+GHH&&x5%HHHr   c                     |                                   |                     |d|          }d|i}|                     |                     ||                    }|                     |          S )a  
        fetch information on a deposit
        :see: https://api.blockchain.com/v3/#/payments/getDepositById
        :param str id: deposit id
        :param str code: not used by blockchaincom fetchDeposit()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  )r  r   privateGetDepositsDepositIdr  r  )r   r    r  r   r  r  r  s          r   fetch_depositzblockchaincom.fetch_deposit  sp     	$$V["==	
 224;;w3O3OPP%%g...r   c                    |                                   |                     |dd          }|                     |d          }d|i}|                     |                     ||                    }|                     ||          }|t          | j        dz   |z   dz             d|i}t          dt          |                    D ]}||         }|                     |d          }	| 
                    |	          }
|                                 }|                     |d	          |d
<   |                     |d          |d<   |||
<   |                     |          S )ad  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://api.blockchain.com/v3/#/payments/getAccounts
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        accountprimaryNz$ fetchBalance() could not find the "z	" accountr   r   r  	availablefreebalancetotal)r  r   rs  privateGetAccountsr  r   r   r    r   r   r   r  safe_balance)r   r   accountNamer  r  balancesr   r   entryr  r  r  s               r   fetch_balancezblockchaincom.fetch_balance  se    	&&vy)DD69--{
 **4;;w+G+GHH  ??8[99*P PS^ ^al lmmm(#q#h--(( 	# 	#AQKE))%<<J**:66DllnnG"..ukBBGFO#//yAAGG"F4LL  (((r   c                     |                                   d|i}|                     |                     ||                    }|                     |          S )at  
        fetches information on an order made by the user
        :see: https://api.blockchain.com/v3/#/trading/getOrderById
        :param str symbol: not used by blockchaincom fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r~  )r  privateGetOrdersOrderIdr  rg  r  s         r   fetch_orderzblockchaincom.fetch_order  s[     	r
 //GV0L0LMM& )))r   r]   GETc                    d|                      ||          z   }| j        d         |         |z   }|                     ||                     |                    }	|dk    r|	r|d|                     |	          z   z  }na|dk    r[|                                  d| j        i}|dk    r|	r|d|                     |	          z   z  }n|                     |	          }d|d	<   ||||d
S )Nr   ra   r]   ?r^   zX-API-Tokenr  zapplication/jsonzContent-Type)urlmethodbodyheaders)implode_paramsr\   rs  extract_params	urlencodecheck_required_credentialsr!   json)
r   pathra   r  r   r  r  requestPathr  querys
             r   signzblockchaincom.sign*  s   D//f===is#k1		&$"5"5d";";<<(?? 3sT^^E2222I++---t{G % 73!6!666Cyy''*<'fdwOOOr   c
                    |d S |                      |d          }
|
 |
dk    rt          | j        dz   |z             |                      |d          }|                      |d          }|d| j        dz   |                     |          z   }|                     | j        d         ||           |                     | j        d         ||           d S )NtextzInsufficient Balance r   errorr   r   )r   r   r    r  throw_exactly_matched_exceptionr   throw_broadly_matched_exception)r   r  reasonr  r  r  r  r  requestHeadersrequestBodyr  	errorCodeerrorMessagefeedbacks                 r   handle_errorszblockchaincom.handle_errors>  s    4&11---'#(<===$$Xx88	'''::w}tyy':'::H001I9V^___001I<Yabbbtr   )N)7__name__
__module____qualname__r   r   r   r  strr   r   r  r  r!  r   r:  r=  r   r   rA  rQ  r
   rg  r   r   floatr	   r|  r   r  r  r   r  r  r  r  r  r   r  r  r  r  r   r   r  rZ   r  r  r  r  r   r  r  r  r  __classcell__)r   s   @r   r   r      s?       O O O O Ob $& z z$v, z z z zx :>b 	? 	?s 	?3 	?Y 	? 	? 	? 	? =A d d# dc d d d d& =A 	d 	d# 	dc 	d 	d 	d 	d# #6 #V # # # #J 02 3 33 3f 3 3 3 3  04B 
4 
4W 
47 
4 
4 
4 
4	6 	6 	66 6 65 6 6 6 6p gksu 22 223 22i 22y 22RW 22`c 22 22 22 22h 37r 
 
s 
C 
 
 
 
$ /32 
 
 
 
 
 
. )+  {    : 37TX\eg O OC Os ORU O O O O 154VZce O O# OS OPS Ojnotju O O O O /3TXac O O O3 Oc Ohlmrhs O O O O :>D_cln A A3 Ac AY\ A A A A+ + +5 + + + +Z -1tRV_a G Gc G GC G G G G* 79  #    :6 6 6B
 B
x B
; B
 B
 B
 B
H ?C2 : :S :% : : : :B -1tRV_a I Ic I IC Ifjkvfw I I I I. 59 0 03 0c 0 0 0 0  *.Dt\^ I I3 Ic I Icghsct I I I I. 26b / / /3 / / / /" $& )) ))( )) )) )) ))V 26b !* !*c !*3 !* !* !* !*F &eBSW P P P P(      r   r   N)"ccxt.base.exchanger   ccxt.abstract.blockchaincomr   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>r"     s   ( ' ' ' ' ' 3 3 3 3 3 3 i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i  i       * * * * * * 0 0 0 0 0 0 . . . . . . . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %y y y y yHk y y y y yr   