
    ei                         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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)AnyBalancesCurrencyDepositAddress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def 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d<d
ededefdZi fdedefdZdi fdedefdZd Zd<dededefdZdi fdededededef
dZdi fdedefdZd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%d<d!edede&fd"Z'dddi fdede	de	fd#Z(i fd$ede)fd%Z*d& Z+d<d'ed(e,de-fd)Z.di fd$eded*ed+ede-f
d,Z/dddi fd$ede	de	dee-         fd-Z0di fded$efd.Z1dddi fd$ede	de	dee-         fd/Z2di fded$efd0Z3i fde4fd1Z5di fdedefd2Z6d3d4i ddfd5Z7d$e8d6ed7ed8ed9ed:efd;Z9 xZ:S )=blockchaincomreturnc                    |                      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i d2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCdidDd dEdFdGdGdHdIdIdHdJdKgdLdMdNdOdPdPdPdPdPdPdQidPdPdPdPdPdPdPdPdPdPdPdPdPdRdPdPdPdSdPdPdTdUdHdVdWdOdd|                     dX          |                     dY          g|                     dZ          |                     d[          g|                     d\          |                     d]          g|                     d^          |                     d]          g|                     d_          |                     d]          g|                     d`          |                     d]          g|                     da          |                     d]          g|                     db          |                     dc          g|                     dd          |                     de          g|                     df          |                     dg          g|                     dh          |                     di          g|                     dj          |                     dk          gg|                     dX          |                     dl          g|                     dZ          |                     dm          g|                     d\          |                     dn          g|                     d^          |                     di          g|                     d_          |                     do          g|                     d`          |                     dk          g|                     da          |                     dp          g|                     db          |                     dq          g|                     dd          |                     dr          g|                     df          |                     ds          g|                     dh          |                     dt          g|                     dj          |                     dX          ggdudvidwdddxdydzi d{d|d}d~ddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddiddddd dddd dddddddddddddd dddddddddddddddddd ddddPdddddd d	d d dd d dd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fetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetwork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urlszOhttps://github.com/user-attachments/assets/975e3054-3399-4363-bcee-ec3c6d63d4e8z"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feesrg   get   )tickersztickers/{symbol}symbolszsymbols/{symbol}zl2/{symbol}zl3/{symbol})rj   ordersorders/{orderId}tradesfillsdepositszdeposits/{depositId}accountszaccounts/{account}/{currency}	whitelistzwhitelist/{currency}withdrawalszwithdrawals/{withdrawalId})ro   zdeposits/{currency}rv   )ro   rp   )rk   postdeleterj   trading0z0.004510000z0.003550000z0.0018100000500000100000025000005000000z0.001625000000z0.0014	100000000z0.0011	500000000z0.0008
1000000000z0.0006z0.004z0.0017z0.0015z0.0007z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features)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedleveragemarketBuyRequiresPricemarketBuyByCostselfTradePreventiontrailingicebergi  i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   )	sandboxr5   createOrdersrM   rQ   rP   fetchOrdersr;   rN   )linearinverse)r.   r0   r1   precisionMode
exceptions)401404)exactbroad)deep_extendsuperr    describeparse_numberr   r   r   )self	__class__s    P/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/blockchaincom.pyr   zblockchaincom.describe   s&   mT : : C C E E UH
/UH
dUH
 $UH
 $	UH

 UH
 tUH
 4UH
  555 $5 	5
 %5 %5 "45 t5 t5 '5 (5 "45 5 &t5 $T5  "5!5" #5 5$ &t%5& ('5( 1%)5*  +5, &u-5. #E/50 *5152 $U354 "5556 #D758 #D95: u;5< "5=5> ?5@ !%A5B  C5D eE5 5 5F +EG5H "4I5J dK5L !$M5N $UO5P )%Q5R tS5T U5V uW5X "5Y5Z #D[5\  ]5^ !%_5` "4a5b #Dc5d +De5f Eg5 5h Di5 5UH
| $}UH
~ iBC 
 GG  03 ? UH
^ #$,-#$,-'('( 	 !""#,-"#!"$%01$%9:%&01'(67   #$/0'(  #$,- + % %_UH
j $!%"& "..s33T5F5Fx5P5PQ!..w779J9J89T9TU!..w779J9J89T9TU!..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9J9J89T9TU!..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>OPS>T>TU" 	" "$kUH
t "$ $uUH
|  (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( (*}UH
R $&+(,,0,1).+06:#'#'"'#'	( ( #($)27+0/4$)#()$ $, %)&+!%$*%+*/& & ',#(*/$)	# # ',!%#($)*/( ( $(&+!%$*,-%+#($)*/	* 	* #'q9 9v ## 
 ## C CSUH
Z Y[UH
\ .(   ]UH
 U U U	    c                 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

        https://api.blockchain.com/v3/#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_sizerz   max_order_size_scaleinfo	numericIdsymbol/basequotesettlebaseIdquoteIdsettleIdtyper.   r/   r0   r1   r2   active)amountprice)minmax)r   r   r   cost)contractr   r   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   r   c                 0    |                      |||          S )a)  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api.blockchain.com/v3/#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_book  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

        https://api.blockchain.com/v3/#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   r0  z!blockchaincom.fetch_l3_order_book  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#   r3  r4  r5  r6  r7  )r8  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   tickerr  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   rB  r  r  r   rR  rV  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

        https://api.blockchain.com/v3/#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#   )r8  r  publicGetTickersSymbolr:  rZ  )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   rn   c                     |                                   |                     |          }|                     ||          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://api.blockchain.com/v3/#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>`
        )r8  publicGetTickersparse_tickers)r   rn   r  rm   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   orderc                    |                      |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   rD  exOrdIdr  r   avgPxrH  cumQty	leavesQtyr#   clientOrderIdrI  lastTradeTimestampr   r   r   rU  r   filled	remainingr   rq   )rj   r   )r  safe_string_lowerrq  rX  r  safe_integeriso8601
safe_order)r   rr  r  r|  r   statusIdro  rw  r  r   exchangeOrderIdr   rU  rH  rI  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   rw  r   r   c                    |                                   |                     |          }|                     |d|          }|                                }	|                     |dd|                                           }
|                     |g d          }|	|d         |                                |                     ||          |
d}|                     |g d          }|                     |g d          }|	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

        https://api.blockchain.com/v3/#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 fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        ru  r|  rt  )ru  r|  rt  r#   )ru  r   rw  orderQtyrt  )r   stopPx	stopPriceSTOP	STOPLIMITNz= createOrder() requires a stopPx or triggerPrice param for a z orderMARKETLIMITFTr   r  )r8  r  r  uppersafe_string_2uuid16omitamount_to_precisionsafe_value_nr   r#   price_to_precisionprivatePostOrdersr:  r  )r   r   r   rw  r   r   r  r  	orderTypeuppercaseOrderTyper|  r=  r   priceRequiredstopPriceRequiredr>  s                   r   create_orderzblockchaincom.create_order`  sS    	V$$$$VY==	&__..**6?It{{}}]]6#J#J#JKK *TlJJLL00@@$

 

 ((1X1X1XYY6#J#J#JKK''+=+L+L#'2q(q  uG  )G  JR  )R  S  S  S#!X--%+	""#w..%0	"!9((GI,>+,M,M M9''79+=+L+L $ 	F#66vuEEGG 	N $ 7 7 M MGH))$++gv*F*FGG&111r   r#   c                     d|i}|                      |                     ||                    }|                     ||d          S )aw  
        cancels an open order

        https://api.blockchain.com/v3/#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=  r>  s         r   cancel_orderzblockchaincom.cancel_order  sY     r
 224;;w3O3OPP 
  
   	r   c                     |                                   i }||                     |          }||d<   |                     |                     ||                    }|                     d|i          gS )a  
        cancel all open orders

        https://api.blockchain.com/v3/#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   )r8  	market_idprivateDeleteOrdersr:  r  )r   r   r  r=  r  r>  s         r   cancel_all_orderszblockchaincom.cancel_all_orders  s     	
 ~~f--H (GH++DKK,H,HII
 OO  
 	
r   c                 ,   |                                   |                     |          }|                     |d          }|                     |d          }i }t          dt	          | j                            D ]}| j        |         }||||d||<   |S )a?  
        fetch the trading fees for multiple markets

        https://api.blockchain.com/v3/#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   )r8  privateGetFeesr  r  r  rn   )r   r  r>  makerFeetakerFeer  r  r   s           r   fetch_trading_feesz blockchaincom.fetch_trading_fees  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

        https://api.blockchain.com/v3/#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 )a%  
        fetches information on multiple closed orders made by the user

        https://api.blockchain.com/v3/#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

        https://api.blockchain.com/v3/#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   )r8  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   tradec                 X   |                      |d          }|                      |d          }|                      |d                                          }|                      |d          }|                      |d          }|                      |d          }|                     |d          }	|                     |	          }
|                     ||d          }|d         }d }|                      |d	          }||d
         }||d}|                     ||	|
||d |d ||d ||d|          S )Nrx  tradeIdrw  r   r   r7  rH  rD  feer   )r   currency)r#   rH  rI  r   rr  r   rw  takerOrMakerr   r   r   r  r   )r  lowerr  r  safe_market
safe_trade)r   r  r  r  r  rw  r  priceStringamountStringrH  rI  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

        https://api.blockchain.com/v3/#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   )r8  r  r  privateGetFillsr:  parse_trades)r   r   r  r   r  r=  r  rq   s           r   fetch_my_tradeszblockchaincom.fetch_my_tradesO  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         d||d	S )
ar  
        fetch the deposit address for a currency associated with self account

        https://api.blockchain.com/v3/#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   rl   r  )r   r  networkr  tag)r8  r  privatePostDepositsCurrencyr:  r  split)
r   r  r  r  r=  r>  
rawAddressr  r  addressPartss
             r   fetch_deposit_addressz#blockchaincom.fetch_deposit_addressf  s     	==&&
 33DKK4P4PQQ%%h	::
!%++C00L""<33C&&|Q77G (
 
 	
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   transactionr  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   rH  r  ro  	depositIddepositwithdrawalId
withdrawalr  )r  r   r  txhashr   r#   txidrI  r  addressFrom	addressTotagFromr  tagTor   r   updated)commentinternalr  )r  r  r  r  r  r  )r   r  r  r   r#   r   rH  
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   r  r  c                     |                                   |                     |          }||d         |dd}|                     |                     ||                    }|                     ||          S )a  
        make a withdrawal

        https://api.blockchain.com/v3/#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)r8  r  privatePostWithdrawalsr:  r  )	r   r  r   r  r  r  r  r=  r>  s	            r   r`   zblockchaincom.withdraw  s~     	==&& "	
 
 ..t{{7F/K/KLL %%h999r   c                     |                                   i }|||d<   d}||                     |          }|                     |                     ||                    }|                     ||||          S )a  
        fetch all withdrawals made from an account

        https://api.blockchain.com/v3/#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)r8  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

        https://api.blockchain.com/v3/#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  )r8  !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

        https://api.blockchain.com/v3/#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  )r8  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

        https://api.blockchain.com/v3/#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  )r8  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 )aT  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://api.blockchain.com/v3/#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)r8  r  r  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_balanceN  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 )a  
        fetches information on an order made by the user

        https://api.blockchain.com/v3/#getorderbyid

        :param str id: the order id
        :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  )r8  privateGetOrdersOrderIdr:  r  r  s         r   fetch_orderzblockchaincom.fetch_order{  s[     	r
 //GV0L0LMM& )))r   rc   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   rg   rc   ?rd   zX-API-Tokenr  zapplication/jsonzContent-Type)urlmethodbodyheaders)implode_paramsrb   r  extract_params	urlencodecheck_required_credentialsr$   json)
r   pathrg   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   reasonr  r  r  r  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  r&  r  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);__name__
__module____qualname__r   r   r   r
   r.  strr	   r   r1  r0  rA  dictr   rZ  r]  r   r   ra  rq  r   r  r   r   floatr   r  r   r  r  r   r  r  r  r  r  r   r  r  r   r  r  r   r   r  r`   r  r  r  r  r   r  r  r%  intr2  __classcell__)r   s   @r   r    r       s       V# V V V V V Vp $& | |$v, | | | || :>b ? ?s ?3 ?Y ? ? ? ? =A d d# dc d d d d* =A 	d 	d# 	dc 	d 	d 	d 	d# #4 # #6 # # # #J 02 3 33 3f 3 3 3 3$ 04B 4 4W 47 4 4 4 4	6 	6 	66 6 6v 6 6 6 6 6p gksu 42 423 42i 42y 42RW 42`c 42 42 42 42l 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+ + +v + + + + +Z -1tRV_a G Gc G GC G G G G. 79 
 
# 
^ 
 
 
 
@6 6 6B
 B
T B
X B
Q\ B
 B
 B
 B
H KOWY !: !:S !:% !:# !:C !:^i !: !: !: !:F -1tRV_a I Ic I IC Ifjkvfw I I I I2 59 0 03 0c 0 0 0 0$ *.Dt\^ I I3 Ic I Icghsct I I I I2 26b / / /3 / / / /& $& +) +)( +) +) +) +)Z 26b $* $*c $*3 $* $* $* $*L &eBSW P P P P(# s  c TX `c        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   r   r   typingr   ccxt.base.errorsr   r   r   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>rC     s   ( ' ' ' ' ' 3 3 3 3 3 3 ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~       * * * * * * 0 0 0 0 0 0 . . . . . . . . . . . . * * * * * * 4 4 4 4 4 4 % % % % % %p p p p pHk p p p p pr   