
    eiC                       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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% d dl&m'Z'  G d dee          Z(dS )    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyDepositAddressIntMarginModificationMarketOrder	OrderSide	OrderTypePositionStrStringsTickerTickersTradeTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)InvalidOrder)DuplicateOrderId)NotSupported)	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
dee         f
dZd[dedefdZd
d
d
i fdede
de
fdZd[defdZd[defdZd
d
d
i fdede
de
fdZd[defdZd
d
d
i fdede
de
dee         fdZd[d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'd[d(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.d[d/edede%fd0Z/d[d1edede0fd2Z1i fdee         fd3Z2dedefd4Z3i fde4fd5Z5dedefd6Z6d
i fd*e)de7fd7Z8i fdede9fd8Z:d[d9e;dede9fd: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@eAdAeBd$e"dBe"f
dCZCd[dDededeDfdEZEdefdFZFd@efdGZGd
i fdHedefdIZHd
i fdefdJZId
d
i fdHeded@eAdAeBd$e"dBe"fdKZJd
i fdHedefdLZKd
d
d
i fdede
de
deeD         fdMZLd
d
d
i fdede
de
fdNZMd
i fded$e"dOedPede%f
dQZNdR ZOg dSi d
d
fdTZPdeQdUedVedWedXedYefdZZR xZSS )\coinbaseinternationalreturnc                    |                      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|                     d          |                     d          d
d
|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          gg|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggddidt          di t          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 allowedz)cbe spot routing instrument not supported)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   rI   createOrdersrl   rp   ro   rr   rV   rm   extendsdefault)linearinverse)r   r6   r8   r9   )optionsfeatures)deep_extendsuperr$   describe
userAgentsparse_numberr!   r   r   r   r   r   r    )self	__class__s    X/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/coinbaseinternational.pyr   zcoinbaseinternational.describe   s
   &;T B B K K M M wP
)wP
,wP
 $wP
 	wP

 4wP
 wP
 twP
 2wP
 lw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& ('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 U 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 U 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 U 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 UwP
D kH ? <? C  EwP
f " $ $gwP
p  	  	  	       
! 
! 
! *4 
 %)#A$  $ 2 24qwP
Z !..w77!..w77!%"& "..s33T5F5Fw5O5OP!..y994;L;LW;U;UV!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mg<V<VW!..{;;T=N=Nx=X=XY" "..s33T5F5Fw5O5OP!..y994;L;LX;V;VW!..y994;L;LW;U;UV!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX!..{;;T=N=Ns=S=ST"  [wP
N YOwP
P 1A&21='35A$4,6+5!+&9AM  QwP
p "#'&   	 	qwP
F '> !& *!' *&#$! ! $  $&+(,,0,0).+06:#'#'"&#'#'( ( #($)$)+026/3#(+$ $. %)&+!$$(%**/& & ',#($)*/	# # ',!$#($)*/( ( $()-#a3 3j y
 "9 "9 	  ## AD DewP
 wP
 wP
 w w w	    
methodNamec                    d }|                      ||d          \  }}|
|dk    r||gS |                     | j        d          }|
|dk    r||gS |                                 }t	          dt          |                    D ]]}||         }|                     |di           }|                     |d          r&|                     |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_paramsS  s;   	 99&*kZZ	6!	Rv&&++DL+FF(/?2/E/E$f--&&((q#h--(( 	- 	-AqkG>>'6266D~~dL11 -"..t^DD,7[)#V,,,,-  #
 :  >]  !]  ^  ^  	^r  currencyCodec                    d }|                      ||d          \  }}||                     |           | j        |         d         }|                     |dd          }|P|                     |          rt          | j        dz   |z   dz             |                     |          }|d         }n|                     ||          }||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_paramse  s    	 99&*N^__	6''555|4Z@H((	JJG==** _$TW/f%fiu%u  y^  &^  _  _  _!%!:!:8!D!D*40		 33G\JJ	6""r  c                     |                                   |                     |          }|                     ||          S )ad  
        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_accountsv  sA     	..v66$ ""8V444r  c                 :    |                      |dd          d d |dS )Nr	  portfolio_uuid)r'   typecoder  )r!  )r  r  s     r  parse_accountz#coinbaseinternational.parse_account  s2    " $$Wn>NOO	
 
 	
r  r   Nr.   symbol	timeframesincer   c           	         |                                   d}|                     |dd          \  }}|r|                     d|||||d          S |                     |          }|d         |                     | j        ||          d}||                     |          |d<   nt          | j        d	z             | 	                    |d
          }	|	.| 
                    |d
          }|                     |	          |d<   |                     |                     ||                    }
|                     |
dg           }|                     |||||          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)
        Frm   paginater   r'   )
instrumentgranularityN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  r3  r4  r5  r   r  r7  r?  requestunitlr-  candless               r  fetch_ohlcvz!coinbaseinternational.fetch_ohlcv  so    	88zZZ& 	y::<QVX]_hjprwxxxV$$ ,++DOY	RR
 
 #||E22GG#DG.W$WXXX!!&'22YYvw//F!\\%00GEN??GU[@\@\]] ..>2>>  &)UEJJJr  r?  c           	      *   |                      |                     |dd                    |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr:  timeopenhighlowclosevolume)	parse8601r!  safe_number)r  ohlcvr?  s      r  parse_ohlcvz!coinbaseinternational.parse_ohlcv  s     NN4--eWfEEFFUF++UF++UE**UG,,UH--
 	
r  c           	      p   |t          | j        dz             |                                  d}|                     |dd          \  }}d}|                     |ddd          \  }}d}|r|                     d||||||          S |                     |          }|                     ||d	          d	z
  }	|d
         |                     |dd|	|z            d}
|||
d<   |                     | 	                    |
|                    }| 
                    |dg           }|                     ||||          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]   r7  maxEntriesPerRequestr.   ccxtPageKey   r'   offsetresult_offset)r8  r[  result_limitresults)r   r'   r)  r   fetch_paginated_call_incrementalr?  rA  safe_integer_2'v1PublicGetInstrumentsInstrumentFundingrD  rE  parse_funding_rate_histories)r  r3  r5  r   r  r7  rW  pageKeyr?  pagerG  r-  rawRatess                r  fetch_funding_rate_historyz0coinbaseinternational.fetch_funding_rate_history  s    >#DG.e$efff88AZ\fgg&#'+'D'DVMfh~  AD  (E  (E$f 	Q889RTZ\achjpry  |P  Q  Q  QV$$  !44q8 ,!00?TX[oTopp
 
 &+GN#??GU[@\@\]]$ >>(Ir::0065%PPPr  c                 .    |                      ||          S N)parse_funding_rate)r  r  r?  s      r  parse_funding_rate_historyz0coinbaseinternational.parse_funding_rate_history&  s    &&tV444r  c                 ^   |                      |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 S )N
event_timerL  r  r3  	markPrice
mark_price
indexPriceinterestRateestimatedSettlePrice	timestampdatetimefundingRatefunding_ratefundingTimestampfundingDatetimenextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetime)r!  safe_symbolrS  rR  )r  contractr?  rv  s       r  rh  z(coinbaseinternational.parse_funding_rate)  s5    ,,X|VLL
H
d&&tV44
 ))(LAA
 $	

 D
 #D
 88
 
 4++HnEE
  ? ?
 
 t
 #D
 "4
 "4
  '!
" &t#
 	
r  c                    |                                   ddi}d}||                     |          }d}|                     |dd          \  }}|||d<   ||                     |          |d<   |||d<   nd|d<   |                     |                     ||                    }|                     |d	g           }	|                     |	|||          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>`
        r0  FUNDINGNr[   r   	time_fromr\  r.   r]  )r)  r?  r  r@  v1PrivateGetTransfersrD  rE  parse_incomes)
r  r3  r5  r   r  rG  r?  r   r-  fundingss
             r  fetch_funding_historyz+coinbaseinternational.fetch_funding_historyG  s     	I
 [[((F
!::6CXZfgg
F!$.GL!#'<<#6#6GK &+GN##&)GN#--dkk'6.J.JKK>>(Ir::!!(FE5AAAr  c           
         |                      |d          }|                     ||d d          }|                     |d          }|                     |          }|                      |d          }|                     |          }||d         |||                     |          |                      |d          |                     |d          d dS )Nr3  r~  
created_atassettransfer_uuidamount)r  r3  r1  rq  rr  r'   r  rate)r  safe_marketrA  rR  safe_currency_coder@  rS  )r  incomer?  marketIdrr  rq  
currencyIdr1  s           r  parse_incomez"coinbaseinternational.parse_incomeh  s    . ##FH55!!(FD*EE$$V\::NN8,,	%%fg66
&&z22X&"Y//""6?;;&&vx88	
 	
 		
r  r1  c                    |                                   ddi}d}||                     |          }d}|                     |dd          \  }}|||d<   ||                     |          |d<   |||d<   nd|d<   |                     |                     ||                    }|                     |d	g           }	|                     |	|||          S )
a5  
        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>`
        r0  INTERNALNr   r   r  r\  r.   r]  )r)  currencyr  r@  r  rD  rE  parse_transfers)
r  r1  r5  r   r  rG  r  r   r-  r   s
             r  fetch_transfersz%coinbaseinternational.fetch_transfers  s     	J
 }}T**H
!::6CSUabb
F!$.GL!#'<<#6#6GK &+GN##&)GN#--dkk'6.J.JKKNN8Y;;	##IxFFFr  transferr  c                 >   |                      |d          }|                     |          }|                     |d          }|                     |          }|                     |di           }|                     |d          }|                     |di           }	|                     |	d          }
||                     |d          ||                     |          ||                     |d          ||
|                     |                     |d                    d		S )
Nr  r  from_portfolior'   to_portfolior  r  status	r  r'   rq  rr  r  r  fromAccount	toAccountr  )rA  rR  r  r  r  r@  rS  parse_transfer_status)r  r  r  rr  rq  r  r1  fromPorfoliofromId
toPorfoliotoIds              r  parse_transferz$coinbaseinternational.parse_transfer  s   . $$X|<<NN8,,	%%h88
&&z22~~h0@"EE!!,55^^HnbAA

D11""8_=="Y//&&x::!001A1A(H1U1UVV

 

 
	
r  r  c                 >    ddddd}|                      |||          S )Nfailedokpending)FAILED	PROCESSEDNEWSTARTEDr  r  r  statusess      r  r  z+coinbaseinternational.parse_transfer_status  s4     	
 
 &&999r  c                    |                                   d}|                     |ddd          \  }}d}|                     d|          \  }}d|i}|dk    rA|                     |          }|d         |d<   d}|                     |d|          \  }}||d<    t          | |          |                     ||                    }|                     |d	          }	|                     |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>`
        NrA   r   v1PrivatePostTransfersAddressr   r'   r  r  destination_tagaddresscounterparty_id)r  tagr  r  r  )	r)  r  r  r  r'  getattrrD  r  r!  )r  r1  r  r   r   rG  r  r%  r-  r  r  s              r  create_deposit_addressz,coinbaseinternational.create_deposit_address  sB    	66v?UW_  bA  B  B	 <<=SU[\\	6
 444}}T**H'~GGI $ A A$H^`f g gIv(1G$%(74((Wf)E)EFF x):;;$$Xy:KLL
 
 	
r  c                     |                      |          }t          dt          |                    D ]5}||         d         }|                     |dd          }|du r
||         c S 6|d         S )Nr   r  r  FT)to_arrayr  r  r  )r  r  networksArrayr  r  r  s         r  r#  z*coinbaseinternational.find_default_network  s    h//q#m,,-- 	( 	(A #F+DlEBBJT!!$Q'''' "Qr  c                     |                      |          }|                     |d          }|dS d|d         i}|                     |          }|                     |          |d<   dS )Nr  Fr  r'   T)r  r  v1PublicGetAssetsAssetNetworksparse_networks)r  r1  r  r  r  rG  rawNetworkss          r  r  z,coinbaseinternational.load_currency_networks!  su    ==&&>>(J775Xd^
 99'BB&  $22;??tr  c                     i }t          dt          |                    D ]<}|                     |                     ||                   |          }|||d         <   =|S )Nr   r  )r  r  rD  parse_network)r  r  r  resultr  r  s         r  r  z$coinbaseinternational.parse_networks?  sb    q#h--(( 	1 	1Akk$"4"4Xa["A"A6JJG)0F79%&&r  c                    |                      |d          }|                     |          }|                      |d          }|                     |g dd          }|                     |||                      |d          |                     ||          d d d d d |                     |d          |                     |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_coderS  )r  r  r  r  r  r%  networkIdForCodes          r  r  z#coinbaseinternational.parse_networkF  s     %%g|<<
..z::$$W.>??	--g7i7i7ikmnn  $$Wn==../?NN  ++G5IJJ++G5IJJ 
   	 	"
 "
   	r  r  c                     d}|                      d|          \  }}|t          | j        dz             ||d}|                     |                     ||                    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'   v1PrivatePostPortfoliosMarginrD  )r  r3  r  r  r   rG  s         r  
set_marginz coinbaseinternational.set_marginp  su     	 <<[&QQ	6TW'bbccc"%
 
 11$++gv2N2NOOOr  c           	         |                                   d}|                     |dd          \  }}d}|                     |ddd          \  }}d}|r|                     d||||||          S |                     ||d          dz
  }d|                     |d	d||z            i}	||                     |          |	d
<   |t          |d          }
|
|	d<   d}|                     |dd          \  }}|||	d<   d}|                     |dd          \  }}||                     |          |	d<   |                     |                     |	|                    }| 	                    |dg           }| 
                    |          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fetchDepositsWithdrawalsr7  rW  r.   rX  rY  r[  rZ  r  r\  r   r;  time_tor]  )r)  r  r^  rA  r_  r@  r  r  rD  rE  parse_transactions)r  r1  r5  r   r  r7  rW  rb  rc  rG  newLimitr   r;  r-  rawTransactionss                  r  fetch_deposits_withdrawalsz0coinbaseinternational.fetch_deposits_withdrawals  s   " 	88A[]ghh&#'+'D'DVMgi  BE  (F  (F$f 	P889SUY[`bgioqx  {O  P  P  P  !44q8T00?TX[oTopp
 #'<<#6#6GK 5#H&.GN#
!::6C]_kll
F!$.GL!55f>XZabbv!%e!4!4GI--dkk'6.J.JKK6 ..9bAA&&777r  c                 6   |                                   |                     |          }d}|                     d|          \  }}||                     |          d}|                     |                     ||                    }|                     |          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>`
        Nrs   )r   r8  )r)  r3  r  	market_id2v1PrivateGetPortfoliosPortfolioPositionsInstrumentrD  parse_position)r  r3  r  r   rG  positions         r  fetch_positionz$coinbaseinternational.fetch_position  s     	V$$	 <<_fUU	6"..00
 
 JJ4;;W^`fKgKghh  ""8,,,r  r  c           
         |                      |d          }|                      |d          }|                     ||d          }d}t          j        |d          rd}t          j        d|          }|                     i d|d	|                      |d	          d|d         d
d d|                     |d          dd dd d|                     |d          d|d|                     |          d|                     |d          dd dd dd dd dd d|                     |d          d d d d d d d          S )Nr3  net_size-longr   shortz-1r  r'   
entryPricerl  rm  notional
collateralunrealizedPnlunrealized_pnlside	contractscontractSizerq  rr  r   maintenanceMarginmaintenanceMarginPercentageinitialMarginim_contribution)initialMarginPercentager   liquidationPricemarginRatior   r   )r  r  r"   	string_le
string_mulsafe_positionrS  r   )r  r  r?  r  quantityr  s         r  r  z$coinbaseinternational.parse_position  s     ##Hh77##Hj99!!(FC88Xs++ 	:D)$99H!! #
H#
$""8T22#
 fX&#
 $	#

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

        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>`
        Nrv   r   r3  F)r)  r  (v1PrivateGetPortfoliosPortfolioPositionsrD  parse_positionsr"  market_symbolsfilter_by_array_positions)r  r  r  r   rG  r-  	positionss          r  fetch_positionsz%coinbaseinternational.fetch_positions"  s     		 <<=MvVV	6
 @@WV\A]A]^^$ ((22	==!! 	%%g..--i7ERRRr  c                 d    |                                   d|d<   |                     ||||          S )ay  
        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>`
        WITHDRAWr0  r)  r  r  r1  r5  r   r  s        r  fetch_withdrawalsz'coinbaseinternational.fetch_withdrawalsJ  s9    " 	#v..tUE6JJJr  c                 d    |                                   d|d<   |                     ||||          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>`
        DEPOSITr0  r  r	  s        r  fetch_depositsz$coinbaseinternational.fetch_deposits_  s9     	"v..tUE6JJJr  c                 >    ddddd}|                      |||          S )Nr  r  canceled)r  r  r  r  r  r  s      r  parse_transaction_statusz.coinbaseinternational.parse_transaction_statusq  s4      	
 
 &&999r  transactionc           
         |                      |d          }|                     |di           }|                     |dd|                     |g d          dg          }|                     |di           }|                     |dd|                     |g d          d	g          }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!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_uuidrq  rr  r  r  r  	addressToaddressFromr  tagTotagFromr0  resourcer  r  r  r  updatedr  costr  )r  r  r  rR  r  rS  r  r  )r  r  r  rr  r  r  r  r  s           r  parse_transactionz'coinbaseinternational.parse_transactionz  s    ##K>>~~k3CRHH((~GXZ^ZlZlmy  |R  |R  |R  [S  [S  Uk  7l  m  m^^K1A2FF
&&{\?TXTfTfgq  tJ  tJ  tJ  UK  UK  Ma  5b  c  c	
K
$"";@@
 D$$[2DEE
 11	

 
 t..t/?/?^/\/\]]
 t
 
 ;
 4
 T
 t
 D$$[*==
 d&&{H==
 //0@0@g0V0VX`aa
  d33D4D4D[RZ4[4[\\!
" t~~h//#
$   %
 
 	
r  tradec                 4   |                      |d          }|                      |d          }|                     ||                     |dd          |                      |d          |                     |          ||                     ||          d |                     |d          d |                     |d          |                     |d          d |                     |d	          |                     |                      |d
                    dd          S )Nr3  rk  fill_idexec_idorder_idr  
fill_pricefill_qtyr  	fee_assetr#  )r  r'   orderrq  rr  r3  r0  r  takerOrMakerpricer  r$  r  )r  
safe_trader!  rR  r}  safe_string_lowerrS  r  )r  r&  r?  r  rr  s        r  parse_tradez!coinbaseinternational.parse_trade  s   B ##E844##E<88$$UIyAA%%eZ8811 &&x88**5&99 %%e\::&&uj99((66 33D4D4DUK4X4XYY  
  
   	r  c                 V    |                      |          }|                     |          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6d !!(+++r  c                 l   |                      |d          }|                      |d          }|                      |d          }|                      |d          }|dk    }| j        }|dz   |z   }d }	|s
|}	|d|z   z  }i d|d	|                                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|                      |d          dk    d| |rd n|	|k    |rd n|	|k    |d         d         |d         d         |rd ndd d d d |                     |d          |                     |d          |                     |d          d d |                     |d!          d"d |rd n|                     |d#          d"d d d"|                     |d$          d d"d%|d d&S )'Nr3  base_asset_namequote_asset_namer0  SPOT/:r'   lowercaseIdbasequotesettlebaseIdquoteIdsettleIdr6   r8   r7   Fr9   r:   r  trading_stateTRADINGr~  r   r   r   rY  base_incrementquote_increment)r  r0  r$  base_imfr  position_limit_qtymin_notional_value)r   r  r0  r$  )r   r   r   r   r  expiryexpiryDatetimestrike
optionTyper  r  r  created)r  r   lowerrS  )
r  r?  r  rB  rC  typeIdisSpotr   r3  rD  s
             r  parse_marketz"coinbaseinternational.parse_market  s   ^ ##FH55!!&*;<<""6+=>>!!&&11F"y#' 	$HcGm#F4
(4
8>>++4
 f4
 F	4

 W4
 (4hh4
 f4
 w4
 H6$4
 f0FF&4
 F4
 e4
 J4
 e4
 e4
  d&&v??9L!4
" F
#4
$ %?dd8w+>%@ttH,?)_W-)_W-$*1DD"**63CDD))&2CDD((1BCC   ++FJ?? 
  #)]44t/?/?H\/]/] 
   
  ++F4HII  $ g4
 4
 4
 4	
r  c                 V    |                      |          }|                     |          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3
 $$Z000r  c                     |                      |d          }|                     |          }|                      |d          }|                     |||d ||dk    d d d d d | j        d          S )Nr  r  ACTIVE)r'   r(   r1  r  r  r  r  r   r  r  r   r  )r  r  safe_currency_structurer  )r  r  r'   r1  statusIds        r  parse_currencyz$coinbaseinternational.parse_currency  s     h55&&r**##Hh77++8+k-
 -
   	r  c                    |                                   |                     |          }|                     |          }i }t          dt	          |                    D ]x}||         }|                     |d          }|                     |          }|                     |di           }	|                     |	| 	                    |                    ||<   y| 
                    |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   r3  r@  T)r)  r  r5  r  r  r  r}  r  parse_tickerr  filter_by_array)
r  r  r  r   tickersr  r8  r  r3  r@  s
             r  fetch_tickersz#coinbaseinternational.fetch_tickers  s     	%%g..11&99q#k**++ 	S 	SA$QJ''
H==H%%h//FNN:w;;E"//t7G7G7Q7QRRGFOO##GXwEEEr  c                     |                                   |                     |          }d|                     |          i}|                     |                     ||                    }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://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>`
        r8  )r)  r?  r  %v1PublicGetInstrumentsInstrumentQuoterD  r_  )r  r3  r  r?  rG  tickers         r  fetch_tickerz"coinbaseinternational.fetch_ticker  sy     	V$$$..00
 ;;DKKQW<X<XYY  000r  re  c                    |                      |d          }|                     i d|d|                     d |          d|                     |          d|d|                     |d          d|                     |d          d	|                     |d
          d|                     |d          dd dd dd dd dd dd dd dd dd d d d |                     |d          |                     |d          d          S )Nrq  r  r3  rr  bidbest_bid_price	bidVolumebest_bid_sizeaskbest_ask_price	askVolumebest_ask_sizerN  rO  rM  rP  lastchanger   averagevwaprm  index_price)
baseVolumequoteVolumepreviousCloserl  rn  )r  safe_tickerr}  rR  rS  )r  re  r?  rr  s       r  r_  z"coinbaseinternational.parse_ticker  s   $ ##FK88 !
F!
d&&tV44!
 11!
 	!

 4##F,<==!
 ))&/BB!
 4##F,<==!
 ))&/BB!
 D!
 4!
 D!
 T!
 D!
 d!
 $!
  t!!
" D#!
$ !))&,??**6=AA-!
 !
 !
   	r  c                     |                                   d}|                     d|          \  }}d|i}|                     |                     ||                    }|                     |          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>`
        NrQ   r   )r)  r  'v1PrivateGetPortfoliosPortfolioBalancesrD  parse_balance)r  r  r   rG  balancess        r  fetch_balancez#coinbaseinternational.fetch_balance
  s{     		 <<^VTT	6
 ??GU[@\@\]]$ !!(+++r  c                 p   d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   |                     |          S )Nr  r   r  r  totalholdused)r  r  r  r  r  safe_balance)r  r-  r  r  
rawBalancer  r1  r  s           r  r{  z#coinbaseinternational.parse_balance.  s    " H
 q#h--(( 	# 	#A!!J))*lCCJ**:66DllnnG#//
JGGGG"..z6BBGFO"F4LL  (((r  r  r  c           
         |                                   |                     |          }|d         |||d}|                     |                     ||                    }|                     |d          }	|ddd|||||	rdn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  v1PrivatePostPortfoliosTransferrD  r  )
r  r1  r  r  r  r  r  rG  r-  r  s
             r  r  zcoinbaseinternational.transferK  s     	==&&d^	
 
 77GV8T8TUU..955&"%3dd8

 

 
	
r  r0  r  r0  c                    |                                   |                     |          }|                                }|                     |g d          }	|                     | j        dd          }
|
dz   |                                 z   }|dd         }||                                |d         |                     |d         |          d	}|	|dk    rd}nd}|	|d<   ||d<   |dk    r|t          | j	        dz             ||d<   d
}| 
                    d|          \  }}|||d<   |                     |dd          }|                     |dd          }|dk    r"||dk    rt          | j	        dz             d}n|dn|}|||d<   ||d<   |                     |g d          }|                     |                     ||                    }|                     ||          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'   r3  )client_order_idr  r8  sizeNr   
STOP_LIMITSTOPr  r0  zA createOrder() requires a price parameter for a limit order typesr0  rI   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!  rB  v1PrivatePostOrdersrD  parse_order)r  r3  r0  r  r  r0  r  r?  rR  r   clientOrderIdprefixclientOrderIdrG  r   r  r  r-  s                    r  create_orderz"coinbaseinternational.create_ordern  s1   * 	V$$))&2]2]2]^^"..t|ZTT+c1DIIKK?%ad+,JJLL ,,,VH-=vFF	
 
 #w%$0GL! 7??}"47-p#pqqq$GG	 <<]FSS	6 #,GK ##FJDD  >>X3%<<"47-f#fgggCCK%%cC#+GK 6#Y#Y#YZZ++DKK,H,HII0 &111r  r.  c           
         |                      |d          }|                     |d          }d }|d|i}|                     |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|          S )Nr3  r  r$  submit_timerk  r  r'   r*  r  r  rq  rr  lastTradeTimestampr0  r   r  r  r  r0  r   r  r  r  filledexec_qty	remaining
leaves_qty	avg_priceorder_status)rr  r  r  trades)	r  rS  r!  
safe_orderrR  r}  parse_order_typer2  parse_order_status)r  r.  r?  r  feeCostr  rr  s          r  r  z!coinbaseinternational.parse_order  s\   0 ##E844""5%00C %%e]LII  
E 
$""5*55 
 T--e5FGG 
 11	 

  
 !$ 
 d&&x88 
 D))$*:*:5&*I*IJJ 
 4++E599 
  
 D**5&99 
 T%%eW55 
 D,,ULAA 
 d&&uf55 
 d&&uj99 
  ))%>>! 
" D# 
$ ''{;;--d.>.>un.U.UVV+ 
  
  
, -  	r  c                 J    ddddddddddd
}|                      |||          S )NrM  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  sF    $""$"! %
 
 &&999r  c                 N    |dk    rd S ddddd}|                      |||          S )NUNKNOWN_ORDER_TYPEr?  r   )r  LIMITr  r  r  )r  r0  typess      r  r  z&coinbaseinternational.parse_order_type  sE    '''4!	
 
 tT222r  r'   c                    |                                   d}|                     d|          \  }}||d}d}||                     |          }|                     |                     ||                    }|                     ||          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?  v1PrivateDeleteOrdersIdrD  r  )r  r'   r3  r  r   rG  r?  r   s           r  cancel_orderz"coinbaseinternational.cancel_order  s     		 <<]FSS	6"
 
 [[((F--dkk'6.J.JKK0 ///r  c                 .   |                                   d}|                     d|          \  }}d|i}d}|r |                     |          }|d         |d<   |                     |                     ||                    }|                     ||          S )a`  
        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'   r8  )r)  r  r?  v1PrivateDeleteOrdersrD  parse_orders)r  r3  r  r   rG  r?  r   s          r  cancel_all_ordersz'coinbaseinternational.cancel_all_ordersG  s     		 <<=NPVWW	6
  	1[[((F$*4LGL!++DKK,H,HII  000r  c                 2   |                                   |                     |          }d|i}	d}
|                     d|          \  }
}|
|
|	d<   ||                     ||          |	d<   ||                     ||          |	d<   |                     |g d          }|||	d<   |                     |d	d
          }|t          | j        dz             ||	d	<   | 	                    | 
                    |	|                    }|                     ||          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'   NrO   r   r  r0  )r  r  r   r  r  r  z/ editOrder() requires a clientOrderId parameter)r)  r?  r  r  price_to_precisionr  r!  r   r'   v1PrivatePutOrdersIdrD  r  )r  r'   r3  r0  r  r  r0  r  r?  rG  r   r   r  r.  s                 r  
edit_orderz coinbaseinternational.edit_order[  sE     	V$$"
 	 <<[&QQ	6 #,GK "66vvFFGFO#66vuEEGG))&2]2]2]^^#$0GL!**63DoVV TW'XXYYY%2!"))$++gv*F*FGGv...r  c                    |                                   d}||                     |          }d}|                     d|          \  }}||d}|                     |                     ||                    }|                     ||          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>`
        Nrp   )r'   r   )r)  r?  r  v1PrivateGetOrdersIdrD  r  )r  r'   r3  r  r?  r   rG  r.  s           r  fetch_orderz!coinbaseinternational.fetch_order  s     	[[((F	 <<\6RR	6"
 
 ))$++gv*F*FGG4 v...r  c           	         |                                   d}|                     d|          \  }}d}|                     |dd          \  }}d}|                     |ddd          \  }}d}|r|                     d||||||          S |                     ||d          dz
  }	||                     |d	d
|	|z            d}
d}|r|                     |          }||
d<   |"|dk    rt          | j        dz             ||
d<   || 	                    |          |
d<   | 
                    |                     |
|                    }|                     |dg           }|                     ||||          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>`
        Nro   Fr7  rW  r.   rX  rY  rZ  r[  )r   r[  r8  z' fetchOpenOrders() maximum limit is 100r\  ref_datetimer]  )r)  r  r  r^  rA  r_  r?  r   r'   r@  v1PrivateGetOrdersrD  rE  r  )r  r3  r5  r   r  r   r7  rW  rb  rc  rG  r?  r-  	rawOrderss                 r  fetch_open_ordersz'coinbaseinternational.fetch_open_orders  s    		 <<=NPVWW	688ART^__&#'+'D'DVM^`vx{'|'|$f 	I889JFTY[`bhjq  tH  I  I  I  !44q8"!00?TX[oTopp
 
  	+[[((F$*GL!s{{ +T!TUUU&+GN#&*ll5&9&9GN#**4;;w+G+GHHF NN8Y;;	  FE5AAAr  c           	      6   |                                   d}|                     |dd          \  }}d}d}|                     |ddd          \  }}|r|                     d||||||          S d}||                     |          }|                     ||d          dz
  }	d	|                     |d
d	|	|z            i}
|"|dk    rt          | j        dz             ||
d<   ||                     |          |
d<   | 	                    |dg          }|/| 
                    |dg          }|                     |          |
d<   |                     |                     |
|                    }|                     |dg           }|                     ||||          S )aX  
        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>`
        Frl   r7  rX  NrW  r.   rY  r[  rZ  z^ fetchMyTrades() maximum limit is 100. Consider setting paginate to True to fetch more trades.r\  r  r;  r  r]  )r)  r  r^  r?  rA  r_  r   r'   r@  r  rB  v1PrivateGetPortfoliosFillsrD  rE  parse_trades)r  r3  r5  r   r  r7  rb  rW  r?  rc  rG  r;  r-  r  s                 r  fetch_my_tradesz%coinbaseinternational.fetch_my_trades  s    	88R\]]&#'+'D'DV_^tvy'z'z$f 	G88&RWY^`fho  rF  G  G  G[[((F  !44q8T00?TX[oTopp
 s{{   ,L  "L  M  M  M&+GN##'<<#6#6GK ""6G955YYvy11F&*ll5&9&9GN#33DKK4P4PQQR )R88  >>>r  r  r  c           	      0   |                      ||          \  }}|                     |           |                                  |                     |          }d}|                     d|          \  }}d}|                     |ddd          \  }}d}	|                     |d|          \  }	}|d|d         |||d         |	|                                 d}
 t          | |          | 	                    |
|                    }| 
                    ||          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   r0  r  r  r  r  r  nonce)handle_withdraw_tag_and_paramscheck_addressr)  r  r  r  r'  r  r  rD  r%  )r  r1  r  r  r  r  r  r   r   r%  rG  r-  s               r  r   zcoinbaseinternational.withdrawT  s-   " 99#vFFV7###==&&	 <<ZPP	666vz8Uuvv	 ==dJPVWW	6"d^ 'ZZ\\	
 	
 )74((Wf)E)EFF %%h999r  c                    |                      |d          }|                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|||dk    }|||dk    }|                     |d          }	|o|}
|d         |	|                     |d          |                     |d	          |                      |d
|
          |||                     |d          |                     |d          |                     |d          |d|                     |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  rS  r  )r  r  withdrawEnableddepositEnabledr  r   withdrawMaxr  
depositMaxr%  	isEnableds              r  r  z"coinbaseinternational.safe_network  s   ..*==;;22>>&*55&&x77..33%%gu55
"{'>*QO!j&<(1nN$$Wd33	$7	FO$$Wf55'';;nnWh	BB%'##GU33))';??  ++He<<& 
  ++GU;;% 	 	
 
 	
r  GETc                    |d         }|d         dk    }d|z   dz   |                      ||          z   }	|                     ||                     |                    }
d|	z   }|dk    s|dk    r|
r|	d|                     |
          z   z  }	| j        d	         d
         |	z   }|r|                                  t          |                                           }d}|dk    r|
r|                     |
          }|}||z   |z   |z   }| 	                    | 
                    |          |                     | j                  t          j        d          }||| j        | j        d}||||dS )Nr   rY  r   r<  z/apir  DELETE?r   r   r   base64)zCB-ACCESS-TIMESTAMPzCB-ACCESS-SIGNzCB-ACCESS-PASSPHRASEzCB-ACCESS-KEY)urlr   bodyr3   )implode_paramsrB  extract_paramsurlencode_with_array_repeatr   check_required_credentialsstrr  jsonhmacencodebase64_to_binaryr   hashlibsha256r   r   )r  pathr   r   r  r3   r  r/   signedfullPathquery	savedPathr  r  payloadauth	signatures                    r  signzcoinbaseinternational.sign  s   a&Q9$=3&)<)<T6)J)JJ		&$"5"5d";";<<X%	U??f00 JC$"B"B5"I"IIIiv&1 	++---

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