
    !:hŉ                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlm Z  d dlm!Z! d dl"m#Z# d dl$m%Z%  G d dee      Z&y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntMarketOrder	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InvalidOrder)DuplicateOrderId)	TICK_SIZE)Precisec                       e Zd Zdef fdZi fdefdZdedefdZi fdZd Z	d	d
di fdede
de
dee   fdZdYdedefdZd
d
d
i fdede
de
fdZdYdefdZdYdefdZd
d
d
i fdede
de
fdZdYdefdZd
d
d
i fdede
de
dee   fdZdYdededefdZdedefdZi fdedefdZd Zi fd Zi fd!Z i fd"Z!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%i fdefd&Z&dYd'edefd(Z'd
i fd)e(dee)   fd*Z*d
d
d
i fdede
de
dee$   fd+Z+d
d
d
i fdede
de
dee$   fd,Z,defd-Z-dYd.edede$fd/Z.dYd0edede/fd1Z0i fdee   fd2Z1dedefd3Z2i fde3fd4Z4dedefd5Z5d
i fd)e(de6fd6Z7i fdede8fd7Z9dYd8e:dede8fd9Z;i fde<fd:Z=de<fd;Z>i fded#e"d<ed=edef
d>Z?d
i fded?e@d@eAd#e"dAe"f
dBZBdYdCededeCfdDZDdefdEZEd?efdFZFd
i fdGedefdHZGd
i fdefdIZHd
d
i fdGeded?e@d@eAd#e"dAe"fdJZId
i fdGedefdKZJd
d
d
i fdede
de
deeC   fdLZKd
d
d
i fdede
de
fdMZLd
i fded#e"dNede$fdOZMdP ZNg dQi d
d
fdRZOdePdSedTedUedVedWefdXZQ xZRS )Zcoinbaseinternationalreturnc                    | j                  t        t        |          i ddddddgddd	d
ddddd| j                  d   dddi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
d0d
d1d
d2dd3dd4dd5dd6di d7dd8dd9d
d:d
d;d
d<dd=d
d>dd?dd@ddAddBddCddDddEddFddGdi dHd
dIddJd
dKd
dLd
dMd
dNddOd
dPd
dQddRddSd
dTddUddVd
dWddXdi dYddZd
d[d
d\dd]dd^dd_dd`d
dad
dbddcd
dddded
dfddgddhd
didjdkdlidkdmidndogdpgdqdrdsd
d
d
dtduddvg dwig dxg dydzd{gd|dzgd}d~idd| j                  d      | j                  d      d
d
| 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                  d      | j                  d      g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                  d      | j                  d      ggddidt        di t        t        t        t        t        t        t        t        t        t        d
dddddddddddddqddidddddddd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 ddddddddddddddd d ddid	ddiddiddidd d ddd      S )Nidr"   namezCoinbase International	countriesUS	certifiedFproT	rateLimitd   versionv1	userAgentchromeheadersz
CB-VERSIONz
2018-05-30hasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateLimitBuyOrdercreateLimitSellOrdercreateMarketBuyOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrdercreateMarketSellOrderWithCostcreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL2OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyBuysfetchMySellsfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransfersfetchWithdrawalsreduceMarginsandboxsetLeverage	setMarginsetMarginModesetPositionModewithdrawurlszQhttps://github.com/ccxt/ccxt/assets/43336371/866ae638-6ab5-4ebf-ab2c-cdcce9545625restz*https://api.international.coinbase.com/apiz!https://api-n5e1.coinbase.com/apiz"https://international.coinbase.comz)https://docs.cloud.coinbase.com/intx/docszlhttps://help.coinbase.com/en/international-exchange/trading-deposits-withdrawals/international-exchange-fees )logoapitestwwwdocfeesreferralrequiredCredentials)apiKeysecretpasswordr   get)assetszassets/{assets}zassets/{asset}/networksinstrumentszinstruments/{instrument}zinstruments/{instrument}/quotez instruments/{instrument}/fundingz instruments/{instrument}/candles)ordersorders/{id}
portfoliosportfolios/{portfolio}zportfolios/{portfolio}/detailzportfolios/{portfolio}/summaryzportfolios/{portfolio}/balancesz'portfolios/{portfolio}/balances/{asset}z portfolios/{portfolio}/positionsz-portfolios/{portfolio}/positions/{instrument}zportfolios/fillszportfolios/{portfolio}/fills	transfersztransfers/{transfer_uuid})	r   r   zportfolios/marginzportfolios/transferztransfers/withdrawztransfers/addressz transfers/create-counterparty-idz"transfers/validate-counterparty-idztransfers/withdraw/counterpartyr   r   r   )r   postputdelete)publicprivater   tradingz0.004z0.002010000005000000z0.00351000000050000000z0.003	250000000z0.0025z0.0016z0.001z0.0008z0.0005)takermaker)r   r   	tierBased
percentagetiersprecisionMode
exceptions)
DUPLICATE_CLIENT_ORDER_IDzOrder rejectedzmarket orders must be IoCztif is requiredzInvalid replace order requestUnauthorizedzinvalid result_limitzis a required fieldz	Not Foundzip not allowed)exactbroad
timeframes
ONE_MINUTEFIVE_MINUTEFIFTEEN_MINUTETHIRTY_MINUTEONE_HOURTWO_HOURSIX_HOURONE_DAY)1m5m15m30m1h2h6h1dnfqkvdjpmethodv1PrivatePostTransfersWithdrawETHARBITRUMAVAXOPTIMISMMATICSOLBTC)ethereumarbitrum	avacchainoptimismpolygonsolanabitcoin)brokerId	portfolior   networksById)IOCFOKPOGTDGTC)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg'  )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   r   i,  )	r   rG   createOrdersrj   rn   rm   rp   rT   rk   extendsdefault)linearinverse)r   r4   r6   r7   )optionsfeatures)deep_extendsuperr"   describe
userAgentsparse_numberr   r   r   r   r   r   )self	__class__s    T/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/coinbaseinternational.pyr   zcoinbaseinternational.describe   s{	   &;T K M vP
)vP
,vP
 $vP
 	vP

 4vP
 vP
 tvP
 2vP
 lvP
  UUU $U 	U
 $U %U UU "4U tU U $UU  U 'U &tU 'U  '!U" /#U$ ,U%U& ('U( 0)U* t+U, &t-U. (/U0 '1U2 (3U4 "45U6 T7U8  9U: ;U<  =U> +E?U@ )%AUB &uCUD $UEUF 'GUH (IUJ "4KUL  MUN &tOUP #EQUR *4SUT $UUUV "5WUX *5YUZ +E[U\ #E]U^ u_U`  aUb %ecUd /eUf "5gUh iUj !%kUl tmUn oUp  qUr dsUt +EuUv "4wUx dyUz !%{U| u}U~  U@ 'AUB $UCUD !$EUF (GUH %eIUJ )%KUL tMUN OUP UQUR uSUT "5UUV #EWUX !$YUZ #D[U\ ]U^ 4_U` uaUb TcUd  eUf "5gUh DiUvP
D kH ? <? C EvP
f " $gvP
p  	   
! *4 
 %)#A$ 24qvP
Z !..w7!..w7!%"& "..s3T5F5Fw5OP!..y94;L;LW;UV!..y94;L;LX;VW!..z:D<M<Mh<WX!..z:D<M<Mg<VW!..{;T=N=Nx=XY" "..s3T5F5Fw5OP!..y94;L;LX;VW!..y94;L;LW;UV!..z:D<M<Mh<WX!..z:D<M<Mh<WX!..{;T=N=Ns=ST"[vP
N YOvP
P 1A&21='35A$4,6+5!+&9QvP
n "#'&   	ovP
D '> !& *!' *&#$!$  $&+(,,0,0).+06:#'#'"&#'#'( #($)$)+026/3#(+$. %)&+!$$(%**/& ',#($)*/	# ',!$#($)*/( $()-#a3j y
 "9 "9 	 ##ADcvP
 v v	    
methodNamec                    d }| j                  ||d      \  }}|	|dk7  r||gS | j                  | j                  d      }|	|dk7  r||gS | j                         }t	        dt        |            D ]S  }||   }| j                  |di       }| j                  |d      s.| j                  |d      }	|	| j                  d<   |	|gc S  t        | j                  dz   |z   dz         )	Nr   r   r   info
is_defaultportfolio_id z]() requires a portfolio parameter or set the default portfolio with self.options["portfolio"])
handle_option_and_paramssafe_stringr   fetch_accountsrangelen	safe_dict	safe_boolr   r%   )
r   r  paramsr   defaultPortfolioaccountsiaccountr  portfolioIds
             r  handle_portfolio_and_paramsz1coinbaseinternational.handle_portfolio_and_paramsQ  s   	 99&*kZ	6!	Rv&&++DLL+F(/?2/E$f--&&(q#h-( 	-AqkG>>'626D~~dL1"..t^D,7[)#V,,	-  #
 :  >]  !]  ^  	^r  currencyCodec                 d   d }| j                  ||d      \  }}|| j                  |       | j                  |   d   }| j                  |dd      }|I| j	                  |      rt        | j                  dz   |z   dz         | j                  |      }|d   }||gS | j                  ||      }||gS )Nnetwork_arn_idnetworksnetworkCodenetworkz5 createDepositAddress network not found for currency z# please specify networkId in paramsr%   )	r	  load_currency_networks
currenciessafe_string_2is_emptyr   r%   find_default_networknetwork_code_to_id)r   r  r  r  	networkIdr  r  defaultNetworks           r  handle_network_id_and_paramsz2coinbaseinternational.handle_network_id_and_paramsc  s    	 99&*N^_	6''5|4Z@H((	JG==*$TWW/f%fiu%u  y^  &^  _  _!%!:!:8!D*40	 6"" !33G\J	6""r  c                 h    | j                          | j                  |      }| j                  ||      S )af  
        fetch all the accounts associated with a profile

        https://docs.cloud.coinbase.com/intx/reference/getportfolios

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        )load_marketsv1PrivateGetPortfoliosparse_accountsr   r  responses      r  r  z$coinbaseinternational.fetch_accountst  s5     	..v6$ ""8V44r  c                 2    | j                  |dd      d d |dS )Nr  portfolio_uuid)r%   typecoder  )r  )r   r  s     r  parse_accountz#coinbaseinternational.parse_account  s*    " $$Wn>NO	
 	
r  r   Nr,   symbolsincer   c           	      P   | j                          d}| j                  |dd      \  }}|r| j                  d|||||d      S | j                  |      }|d   | j	                  | j
                  ||      d}|| j                  |      |d<   nt        | j                  dz         | j                  |d	      }	|	&| j                  |d	      }| j                  |	      |d
<   | j                  | j                  ||            }
| j                  |
dg       }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.cdp.coinbase.com/intx/reference/getinstrumentcandles

        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch, default 100 max 10000
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        :param int [params.until]: timestamp in ms of the latest candle to fetch
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        Frk   paginater   r%   )
instrumentgranularitystartz' fetchOHLCV() requires a since argumentuntilendaggregations)r'  r	  "fetch_paginated_call_deterministicmarketr
  r   iso8601r   r%   safe_integeromit'v1PublicGetInstrumentsInstrumentCandlesextend	safe_listparse_ohlcvs)r   r1  	timeframer2  r   r  r4  r<  requestunitlr+  candless               r  fetch_ohlcvz!coinbaseinternational.fetch_ohlcv  s8    	88zZ&::<QVX]_hjprwxxV$ ,++DOOY	R
 #||E2GG#DGG.W$WXX!!&'2YYvw/F!\\%0GEN??GU[@\] ..>2>  &)UEJJr  r<  c           	          | j                  | j                  |dd            | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr7  timeopenhighlowclosevolume)	parse8601r  safe_number)r   ohlcvr<  s      r  parse_ohlcvz!coinbaseinternational.parse_ohlcv  sy     NN4--eWfEFUF+UF+UE*UG,UH-
 	
r  c           	         |t        | j                  dz         | j                          d}| j                  |dd      \  }}d}| j                  |ddd      \  }}d}|r| j	                  d||||||      S | j                  |      }| j                  ||d	      d	z
  }	|d
   | j                  |dd|	|z        d}
|||
d<   | j                  | j                  |
|            }| j                  |dg       }| j                  ||||      S )a  
        fetches historical funding rate prices

        https://docs.cloud.coinbase.com/intx/reference/getinstrumentfunding

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: timestamp in ms of the earliest funding rate to fetch
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentFr[   r4  maxEntriesPerRequestr,   ccxtPageKey   r%   offsetresult_offset)r5  rY  result_limitresults)r   r%   r'  r	   fetch_paginated_call_incrementalr<  r>  safe_integer_2'v1PublicGetInstrumentsInstrumentFundingrA  rB  parse_funding_rate_histories)r   r1  r2  r   r  r4  rU  pageKeyr<  pagerE  r+  rawRatess                r  fetch_funding_rate_historyz0coinbaseinternational.fetch_funding_rate_history  sU    >#DGG.e$eff88AZ\fg&#'+'D'DVMfh~  AD  (E$f889RTZ\achjpry  |P  Q  QV$  !4q8 ,!00?TX[oTop
 &+GN#??GU[@\]$ >>(Ir:0065%PPr  c                 &    | j                  ||      S N)parse_funding_rate)r   r  r<  s      r  parse_funding_rate_historyz0coinbaseinternational.parse_funding_rate_history$  s    &&tV44r  c                 .   | j                  |dd      }i d|d| j                  d |      d| j                  |d      dd dd d	d d
| j                  |      d|d| j                  |d      d| j                  |      d|dd dd dd dd dd dd S )N
event_timerJ  r  r1  	markPrice
mark_price
indexPriceinterestRateestimatedSettlePrice	timestampdatetimefundingRatefunding_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r  safe_symbolrQ  rP  )r   contractr<  rt  s       r  rf  z(coinbaseinternational.parse_funding_rate'  s#    ,,X|VL
H
d&&tV4
 ))(LA
 $	

 D
 #D
 8
 
 4++HnE
  ?
 
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  c                 h   | j                          ddi}d}|| j                  |      }d}| j                  |dd      \  }}|||d<   || j                  |      |d<   |||d<   nd|d<   | j	                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      S )
a<  
        fetch the history of funding payments paid and received on self account

        https://docs.cdp.coinbase.com/intx/reference/gettransfers

        :param str [symbol]: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
        r.  FUNDINGNrY   r   	time_fromrZ  r,   r[  )r'  r<  r	  r=  v1PrivateGetTransfersrA  rB  parse_incomes)
r   r1  r2  r   r  rE  r<  r   r+  fundingss
             r  fetch_funding_historyz+coinbaseinternational.fetch_funding_historyE  s     	I
 [[(F
!::6CXZfg
F!$.GL!#'<<#6GK &+GN#&)GN#--dkk'6.JK>>(Ir:!!(FE5AAr  c           
      T   | j                  |d      }| j                  ||d d      }| j                  |d      }| j                  |      }| j                  |d      }| j	                  |      }||d   ||| j                  |      | j                  |d      | j                  |d      d dS )Nr1  r|  
created_atassettransfer_uuidamount)r  r1  r/  ro  rp  r%   r  rate)r
  safe_marketr>  rP  safe_currency_coder=  rQ  )r   incomer<  marketIdrp  ro  
currencyIdr/  s           r  parse_incomez"coinbaseinternational.parse_incomef  s    . ##FH5!!(FD*E$$V\:NN8,	%%fg6
&&z2X&"Y/""6?;&&vx8	
 		
r  r/  c                 h   | j                          ddi}d}|| j                  |      }d}| j                  |dd      \  }}|||d<   || j                  |      |d<   |||d<   nd|d<   | j	                  | j                  ||            }| j                  |d	g       }	| j                  |	|||      S )
a7  
        fetch a history of internal transfers made on an account

        https://docs.cdp.coinbase.com/intx/reference/gettransfers

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        r.  INTERNALNr~   r   r  rZ  r,   r[  )r'  currencyr	  r=  r  rA  rB  parse_transfers)
r   r/  r2  r   r  rE  r  r   r+  r   s
             r  fetch_transfersz%coinbaseinternational.fetch_transfers  s     	J
 }}T*H
!::6CSUab
F!$.GL!#'<<#6GK &+GN#&)GN#--dkk'6.JKNN8Y;	##IxFFr  transferr  c                    | j                  |d      }| j                  |      }| j                  |d      }| j                  |      }| j	                  |di       }| j                  |d      }| j	                  |di       }	| j                  |	d      }
|| j                  |d      || j                  |      || j                  |d      ||
| j                  | j                  |d            d		S )
Nr  r  from_portfolior%   to_portfolior  r  status	r  r%   ro  rp  r  r  fromAccount	toAccountr  )r>  rP  r
  r  r  r=  rQ  parse_transfer_status)r   r  r  rp  ro  r  r/  fromPorfoliofromId
toPorfoliotoIds              r  parse_transferz$coinbaseinternational.parse_transfer  s    . $$X|<NN8,	%%h8
&&z2~~h0@"E!!,5^^HnbA

D1""8_="Y/&&x:!001A1A(H1UV

 
	
r  r  c                 6    ddddd}| j                  |||      S )Nfailedokpending)FAILED	PROCESSEDNEWSTARTEDr
  r   r  statusess      r  r  z+coinbaseinternational.parse_transfer_status  s,     	
 &&99r  c                    | j                          d}| j                  |ddd      \  }}d}| j                  d|      \  }}d|i}|dk(  r6| j                  |      }|d   |d<   d}| j	                  |d|      \  }}||d<    t        | |      | j                  ||            }| j                  |d	      }	| j                  |d
d      }
||	|
d|dS )a  
        create a currency deposit address

        https://docs.cloud.coinbase.com/intx/reference/createaddress
        https://docs.cloud.coinbase.com/intx/reference/createcounterpartyid

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network_arn_id]: Identifies the blockchain network(e.g., networks/ethereum-mainnet/assets/313ef8a9-ae5a-5f2f-8a56-572c0e2a4d5a) if not provided will pick default
        :param str [params.network]: unified network code to identify the blockchain network
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr?   r   v1PrivatePostTransfersAddressr   r%   r  r  destination_tagaddresscounterparty_id)r  tagr  r  r  )	r'  r	  r  r  r%  getattrrA  r
  r  )r   r/  r  r   r   rE  r  r#  r+  r  r  s              r  create_deposit_addressz,coinbaseinternational.create_deposit_address  s    	66v?UW_  bA  B	 <<=SU[\	6
 44}}T*H'~GGI $ A A$H^`f gIv(1G$%(74(Wf)EF x):;$$Xy:KL
 	
r  c                     | j                  |      }t        dt        |            D ](  }||   d   }| j                  |dd      }|du s#||   c S  |d   S )Nr   r  r  FT)to_arrayr  r  r  )r   r  networksArrayr  r  r  s         r  r!  z*coinbaseinternational.find_default_network  sl    h/q#m,- 	(A #F+DlEBJT!$Q''		(
 Qr  c                     | j                  |      }| j                  |d      }|yd|d   i}| j                  |      }| j                  |      |d<   y)Nr  Fr  r%   T)r  r  v1PublicGetAssetsAssetNetworksparse_networks)r   r/  r  r  r  rE  rawNetworkss          r  r  z,coinbaseinternational.load_currency_networks  se    ==&>>(J7Xd^
 99'B&  $22;?r  c                     i }t        dt        |            D ].  }| j                  | j                  ||         |      }|||d   <   0 |S )Nr   r  )r  r  rA  parse_network)r   r  r  resultr  r  s         r  r  z$coinbaseinternational.parse_networks=  sV    q#h-( 	1Akk$"4"4Xa["A6JG)0F79%&	1 r  c                 `   | j                  |d      }| j                  |      }| j                  |d      }| j                  |g dd      }| j                  ||| j                  |d      | j	                  ||      d d d d d | j                  |d      | j                  |d      dd d dd	d

      S )N
asset_namer  )network_namedisplay_namer  r   r  min_withdrawal_amtmax_withdrawal_amtminmaxr   deposit)
r  r%   r&   r  activer  r   	precisionfeelimits)r
  r  safe_string_nsafe_networknetwork_id_to_coderQ  )r   r  r  r  r  r#  networkIdForCodes          r  r  z#coinbaseinternational.parse_networkD  s      %%g|<
..z:$$W.>?	--g7ikmn  $$Wn=../?N  ++G5IJ++G5IJ
  	"
  	r  r  c                     d}| j                  d|      \  }}|t        | j                  dz         ||d}| j                  | j	                  ||            S )a  
        Either adds or reduces margin in order to set the margin to a specific value

        https://docs.cloud.coinbase.com/intx/reference/setportfoliomarginoverride

        :param str symbol: unified market symbol of the market to set margin in
        :param float amount: the amount to set the margin to
        :param dict [params]: parameters specific to the exchange API endpoint
        :returns dict: A `margin structure <https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure>`
        Nr   z9 setMargin() only allows setting margin to full portfolio)r   margin_override)r  r   r%   v1PrivatePostPortfoliosMarginrA  )r   r1  r  r  r   rE  s         r  
set_marginz coinbaseinternational.set_marginn  sf     	 <<[&Q	6TWW'bbcc"%
 11$++gv2NOOr  c           	         | j                          d}| j                  |dd      \  }}d}| j                  |ddd      \  }}d}|r| j                  d||||||      S | j                  ||d      dz
  }d| j	                  |d	d||z        i}	|| j                  |      |	d
<   |t        |d      }
|
|	d<   d}| j                  |dd      \  }}|||	d<   d}| j                  |dd      \  }}|| j                  |      |	d<   | j                  | j                  |	|            }| j                  |dg       }| j                  |      S )a  
        fetch history of deposits and withdrawals

        https://docs.cloud.coinbase.com/intx/reference/gettransfers

        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.portfolios]: Identifies the portfolios by UUID(e.g., 892e8c7c-e979-4cad-b61b-55a197932cf1) or portfolio ID(e.g., 5189861793641175). Can provide single or multiple portfolios to filter by or fetches transfers for all portfolios if none are provided.
        :param int [params.until]: Only find transfers updated before self time. Use timestamp format
        :param str [params.status]: The current status of transfer. Possible values: [PROCESSED, NEW, FAILED, STARTED]
        :param str [params.type]: The type of transfer Possible values: [DEPOSIT, WITHDRAW, REBATE, STIPEND, INTERNAL, FUNDING]
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        NfetchDepositsWithdrawalsr4  rU  r,   rV  rW  rY  rX  r  rZ  r   r8  time_tor[  )r'  r	  r\  r>  r]  r=  r  r  rA  rB  parse_transactions)r   r/  r2  r   r  r4  rU  r`  ra  rE  newLimitr   r8  r+  rawTransactionss                  r  fetch_deposits_withdrawalsz0coinbaseinternational.fetch_deposits_withdrawals  s   " 	88A[]gh&#'+'D'DVMgi  BE  (F$f889SUY[`bgioqx  {O  P  P  !4q8T00?TX[oTop
 #'<<#6GK 5#H&.GN#
!::6C]_kl
F!$.GL!55f>XZabv!%e!4GI--dkk'6.JK6 ..9bA&&77r  c                     | j                          | j                  |      }d}| j                  d|      \  }}|| j                  |      d}| j	                  | j                  ||            }| j                  |      S )a  

        https://docs.cloud.coinbase.com/intx/reference/getportfolioposition

        fetch data on an open position
        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nrq   )r   r5  )r'  r1  r  	market_id2v1PrivateGetPortfoliosPortfolioPositionsInstrumentrA  parse_position)r   r1  r  r   rE  positions         r  fetch_positionz$coinbaseinternational.fetch_position  s     	V$	 <<_fU	6"..0
 JJ4;;W^`fKgh  ""8,,r  r  c           
      .   | j                  |d      }| j                  |d      }| j                  ||d      }d}t        j                  |d      rd}t        j                  d|      }| j                  i d|d	| j                  |d	      d|d   d
d d| j                  |d      dd dd d| j                  |d      d|d| j                  |      d| j                  |d      dd dd dd dd dd d| j                  |d      d d d d d d d      S )Nr1  net_size-longr   shortz-1r  r%   
entryPricerj  rk  notional
collateralunrealizedPnlunrealized_pnlside	contractscontractSizero  rp  r   maintenanceMarginmaintenanceMarginPercentageinitialMarginim_contribution)initialMarginPercentager   liquidationPricemarginRatior   r   )r
  r  r    	string_le
string_mulsafe_positionrQ  r   )r   r  r<  r  quantityr  s         r  r  z$coinbaseinternational.parse_position  s     ##Hh7##Hj9!!(FC8Xs+D))$9H!! #
H#
$""8T2#
 fX&#
 $	#

 ))(LA#
 #
 $#
 T--h8HI#
 D#
 **84#
 D,,V^D#
 #
 #
 d#
  #
  *4!#
" T--h8IJ##
$ (, $/#
  	r  symbolsc                 ,   | j                          d}| j                  d|      \  }}d|i}| j                  | j                  ||            }| j	                  |      }| j                  |      r|S | j                  |      }| j                  |d|d      S )av  

        https://docs.cloud.coinbase.com/intx/reference/getportfoliopositions

        fetch all open positions
        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
        Nrt   r   r1  F)r'  r  (v1PrivateGetPortfoliosPortfolioPositionsrA  parse_positionsr   market_symbolsfilter_by_array_positions)r   r  r  r   rE  r+  	positionss          r  fetch_positionsz%coinbaseinternational.fetch_positions   s     		 <<=MvV	6
 @@WV\A]^$ ((2	==!%%g.--i7ERRr  c                 T    | j                          d|d<   | j                  ||||      S )a{  
        fetch all withdrawals made from an account

        https://docs.cloud.coinbase.com/intx/reference/gettransfers

        :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
        :param str [params.portfolios]: Identifies the portfolios by UUID(e.g., 892e8c7c-e979-4cad-b61b-55a197932cf1) or portfolio ID(e.g., 5189861793641175). Can provide single or multiple portfolios to filter by or fetches transfers for all portfolios if none are provided.
        :param int [params.until]: Only find transfers updated before self time. Use timestamp format
        :param str [params.status]: The current status of transfer. Possible values: [PROCESSED, NEW, FAILED, STARTED]
        :param str [params.type]: The type of transfer Possible values: [DEPOSIT, WITHDRAW, REBATE, STIPEND, INTERNAL, FUNDING]
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        WITHDRAWr.  r'  r  r   r/  r2  r   r  s        r  fetch_withdrawalsz'coinbaseinternational.fetch_withdrawalsH  s0    " 	#v..tUE6JJr  c                 T    | j                          d|d<   | j                  ||||      S )a*  
        fetch all deposits made to an account
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.portfolios]: Identifies the portfolios by UUID(e.g., 892e8c7c-e979-4cad-b61b-55a197932cf1) or portfolio ID(e.g., 5189861793641175). Can provide single or multiple portfolios to filter by or fetches transfers for all portfolios if none are provided.
        :param int [params.until]: Only find transfers updated before self time. Use timestamp format
        :param str [params.status]: The current status of transfer. Possible values: [PROCESSED, NEW, FAILED, STARTED]
        :param str [params.type]: The type of transfer Possible values: [DEPOSIT, WITHDRAW, REBATE, STIPEND, INTERNAL, FUNDING]
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        DEPOSITr.  r  r  s        r  fetch_depositsz$coinbaseinternational.fetch_deposits]  s0     	"v..tUE6JJr  c                 6    ddddd}| j                  |||      S )Nr  r  canceled)r  r  r  r  r  r  s      r  parse_transaction_statusz.coinbaseinternational.parse_transaction_statuso  s,      	
 &&99r  transactionc           
         | j                  |d      }| j                  |di       }| j                  |dd| j                  |g d      dg      }| j                  |di       }| j                  |dd| j                  |g d      d	g      }i d
|d| j                  |d      d| j                  |d      d| j                  |      d|d| j	                  | j                  |d            dd d|d|dd dd dd d| j                  |d      d| j                  |d      d| j                  | j                  |d      |      d| j                  | j                  |d            d| j                  |      d d d d!iS )"N
updated_atr  from_addressfrom_cb_account)r%   uuidr&   from_counterparty_id
to_addressto_cb_accountto_counterparty_idr  r%   r  txidtransaction_uuidro  rp  r  r  r  	addressToaddressFromr  tagTotagFromr.  resourcer  r  r  r  updatedr  costr  )r
  r  r  rP  r  rQ  r  r  )r   r  r  rp  r  r  r  r  s           r  parse_transactionz'coinbaseinternational.parse_transactionx  s3    ##K>~~k3CRH((~GXZ^ZlZlmy  |R  [S  Uk  7l  m^^K1A2F
&&{\?TXTfTfgq  tJ  UK  Ma  5b  c	
K
$"";@
 D$$[2DE
 1	

 
 t..t/?/?^/\]
 t
 
 ;
 4
 T
 t
 D$$[*=
 d&&{H=
 //0@0@g0VX`a
  d33D4D4D[RZ4[\!
" t~~h/#
$  %
 	
r  tradec                    | j                  |d      }| j                  |d      }| j                  || j                  |dd      | j                  |d      | j                  |      || j	                  ||      d | j                  |d      d | j                  |d      | j                  |d      d | j                  |d	      | j                  | j                  |d
            dd      S )Nr1  ri  fill_idexec_idorder_idr  
fill_pricefill_qtyr  	fee_assetr!  )r  r%   orderro  rp  r1  r.  r  takerOrMakerpricer  r"  r  )r
  
safe_trader  rP  r{  safe_string_lowerrQ  r  )r   r$  r<  r  rp  s        r  parse_tradez!coinbaseinternational.parse_trade  s    B ##E84##E<8$$UIyA%%eZ81 &&x8**5&9 %%e\:&&uj9((6 33D4D4DUK4XY 
  	r  c                 F    | j                  |      }| j                  |      S )a,  

        https://docs.cloud.coinbase.com/intx/reference/getinstruments

        retrieves data on all markets for coinbaseinternational
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        )v1PublicGetInstrumentsparse_marketsr*  s      r  fetch_marketsz#coinbaseinternational.fetch_markets  s(     ..v6d !!(++r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|dk(  }| j                  }|dz   |z   }d }	|s
|}	|d|z   z  }i d|d	|j                         d|d
|d|d|	r|	nd d|d|d|	r|	nd d|rdndd|ddd| ddddd| j                  |d      dk(  d| |rd n|	|k(  |rd n|	|k7  |d   d   |d   d   |rd ndd d d d | j                  |d      | j                  |d      | j                  |d      d d | j                  |d!      d"d |rd n| j                  |d#      d"d d d"| j                  |d$      d d"d%|d d&S )'Nr1  base_asset_namequote_asset_namer.  SPOT/:r%   lowercaseIdbasequotesettlebaseIdquoteIdsettleIdr4   r6   r5   Fr7   r8   r  trading_stateTRADINGr|  r   r   r   rW  base_incrementquote_increment)r  r.  r"  base_imfr  position_limit_qtymin_notional_value)r   r  r.  r"  )r   r   r   r   r  expiryexpiryDatetimestrike
optionTyper  r  r  created)r
  r   lowerrQ  )
r   r<  r  r@  rA  typeIdisSpotr   r1  rB  s
             r  parse_marketz"coinbaseinternational.parse_market  sw   ^ ##FH5!!&*;<""6+=>!!&&1F"yy#'HcGm#F4
(4
8>>+4
 f4
 F	4

 W4
 (h4
 f4
 w4
 H$4
 fF&4
 F4
 e4
 J4
 e4
 e4
  d&&v?9L!4
" F
#4
$ %d8w+>%tH,?)_W-)_W-$*D"**63CD))&2CD((1BC  ++FJ?
  #)4t/?/?H\/]
  
  ++F4HI$ g4
 4	
r  c                 F    | j                  |      }| j                  |      S )a  
        fetches all available currencies on an exchange

        https://docs.cloud.coinbase.com/intx/reference/getassets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        )v1PublicGetAssetsparse_currencies)r   r  r  s      r  fetch_currenciesz&coinbaseinternational.fetch_currencies~  s'     ++F3
 $$Z00r  c                     | j                  |d      }| j                  |      }| j                  |d      }| j                  |||d ||dk(  d d d d d | j                  d      S )Nr  r  ACTIVE)r%   r&   r/  r  r  r  r  r   r  r  r   r  )r
  r  safe_currency_structurer  )r   r  r%   r/  statusIds        r  parse_currencyz$coinbaseinternational.parse_currency  s}     h5&&r*##Hh7++8+kk-
  	r  c                    | j                          | j                  |      }| j                  |      }i }t        dt	        |            D ]a  }||   }| j                  |d      }| j                  |      }| j                  |di       }	| j                  |	| j                  |            ||<   c | j                  |d|d      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.cloud.coinbase.com/intx/reference/getinstruments

        :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   r1  r>  T)r'  r   r3  r  r  r
  r{  r  parse_tickerr  filter_by_array)
r   r  r  r   tickersr  r5  r  r1  r>  s
             r  fetch_tickersz#coinbaseinternational.fetch_tickers  s     	%%g.11&9q#k*+ 	SA$QJ''
H=H%%h/FNN:w;E"//t7G7G7QRGFO	S ##GXwEEr  c                     | j                          | j                  |      }d| j                  |      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://docs.cloud.coinbase.com/intx/reference/getinstrumentquote

        :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>`
        r5  )r'  r<  r  %v1PublicGetInstrumentsInstrumentQuoterA  r]  )r   r1  r  r<  rE  tickers         r  fetch_tickerz"coinbaseinternational.fetch_ticker  sd     	V$$..0
 ;;DKKQW<XY  00r  rc  c                    | j                  |d      }| j                  i d|d| j                  d |      d| j                  |      d|d| j	                  |d      d| j	                  |d      d	| j	                  |d
      d| j	                  |d      dd dd dd dd dd dd dd dd dd d d d | j	                  |d      | j	                  |d      d      S )Nro  r  r1  rp  bidbest_bid_price	bidVolumebest_bid_sizeaskbest_ask_price	askVolumebest_ask_sizerL  rM  rK  rN  lastchanger   averagevwaprk  index_price)
baseVolumequoteVolumepreviousCloserj  rl  )r
  safe_tickerr{  rP  rQ  )r   rc  r<  rp  s       r  r]  z"coinbaseinternational.parse_ticker  sr   $ ##FK8 !
F!
d&&tV4!
 1!
 	!

 4##F,<=!
 ))&/B!
 4##F,<=!
 ))&/B!
 D!
 4!
 D!
 T!
 D!
 d!
 $!
  t!!
" D#!
$ !))&,?**6=A-!
  	r  c                     | j                          d}| j                  d|      \  }}d|i}| j                  | j                  ||            }| j	                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://docs.cloud.coinbase.com/intx/reference/getportfoliobalances

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.v3]: default False, set True to use v3 api endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        NrO   r   )r'  r  'v1PrivateGetPortfoliosPortfolioBalancesrA  parse_balance)r   r  r   rE  balancess        r  fetch_balancez#coinbaseinternational.fetch_balance  si     		 <<^VT	6
 ??GU[@\]$ !!(++r  c                 .   d|i}t        dt        |            D ]i  }||   }| j                  |d      }| j                  |      }| j	                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S )Nr  r   r  r  totalholdused)r  r  r
  r  r  safe_balance)r   r+  r  r  
rawBalancer  r/  r  s           r  ry  z#coinbaseinternational.parse_balance,  s    " H
 q#h-( 	#A!!J))*lCJ**:6DllnG#//
JGGG"..z6BGFO"F4L	#   ((r  r  r  c           
          | j                          | j                  |      }|d   |||d}| j                  | j                  ||            }| j	                  |d      }	|ddd|||||	rdd	S dd	S )a0  
        Transfer an amount of asset from one portfolio to another.

        https://docs.cloud.coinbase.com/intx/reference/createportfolioassettransfer

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure>`
        r%   )r  ammountfromtosuccessNr  r  r  )r'  r  v1PrivatePostPortfoliosTransferrA  r  )
r   r/  r  r  r  r  r  rE  r+  r  s
             r  r  zcoinbaseinternational.transferI  s     	==&d^	
 77GV8TU..95&"%d

 
	
 ,4

 
	
r  r.  r  r.  c                 N   | j                          | j                  |      }|j                         }| j                  |g d      }	| j	                  | j
                  dd      }
|
dz   | j                         z   }|dd }||j                         |d   | j                  |d   |      d	}|	|dk(  rd}nd}|	|d<   ||d<   |dk(  r|t        | j                  dz         ||d<   d
}| j                  d|      \  }}|||d<   | j                  |dd      }| j                  |dd      }|dk(  r"||dk7  rt        | j                  dz         d}n|dn|}|||d<   ||d<   | j                  |g d      }| j                  | j                  ||            }| j!                  ||      S )a  
        create a trade order

        https://docs.cloud.coinbase.com/intx/reference/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 you want to trade in units of the base currency, quote currency for 'market' 'buy' orders
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.stopPrice]: alias for triggerPrice
        :param float [params.triggerPrice]: price to trigger stop orders
        :param float [params.stopLossPrice]: price to trigger stop-loss orders
        :param bool [params.postOnly]: True or False
        :param str [params.tif]: 'GTC', 'IOC', 'GTD' default is 'GTC' for limit orders and 'IOC' for market orders
        :param str [params.expire_time]: The expiration time required for orders with the time in force set to GTT. Must not go beyond 30 days of the current time. Uses ISO-8601 format(e.g., 2023-03-16T23:59:53Z)
        :param str [params.stp_mode]: Possible values: [NONE, AGGRESSING, BOTH] Specifies the behavior for self match handling. None disables the functionality, new cancels the newest order, and both cancels both orders.
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        )r   	stopPrice
stop_pricer   r   r  r      r%   r1  )client_order_idr  r5  sizeNr   
STOP_LIMITSTOPr  r.  zA createOrder() requires a price parameter for a limit order typesr.  rG   r   postOnly	post_onlytifr   MARKETr   z7 createOrder() market orders must have tif set to "IOC"r   )r  userr  r   )r'  r<  uppersafe_number_nr
  r   r  amount_to_precisionr   r%   r  safe_bool_2r  r?  v1PrivatePostOrdersrA  parse_order)r   r1  r.  r  r  r.  r  r<  rP  r   clientOrderIdprefixclientOrderIdrE  r   r  r  r+  s                    r  create_orderz"coinbaseinternational.create_orderl  s   * 	V$))&2]^"..t||ZT+c1DIIK?%a+,JJL ,,,VH-=vF	
 #w%$0GL! 7?}"477-p#pqq$GG	 <<]FS	6 #,GK ##FJD  >X3%<"477-f#fggCK%cC#+GK 6#YZ++DKK,HI0 &11r  r,  c           
         | j                  |d      }| j                  |d      }d }|d|i}| j                  |dd      }| j                  i d|d| j                  |d      d	| j                  |d
      d| j	                  |      d|dd d| j                  ||      d| j                  | j                  |d            d| j                  |d      dd d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd | j                  |d      | j                  | j                  |d            |d d|      S )Nr1  r  r"  submit_timeri  r  r%   r(  r  r  ro  rp  lastTradeTimestampr.  r   r  r  r  r.  r   r  r  r  filledexec_qty	remaining
leaves_qty	avg_priceorder_status)rp  r  r  trades)	r
  rQ  r  
safe_orderrP  r{  parse_order_typer0  parse_order_status)r   r,  r<  r  feeCostr  rp  s          r  r  z!coinbaseinternational.parse_order  s   0 ##E84""5%0C %%e]LI  
E 
$""5*5 
 T--e5FG 
 1	 

  
 !$ 
 d&&x8 
 D))$*:*:5&*IJ 
 4++E59 
  
 D**5&9 
 T%%eW5 
 D,,ULA 
 d&&uf5 
 d&&uj9 
  ))%>! 
" D# 
$ ''{;--d.>.>un.UV+ 
, - 	r  c                 B    ddddddddddd
}| j                  |||      S )NrK  closedr  rejectedexpired)
r  PARTIAL_FILLEDFILLEDCANCELEDREPLACEDPENDING_CANCELREJECTEDPENDING_NEWEXPIREDPENDING_REPLACEr  r  s      r  r  z(coinbaseinternational.parse_order_status  s>    $""$"! %
 &&99r  c                 B    |dk(  ry ddddd}| j                  |||      S )NUNKNOWN_ORDER_TYPEr<  r   )r  LIMITr  r  r  )r   r.  typess      r  r  z&coinbaseinternational.parse_order_type  s8    ''!	
 tT22r  r%   c                     | j                          d}| j                  d|      \  }}||d}d}|| j                  |      }| j                  | j	                  ||            }| j                  ||      S )a  
        cancels an open order

        https://docs.cloud.coinbase.com/intx/reference/cancelorder

        :param str id: order id
        :param str symbol: not used by coinbaseinternational cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr;   )r   r%   )r'  r  r<  v1PrivateDeleteOrdersIdrA  r  )r   r%   r1  r  r   rE  r<  r   s           r  cancel_orderz"coinbaseinternational.cancel_order  s     		 <<]FS	6"
 [[(F--dkk'6.JK0 //r  c                     | j                          d}| j                  d|      \  }}d|i}d}|r| j                  |      }|d   |d<   | j                  | j	                  ||            }| j                  ||      S )ab  
        cancel all open orders
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not 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>`
        Nr:   r   r%   r5  )r'  r  r<  v1PrivateDeleteOrdersrA  parse_orders)r   r1  r  r   rE  r<  r   s          r  cancel_all_ordersz'coinbaseinternational.cancel_all_ordersE  s     		 <<=NPVW	6
 [[(F$*4LGL!++DKK,HI  00r  c                    | j                          | j                  |      }d|i}	d}
| j                  d|      \  }
}|
|
|	d<   || j                  ||      |	d<   || j	                  ||      |	d<   | j                  |g d      }|||	d<   | j                  |d	d
      }|t        | j                  dz         ||	d	<   | j                  | j                  |	|            }| j                  ||      S )a  
        edit a trade order

        https://docs.cloud.coinbase.com/intx/reference/modifyorder

        :param str id: cancel order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str params['clientOrderId']: client order id
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r%   NrM   r   r  r.  )r  r  r   r  r  r  z/ editOrder() requires a clientOrderId parameter)r'  r<  r  r  price_to_precisionr  r  r   r%   v1PrivatePutOrdersIdrA  r  )r   r%   r1  r.  r  r  r.  r  r<  rE  r   r   r  r,  s                 r  
edit_orderz coinbaseinternational.edit_orderY  s     	V$"
 	 <<[&Q	6 #,GK "66vvFGFO#66vuEGG))&2]^#$0GL!**63DoV TWW'XXYY%2!"))$++gv*FGv..r  c                     | j                          d}|| j                  |      }d}| j                  d|      \  }}||d}| j                  | j	                  ||            }| j                  ||      S )a  
        fetches information on an order made by the user

        https://docs.cloud.coinbase.com/intx/reference/modifyorder

        :param str id: the order id
        :param str symbol: unified market symbol that 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>`
        Nrn   )r%   r   )r'  r<  r  v1PrivateGetOrdersIdrA  r  )r   r%   r1  r  r<  r   rE  r,  s           r  fetch_orderz!coinbaseinternational.fetch_order  s     	[[(F	 <<\6R	6"
 ))$++gv*FG4 v..r  c           	         | j                          d}| j                  d|      \  }}d}| j                  |dd      \  }}d}| j                  |ddd      \  }}d}|r| j                  d||||||      S | j	                  ||d      dz
  }	|| j                  |d	d
|	|z        d}
d}|r| j                  |      }||
d<   |"|dkD  rt        | j                  dz         ||
d<   || j                  |      |
d<   | j                  | j                  |
|            }| j                  |dg       }| j                  ||||      S )a  
        fetches information on all currently open orders

        https://docs.cloud.coinbase.com/intx/reference/getorders

        :param str symbol: unified market symbol of the orders
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of open order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :param int [params.offset]: offset
        :param str [params.event_type]: The most recent type of event that happened to the order. Allowed values: NEW, TRADE, REPLACED
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nrm   Fr4  rU  r,   rV  rW  rX  rY  )r   rY  r5  z' fetchOpenOrders() maximum limit is 100rZ  ref_datetimer[  )r'  r  r	  r\  r>  r]  r<  r   r%   r=  v1PrivateGetOrdersrA  rB  r  )r   r1  r2  r   r  r   r4  rU  r`  ra  rE  r<  r+  	rawOrderss                 r  fetch_open_ordersz'coinbaseinternational.fetch_open_orders  s    		 <<=NPVW	688ART^_&#'+'D'DVM^`vx{'|$f889JFTY[`bhjq  tH  I  I  !4q8"!00?TX[oTop
 [[(F$*GL!s{ +T!TUU&+GN#&*ll5&9GN#**4;;w+GHF NN8Y;	  FE5AAr  c           	         | j                          d}| j                  |dd      \  }}d}d}| j                  |ddd      \  }}|r| j                  d||||||      S d}|| j                  |      }| j	                  ||d      dz
  }	d	| j                  |d
d	|	|z        i}
|"|dkD  rt        | j                  dz         ||
d<   || j                  |      |
d<   | j                  |dg      }|'| j                  |dg      }| j                  |      |
d<   | j                  | j                  |
|            }| j                  |dg       }| j                  ||||      S )aZ  
        fetch all trades made by the user

        https://docs.cloud.coinbase.com/intx/reference/getmultiportfoliofills

        :param str symbol: unified market symbol of the trades
        :param int [since]: timestamp in ms of the earliest order, default is None
        :param int [limit]: the maximum number of trade structures to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch trades for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Frj   r4  rV  NrU  r,   rW  rY  rX  z^ fetchMyTrades() maximum limit is 100. Consider setting paginate to True to fetch more trades.rZ  r  r8  r  r[  )r'  r	  r\  r<  r>  r]  r   r%   r=  r  r?  v1PrivateGetPortfoliosFillsrA  rB  parse_trades)r   r1  r2  r   r  r4  r`  rU  r<  ra  rE  r8  r+  r  s                 r  fetch_my_tradesz%coinbaseinternational.fetch_my_trades  s    	88R\]&#'+'D'DV_^tvy'z$f88&RWY^`fho  rF  G  G[[(F  !4q8T00?TX[oTop
 s{   ,L  "L  M  M&+GN##'<<#6GK ""6G95YYvy1F&*ll5&9GN#33DKK4PQR )R8  >>r  r  c           	         | j                  ||      \  }}| j                  |       | j                          | j                  |      }d}| j	                  d|      \  }}d}| j                  |ddd      \  }}d}	| j                  |d|      \  }	}|d|d   |||d   |	| j                         d}
 t        | |      | j                  |
|            }| j                  ||      S )a  
        make a withdrawal

        https://docs.cloud.coinbase.com/intx/reference/withdraw
        https://docs.cloud.coinbase.com/intx/reference/counterpartywithdraw

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str [tag]: an optional tag for the withdrawal
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.add_network_fee_to_total]: if True, deducts network fee from the portfolio, otherwise deduct fee from the withdrawal
        :param str [params.network_arn_id]: Identifies the blockchain network(e.g., networks/ethereum-mainnet/assets/313ef8a9-ae5a-5f2f-8a56-572c0e2a4d5a)
        :param str [params.nonce]: a unique integer representing the withdrawal request
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   r   r   sendr%   )r   r.  r  r  r  r  r  nonce)handle_withdraw_tag_and_paramscheck_addressr'  r  r  r	  r%  r  r  rA  r#  )r   r/  r  r  r  r  r  r   r   r#  rE  r+  s               r  r   zcoinbaseinternational.withdrawR  s    " 99#vFV7#==&	 <<ZP	666vz8Uuv	 ==dJPVW	6"d^ 'ZZ\	
 )74(Wf)EF %%h99r  c                 f   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }|||dkD  }|||dkD  }| j                  |d      }	|xr |}
|d   |	| j                  |d      | j                  |d	      | j                  |d
|
      ||| j                  |d      | j                  |d      | j                  |d      |d| j                  |d      |ddd
S )Nr   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  rQ  r
  )r   r  withdrawEnableddepositEnabledr  r   withdrawMaxr  
depositMaxr#  	isEnableds              r  r  z"coinbaseinternational.safe_network  s]   ..*=;2>>&*5&&x7..3%%gu5
"{'>*QO!j&<(1nN$$Wd3	$7	FO$$Wf5'';nnWh	B%'##GU3))';?  ++He<&
  ++GU;%	
 	
r  GETc                    |d   }|d   dk(  }d|z   dz   | j                  ||      z   }	| j                  || j                  |            }
d|	z   }|dk(  s|dk(  r|
r|	d| j                  |
      z   z  }	| j                  d	   d
   |	z   }|r| j                          t        | j                               }d}|dk7  r|
r| j                  |
      }|}||z   |z   |z   }| j                  | j                  |      | j                  | j                        t        j                  d      }||| j                  | j                   d}||||dS )Nr   rW  r   r:  z/apir  DELETE?r   r   r   base64)zCB-ACCESS-TIMESTAMPzCB-ACCESS-SIGNzCB-ACCESS-PASSPHRASEzCB-ACCESS-KEY)urlr   bodyr1   )implode_paramsr?  extract_paramsurlencode_with_array_repeatr   check_required_credentialsstrr  jsonhmacencodebase64_to_binaryr   hashlibsha256r   r   )r   pathr   r   r  r1   r  r-   signedfullPathquery	savedPathr  r  payloadauth	signatures                    r  signzcoinbaseinternational.sign  sU   a&Q9$=3&)<)<T6)JJ		&$"5"5d";<X%	U?f0C$"B"B5"IIIiiv&1++-

%EG99U+D"G6>I-7D		$++d"3T5J5J4;;5WY`YgYgiqrI',"+(,!%	G fdwOOr  reasonr  r   r1   r  c
                     |y | j                   dz   |z   }
| j                  |d      }|K| j                  | j                  d   ||
       | j	                  | j                  d   ||
       t        |
      y )Nr  titler   r   )r%   r
  throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r/  r  r  r   r1   r  r+  requestHeadersrequestBodyfeedbackerrMsgs               r  handle_errorsz#coinbaseinternational.handle_errors  s}     77S=4'!!(G4001I6S[\001I6S[\))r  re  )S__name__
__module____qualname__r   r   r  r  r%  r  r0  r
   r   listrH  r   rS  r   rc  rg  rf  r  r  r   r  dictr   r  r  r	   r  r!  r  r  r  floatr  r   r  r  r  r   r   r  r  r  r  r#  r   r1  r5  rR  r   rV  r[  r   r`  r   rd  objectr]  r   r{  ry  r  r   r   r  r   r  r  r  r  r  r  r  r  r  r   r  r  intr  __classcell__)r   s   @r  r"   r"      s   w# wr	 CE ^c ^$# ## #" %' 5<
. 26DWZce 1K# 1Kc 1KQT 1Kjnosjt 1Kf
 
4 
( 8<$]ajl 2Q 2QC 2QWZ 2Qh5v 5
6 
< 37TX\eg BC Bs BRU BB&
6 &
P +/TPT]_ GC Gs G# Gdhivdw GB)
t )
x )
= )
V:C :C : 8: 1
3 1
n 1
f  35 < /1  -/ (T =? P Pe P3 P* 6:[_hj F8s F8# F8UX F8ost  pA F8P 24 "-S "-H/t /V /b 26b &Sw &ST(^ &SP -1tRV_a Kc K KC Kfjkvfw K* *.Dt\^ K3 Kc K Kcghsct K$:s :!
T !
X !
Q\ !
F4 4v 4 4l $& ;,$v, ;,zn
4 n
F n
` ') 1Z 12t  : 04B FW F7 F, 02 13 1f 1$*6 *6 *V *X $& ",( ",H) ): [] !
S !
% !
c !
c !
an !
F imuw V23 V2i V2y V2RW V2`e V2p6 6v 6 6p: :	3S 	3 37r -0s -0C -0^ /32 1 1( bfvz  DF %/S %/# %/Y %/i %/Y^ %/ns %/N 26b //c //3 //b /3TXac LB LB3 LBc LBhlmrhs LB\ -1tRV_a Q?c Q? Q?C Q?f DHPR +:S +:% +:# +:Wb +:Z"
H  b$T P8# s  c TX `c r  r"   )'ccxt.base.exchanger   #ccxt.abstract.coinbaseinternationalr   r  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   r   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser    r"    r  r  <module>r     s\    ( ;  F  F  F  F  F  * 0 - . ' ) - 4 %x"Hk x"r  