
    !:h                         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#y)    )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-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d/Z3i fde4fd0Z5di fdedefd1Z6d2d3i ddfd4Z7d$e8d5ed6ed7ed8ed9efd:Z9 xZ:S )<blockchaincomreturnc                 
   | j                  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 dDdEdFdFdGdHdHdGdIdJgdKdLdMdNdOdOdOdOdOdOdPidOdOdOdOdOdOdOdOdOdOdOdOdOdQdOdOdOdRdOdOdSdTdGdUdVdNdd| j	                  dW      | j	                  dX      g| j	                  dY      | j	                  dZ      g| j	                  d[      | j	                  d\      g| j	                  d]      | j	                  d\      g| j	                  d^      | j	                  d\      g| j	                  d_      | j	                  d\      g| j	                  d`      | j	                  d\      g| j	                  da      | j	                  db      g| j	                  dc      | j	                  dd      g| j	                  de      | j	                  df      g| j	                  dg      | j	                  dh      g| j	                  di      | j	                  dj      gg| j	                  dW      | j	                  dk      g| j	                  dY      | j	                  dl      g| j	                  d[      | j	                  dm      g| j	                  d]      | j	                  dh      g| j	                  d^      | j	                  dn      g| j	                  d_      | j	                  dj      g| j	                  d`      | j	                  do      g| j	                  da      | j	                  dp      g| j	                  dc      | j	                  dq      g| j	                  de      | j	                  dr      g| j	                  dg      | j	                  ds      g| j	                  di      | j	                  dW      ggdtduidvdddwdxdyi dzd{d|d}d~d~dd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dddOdd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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feesrf   get   )tickersztickers/{symbol}symbolszsymbols/{symbol}zl2/{symbol}zl3/{symbol})ri   ordersorders/{orderId}tradesfillsdepositszdeposits/{depositId}accountszaccounts/{account}/{currency}	whitelistzwhitelist/{currency}withdrawalszwithdrawals/{withdrawalId})rn   zdeposits/{currency}ru   )rn   ro   )rj   postdeleteri   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   createOrdersrL   rP   rO   fetchOrdersr;   rM   )linearinverse)r.   r0   r1   precisionMode
exceptions)401404)exactbroad)deep_extendsuperr    describeparse_numberr   r   r   )self	__class__s    L/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/blockchaincom.pyr   zblockchaincom.describe   s	   mT C E TH
/TH
dTH
 $TH
 $	TH

 TH
 tTH
 4TH
  444 $4 	4
 %4 %4 "44 t4 t4 '4 (4 "44 4 &t4 $T4  !4" &t#4$ (%4& 1%'4(  )4* &u+4, #E-4. *5/40 $U142 "5344 #D546 #D748 u94: "5;4< =4> !%?4@  A4B eC4D +EE4F "4G4H dI4J !$K4L $UM4N )%O4P tQ4R S4T uU4V "5W4X #DY4Z  [4\ !%]4^ "4_4` #Da4b +Dc4d Ee4f Dg4TH
z ${TH
| iBC
 GG 03 ?}TH
\ #$,-#$,-'('(	 !""#,-"#!"$%01$%9:%&01'(67  #$/0'( #$,-+%]TH
h $!%"& "..s3T5F5Fx5PQ!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPX>YZ" "..s3T5F5Fw5OP!..w79J9J89TU!..w79J9J89TU!..x8$:K:KH:UV!..x8$:K:KH:UV!..y94;L;LX;VW!..y94;L;LX;VW!..y94;L;LX;VW!..z:D<M<Mh<WX!..{;T=N=Nx=XY!..{;T=N=Nx=XY!..|<d>O>OPS>TU"	"$iTH
r "$sTH
z  (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(*{TH
P $&+(,,0,1).+06:#'#'"'#'	( #($)27+0/4$)#()$, %)&+!%$*%+*/& ',#(*/$)	# ',!%#($)*/( $(&+!%$*,-%+#($)*/	* #'q9v ##
 ##CQTH
X YYTH
Z .( [TH
 T T	    c                 t   | j                  |      }t        |j                               }g }t        dt	        |            D ]r  }||   }| j                  ||      }| j                  |d      }| j                  |d      }	| j                  |      }
| j                  |	      }| j                  |d      }d}| j                  |d      }|dk(  rd}nd	}| j                  |d
      }| j                  |d      }| j                  |      }t        j                  ||      }| j                  |d      }| j                  |d      }| j                  |      }t        j                  ||      }| j                  |d      }| j                  |d      }| j                  |      }t        j                  ||      }| j                  |      }d}| j                  |d      }|dk7  rK| j                  |d      }| j                  |      }t        j                  ||      }| j                  |      }nd}|j                  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| j                  |      | j                  |      d$ddd%||d%ddd%ddd%d&dd'       u |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_sizery   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,  s   > ''/(	q#i.) Y	A |H__Wh7F%%fo>F&&v/ABG**62D++G4E((6IF**68<Kf$&*&6&6v?T&U#+/+;+;FD_+`(+/+?+?@\+](#*#5#56MOk#l  ,,VZ@M!%!1!1&:J!K*.*>*>?Q*R'$+$6$6}Fa$b!!%!1!1&:J!K&*&6&6v?U&V#/3/C/CD[/\,(/(:(:;MOo(p%,,-FGLL++F4DELs"*.*:*:6CY*Z'373G3GH_3`0%,%7%7Ff%g"#001C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!../CD  $#!
  ,+
  $#
  $#$  a1 1QY	t r   Nr   r   c                 (    | j                  |||      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           	          | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||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   r/  z!blockchaincom.fetch_l3_order_book  s     	V$fTl
 $GG))$++gv*FG$$Xvh/?vvW[]bccr   c           	          | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  ||d   d dddd      S )Nr   r#   r2  r3  r4  r5  r6  )r7  r  publicGetL2Symbolr9  r:  r;  s          r   fetch_l2_order_bookz!blockchaincom.fetch_l2_order_book  s}    V$fTl
 $GG))$++gv*FG$$Xvh/?vvW[]bccr   tickerr  c                 N   | j                  |d      }| j                  ||d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  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   rA  r  r  r   rQ  rU  r   s           r   parse_tickerzblockchaincom.parse_ticker  sV    ##FH5!!(FC8(:;%%fl;
4 !
f!
!
 !
 D	!

 4!
 4!
 !
 4!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ %)!
* + 	r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      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#   )r7  r  publicGetTickersSymbolr9  rY  )r   r   r  r  r<  r=  s         r   fetch_tickerzblockchaincom.fetch_ticker  s^     	V$fTl
 ..t{{7F/KL  622r   rm   c                 h    | j                          | j                  |      }| j                  ||      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>`
        )r7  publicGetTickersparse_tickers)r   rm   r  rl   s       r   fetch_tickerszblockchaincom.fetch_tickers  s3     	''/!!'733r   c                 :    ddddddd}| j                  |||      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  s2    ""! 
 u55r   orderc                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }| j                  ||d      }	| j                  |d      }
|dk7  r| j                  |d	      nd }| j	                  |d
      }| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }| j                  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   rC  exOrdIdr  r   avgPxrG  cumQty	leavesQtyr#   clientOrderIdrH  lastTradeTimestampr   r   r   rT  r   filled	remainingr   rp   )ri   r   )r  safe_string_lowerrp  rW  r  safe_integeriso8601
safe_order)r   rq  r  r{  r   statusIdrn  rv  r  r   exchangeOrderIdr   rT  rG  rH  r}  r~  r  s                     r   parse_orderzblockchaincom.parse_order'  s   & ((	:%%eY7##E;7&&x0%%eV4##E84!!(FC8**5)<59X5E  0D""5'2%%e[9	<<	*!!%2$$UK8	 "
/"
]"
 "
 	"

 !$"
 e"
 f"
 D"
 4"
 D"
 U"
 w"
 d"
 f"
 "
  D!"
" b#"
$ '"
 * r   r   rv  r   r   c                 ,   | j                          | j                  |      }| j                  |d|      }|j                         }	| j	                  |dd| j                               }
| j                  |g d      }|	|d   |j                         | j                  ||      |
d}| j                  |g d      }| j                  |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| j                  ||      |d<   |r| j                  ||      |d<   | j                  | j                  ||            }| j                  ||      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>`
        rt  r{  rs  )rt  r{  rs  r#   )rt  r   rv  orderQtyrs  )r   stopPx	stopPriceSTOP	STOPLIMITz= createOrder() requires a stopPx or triggerPrice param for a z orderMARKETLIMITFTr   r  )r7  r  r  uppersafe_string_2uuid16omitamount_to_precisionsafe_value_nr   r#   price_to_precisionprivatePostOrdersr9  r  )r   r   r   rv  r   r   r  r  	orderTypeuppercaseOrderTyper{  r<  r   priceRequiredstopPriceRequiredr=  s                   r   create_orderzblockchaincom.create_order_  s    	V$$$VY=	&__.**6?It{{}]6#JK *TlJJL00@$

 ((1XY6#JK'+=+L#'2q(q  uG  )G  JR  )R  S  S#!X-%+	"#w.%0	"!9(GI,>+,M M9'79+=+L $#66vuEGG $ 7 7 MGH))$++gv*FG&11r   r#   c                 t    d|i}| j                  | j                  ||            }| j                  ||d      S )ay  
        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   )privateDeleteOrdersOrderIdr9  r  r   r#   r   r  r<  r=  s         r   cancel_orderzblockchaincom.cancel_order  sI     r
 224;;w3OP 
  	r   c                     | j                          i }|| j                  |      }||d<   | j                  | j                  ||            }| j	                  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>`
        r   r   )r7  	market_idprivateDeleteOrdersr9  r  )r   r   r  r<  r  r=  s         r   cancel_all_orderszblockchaincom.cancel_all_orders  st     	
 ~~f-H (GH++DKK,HI
 OO 
 	
r   c                    | j                          | j                  |      }| j                  |d      }| j                  |d      }i }t        dt	        | j
                              D ]  }| j
                  |   }||||d||<    |S )aA  
        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   )r7  privateGetFeesr  r  r  rm   )r   r  r=  makerFeetakerFeer  r  r   s           r   fetch_trading_feesz blockchaincom.fetch_trading_fees  s     	&&v. ##Hk:##Hk:q#dll+, 	A\\!_F  !!	F6N	 r   sincec                 0    d}| j                  |||||      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>`
        ri  fetch_orders_by_stater   r   r  r   r  rn  s         r   fetch_canceled_ordersz#blockchaincom.fetch_canceled_orders  s"     ))%vNNr   c                 0    d}| j                  |||||      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>`
        rh  r  r  s         r   fetch_closed_ordersz!blockchaincom.fetch_closed_orders  s"     ))%vNNr   c                 0    d}| j                  |||||      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>`
        rf  r  r  s         r   fetch_open_orderszblockchaincom.fetch_open_orders  s"     ))%vNNr   c                     | j                          |dd}d }|| j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  ||||      S )Nd   )r   r   r#   r   )r7  r  privateGetOrdersr9  parse_orders)	r   rn  r   r  r   r  r<  r  r=  s	            r   r  z#blockchaincom.fetch_orders_by_state  sx     	
 [[(F &tGH((Wf)EF  65%@@r   tradec                    | j                  |d      }| j                  |d      }| j                  |d      j                         }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |	      }
| j	                  ||d      }|d   }d }| j                  |d	      }|
|d
   }||d}| j                  ||	|
||d |d ||d ||d|      S )Nrw  tradeIdrv  r   r   r6  rG  rC  feer   )r   currency)r#   rG  rH  r   rq  r   rv  takerOrMakerr   r   r   r  r   )r  lowerr  r  safe_market
safe_trade)r   r  r  r  r  rv  r  priceStringamountStringrG  rH  r   r  feeCostStringfeeCurrencys                  r   parse_tradezblockchaincom.parse_trade!  s)    ""5)4""5)4v.446##E84&&ug6''u5%%e[9	<<	*!!(FC8!((6$ /K(kBC"   " 
  	r   c                     | j                          i }|||d<   d}|%| j                  |      |d<   | j                  |      }| j                  | j	                  ||            }| j                  |||||      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   )r7  r  r  privateGetFillsr9  parse_trades)r   r   r  r   r  r<  r  rp   s           r   fetch_my_tradeszblockchaincom.fetch_my_tradesN  s     	$GG $v 6GH[[(F%%dkk'6&BC  vFFr   codec                 D   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d      }d}d}|5|j                  d      }	| j	                  |	d      }| j	                  |	d      }||d   d||d	S )
at  
        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   rk   r  )r   r  networkr  tag)r7  r  privatePostDepositsCurrencyr9  r  split)
r   r  r  r  r<  r=  
rawAddressr  r  addressPartss
             r   fetch_deposit_addressz#blockchaincom.fetch_deposit_addresse  s     	==&
 33DKK4PQ%%h	:
!%++C0L""<3C&&|Q7G (
 	
r   c                 8    dddddd}| j                  |||      S )Nokfailedpendingrefunded)	COMPLETEDrg  PENDINGFAILEDREFUNDEDrl  rm  s      r   parse_transaction_statez%blockchaincom.parse_transaction_state  s/      "
 u55r   transactionr  c                 ^   d }d }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }	d|v rd}| j                  |d      }nd|v rd}| j                  |d      }|dk(  r| j                  |d	      nd }
d }|
||
d
}| j                  |d      }| j                  |d      }i d|d|d|d|d| j	                  |      dd dd d|d|dd dd dd d|d|d|d| j                  |	      dd d d |dS )Nr   rG  r  rn  	depositIddepositwithdrawalId
withdrawalr  )r  r   r  txhashr   r#   txidrH  r  addressFrom	addressTotagFromr  tagTor   r   updated)commentinternalr  )r  r  r  r  r  r  )r   r  r  r   r#   r   rG  
currencyIdr  rn  feeCostr  r  r  s                 r   parse_transactionzblockchaincom.parse_transaction  s   4 !!+x8%%k;?	%%k:>
&&z8<  g6+%D!!+{;B{*D!!+~>B;?<;O$"";6VZ#W5C"";	:X6
K
"
 D
 	

 Y/
 t
 4
 w
 
 t
 4
 T
 D
 f
 
  d2259!
" t#
$ )
 	
r   r  c                     | j                          | j                  |      }||d   |dd}| j                  | j                  ||            }| j	                  ||      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)r7  r  privatePostWithdrawalsr9  r  )	r   r  r   r  r  r  r  r<  r=  s	            r   r_   zblockchaincom.withdraw  sg     	==& "	
 ..t{{7F/KL %%h99r   c                     | j                          i }|||d<   d}|| j                  |      }| j                  | j                  ||            }| j	                  ||||      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)r7  r  privateGetWithdrawalsr9  parse_transactionsr   r  r  r   r  r<  r  r=  s           r   fetch_withdrawalszblockchaincom.fetch_withdrawals  ss     	
 #GFO}}T*H--dkk'6.JK&&x5%HHr   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      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  )r7  !privateGetWithdrawalsWithdrawalIdr9  r  )r   r#   r  r  r<  r=  s         r   fetch_withdrawalzblockchaincom.fetch_withdrawal  sJ     	B
 99$++gv:VW%%h//r   c                     | j                          i }|||d<   d}|| j                  |      }| j                  | j                  ||            }| j	                  ||||      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  )r7  r  privateGetDepositsr9  r  r  s           r   fetch_depositszblockchaincom.fetch_deposits!  ss     	
 #GFO}}T*H**4;;w+GH&&x5%HHr   c                     | j                          | j                  |d|      }d|i}| j                  | j                  ||            }| j	                  |      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  )r7  r  privateGetDepositsDepositIdr9  r  )r   r#   r  r  r  r<  r  s          r   fetch_depositzblockchaincom.fetch_deposit:  s^     	$$V["=	
 224;;w3OP%%g..r   c                 F   | j                          | j                  |dd      }| j                  |d      }d|i}| j                  | j	                  ||            }| j                  ||      }|t        | j                  dz   |z   dz         d|i}t        dt        |            D ]i  }||   }| j                  |d      }	| j                  |	      }
| j                         }| j                  |d      |d	<   | j                  |d
      |d<   |||
<   k | j                  |      S )aV  
        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primaryz$ fetchBalance() could not find the "z	" accountr   r   r  	availablefreebalancetotal)r7  r  r  privateGetAccountsr9  r  r   r#   r  r  r  r  safe_balance)r   r  accountNamer<  r=  balancesr  r  entryr  r  r  s               r   fetch_balancezblockchaincom.fetch_balanceM  s9    	&&vy)D69-{
 **4;;w+GH  ??8[9*P PS^ ^al lmm)q#h-( 	#AQKE))%<J**:6DllnG"..ukBGFO#//yAGG"F4L	#   ((r   c                     | j                          d|i}| j                  | j                  ||            }| j                  |      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  )r7  privateGetOrdersOrderIdr9  r  r  s         r   fetch_orderzblockchaincom.fetch_orderz  sL     	r
 //GV0LM& ))r   rb   GETc                    d| j                  ||      z   }| j                  d   |   |z   }| j                  || j                  |            }	|dk(  r|	rp|d| j	                  |	      z   z  }nX|dk(  rS| j                          d| j                  i}|dk(  r|	r.|d| j	                  |	      z   z  }n| j                  |	      }d|d	<   ||||d
S )Nr   rf   rb   ?rc   zX-API-Tokenr  zapplication/jsonzContent-Type)urlmethodbodyheaders)implode_paramsra   r  extract_params	urlencodecheck_required_credentialsr$   json)
r   pathrf   r  r  r  r  requestPathr  querys
             r   signzblockchaincom.sign  s    D//f==iis#k1		&$"5"5d";<(?sT^^E222I++-t{{G %3!666Cyy'*<'fdwOOr   reasonr  r  r  r  c
                    |y | j                  |d      }
|
 |
dk(  rt        | j                  dz   |z         | j                  |d      }| j                  |d      }|a| j                  dz   | j                  |      z   }| j	                  | j
                  d   ||       | j                  | j
                  d   ||       y )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    &1--'#(<==$$Xx8	''':ww}tyy'::H001I9V^_001I<Yabr   )N);__name__
__module____qualname__r   r   r   r
   r-  strr	   r   r0  r/  r@  dictr   rY  r\  r   r   r`  rp  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$  intr1  __classcell__)r   s   @r   r    r       s   U# Un $& |$v, || :>b ?s ?3 ?Y ? =A d# dc d* =A 	d# 	dc 	d#4 # #6 #J 02 33 3f 3$ 04B 4W 47 4	66 6v 6 6p gksu 423 42i 42y 42RW 42`c 42l 37r s C ( /32 
 
: )+ { > 37TX\eg OC Os ORU O 154VZce O# OS OPS Ojnotju O /3TXac O O3 Oc Ohlmrhs O :>D_cln A3 Ac AY\ A+ +v + +Z -1tRV_a Gc G GC G. 79 
# 
^ 
@6B
T B
X B
Q\ B
H DHPR !:S !:% !:# !:Wb !:F -1tRV_a Ic I IC Ifjkvfw I2 59 03 0c 0$ *.Dt\^ I3 Ic I Icghsct I2 26b / /3 /& $& +)( +)Z 26b $*c $*3 $*L &eBSW 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>rB     sS    ( 3 ~  ~  ~  ~  ~  * 0 . . * 4 %oHk or   