
    iY                    T   d dl mZ d dlmZ d dl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& 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)AccountBalances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeesTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)OnMaintenance)	TICK_SIZE)Precisec                   B    e Zd Z fdZi fdZi fdZi fdefdZi fdee	         fdZ
de	fdZdi fd	edefd
Zi fdedefdZdDde	defdZdi fdededefdZdddi fdedededee         fdZdDde	defdZddi fdedededee         fdZdDde	defdZi fdefdZdDde	fdZi fdee         fdZ d Z!i fde"fdZ#de"fdZ$dddi fde%dedefdZ&dddi fdede%dededee         f
dZ'dddi fde%dededee(         fd Z)di fdede%fd!Z*dddi fde%dededee(         fd"Z+dddi fde%dededee(         fd#Z,dddi fde%dedefd$Z-di fde%fd%Z.di fdede%fd&Z/di fde%fd'Z0di fded(e1d)e2d*e3d+e4f
d,Z5ddi fdeded(e1d)e2d*e4d+e4fd-Z6dDde	de(fd.Z7d/ Z8d0 Z9i fd1ed*e3d2ed3ede:f
d4Z;dddi fd1e%dedefd5Z<dDd6e=fd7Z>d8 Z?dddi fd1e%dededee@         fd9ZAdi fd1ed*e3fd:ZBdDd6e=de@fd;ZCd< ZDdddi fd1e%dedefd=ZEdDd6e=fd>ZFd? ZGd@dAi ddfdBZHdC ZI xZJS )Ecoinlistc           $         |                      t          t          |                                           dddgddddi dd dd	d
ddddddddddd	dd	dd	dddddddd	dd	dddd	i dd	dd	dddd	dd	dd	ddd dd!dd"dd#d	d$dd%d	d&dd'dd(d	d)di d*dd+dd,dd-dd.d	d/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9d	d:di d;dd<dd=d	d>dd?d	d@d	dAddBddCd	dDd	dEd	dFddGd	dHd	dIddJddKdi dLddMddNd	dOd	dPd	dQd	dRddSd	dTddUddVddWd	dXd	dYddZdd[dd\ddddddddd	d	dd]
d^d_d`dadbdcdcdddedfgdgdhdidjdjdjdjdjdjdjdjdjdjdjdjdjdjdkii dldjdmdjdndjdodjdpdjdqdjdrdjdsdjdtdjdudjdvdjdwdjdxdjdydjdzdjd{djd|djdjdjd}djdjdjdjdjdjdjdjdjdjdjd~djdjddjdjdjdjddddddid	d	|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     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|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggddit
          ddddddddddddddii dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          dt          t          t          t          t          t          dt          t          t           t          t          t          t          t          t          d	dd          S )Nr(   CoinlistUSv1i,  FCORSspotTmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreatePostOnlyOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderdeposit	editOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCanceledOrdersfetchClosedOrderfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositsWithdrawalsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrderfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersfetchOrderTradesfetchPositionfetchPositionsfetchPositionsRiskfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTradingLimitsfetchTransactionFeefetchTransactionFeesfetchTransactionsfetchTransfersfetchWithdrawalfetchWithdrawalsfetchWithdrawalWhitelistreduceMargin)
repayCrossMarginrepayIsolatedMarginsetLeverage	setMarginsetMarginModesetPositionModesignIntransferwithdrawws1m5m30m)r   r   r   zwhttps://github-production-user-asset-6210df.s3.amazonaws.com/1294454/281108917-eff2ae1d-ce8a-4b2a-950d-8678b12da965.jpgzhttps://trade-api.coinlist.co)publicprivatezhttps://coinlist.cozhttps://trade-docs.coinlist.cozhttps://coinlist.co/fees)logoapiwwwdocfeesget   )z
v1/symbolszv1/symbols/summaryzv1/symbols/{symbol}zv1/symbols/{symbol}/summaryzv1/symbols/{symbol}/bookzv1/symbols/{symbol}/quotezv1/symbols/{symbol}/candleszv1/symbols/{symbol}/auctionsz+v1/symbols/{symbol}/auctions/{auction_code}zv1/timez	v1/assetszv1/leaderboardzv1/affiliate/{competition_code}zv1/competition/{competition_id}zv1/feeszv1/accountszv1/accounts/{trader_id}zv1/accounts/{trader_id}/aliaszv1/accounts/{trader_id}/ledgerzv1/accounts/{trader_id}/walletsz%v1/accounts/{trader_id}/wallet-ledgerz&v1/accounts/{trader_id}/ledger-summaryv1/keyszv1/fills	v1/ordersv1/orders/{order_id}
v1/reportszv1/balanceszv1/transferszv1/userz
v1/credits)zv1/positions$v1/accounts/{trader_id}/competitions)r   r   zv1/orders/cancel-all-afterr   zv1/transfers/to-walletzv1/transfers/from-walletzv1/transfers/internal-transferzv1/transfers/withdrawal-requestv1/orders/bulkr   z*v1/accounts/{trader_id}/create-competition)r   r   )zv1/keys/{key}r   r   r   )r   postpatchdeletetradingz0.0045z0.0025020000z0.00350000100000z0.002500000z0.00187500001000000z0.00162500000z0.00135000000z0.001210000000z0.00150000000z0.0005	100000000z0.0015z0.0008z0.0007z0.0006z0.0000z0.00)takermaker)feeSide	tierBased
percentager   r   tiersaccountsByTypefunding)zCoinList ProzCoinList Pro trading accountProprotrader   CoinListzCoinList walletWalletwalletfundr   AUTH_SIG_INVALIDDENIED_MAINTENANCEORDER_REJECT_BAD_STATUSORDER_REJECT_INVALID_POST_ONLYORDER_REJECT_INVALID_CLOSE_ONLYORDER_REJECT_POST_ONLY_REQUIREDORDER_REJECT_FROZEN_ORDER-ORDER_REJECT_LIMIT_PRICE_PROTECTION_VIOLATIONORDER_REJECT_CLOSEDORDER_REJECT_MAX_ORDERSORDER_REJECT_NOT_FOUNDORDER_REJECT_PARSE_ERRORORDER_REJECT_PRICE_INVALIDORDER_REJECT_QUANTITY_ZEROORDER_REJECT_TOKEN_LIMITORDER_REJECT_TOKEN_LIMIT_OTHERORDER_REJECT_SELF_TRADE)!ORDER_VALIDATE_BAD_SIZE_ALIGNMENT!ORDER_VALIDATE_BAD_TICK_ALIGNMENTORDER_VALIDATE_SYMBOL_NOT_FOUND&TRANSFERS_WITHDRAWAL_REQUEST_TOO_LARGEWITHDRAWAL_REQUEST_NOT_ALLOWED)	z8A destinationAddress is required for non-USD withdrawalsz6fails to match the JsonSchema date-time format patternzis requiredzmust be a stringzmust be a valid GUIDz must be greater than or equal tozmust be less than or equal tozmust be one ofzSymbol not found)exactbroad)idname	countriesversion	rateLimit	certifiedr   has
timeframesurlsr   r   precisionModeoptions
exceptions)deep_extendsuperr(   describeparse_numberr%   r   r$   r!   r#   r   r"   r   r   r   r    r   )self	__class__s    S/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/coinlist.pyr   zcoinlist.describe   ss   h 5 5 > > @ @``` %` 	`
 %` %` U` "4` t` ` $U`  ` '` t` &t`  (!`" '#` `$ (%`& "4'`( 5)`* T+`,  -`. /`0  1`2 &u3`4 +E5`6 )%7`8 &t9`: #E;`< $T=`> '?`@ (A`B "4C`D E` ` `F &uG`H (I`J 1%K`L  M`N +DO`P *5Q`R +ES`T &uU`V #EW`X *5Y`Z $U[`\ "5]`^ *5_`` +Ea`b #Ec`d te`f  g` ` `h %ei`j +Ek`l m`n !%o`p  q`r ds`t +Eu`v !%w`x "4y`z d{`| !$}`~ "5`@ tA`B #DC`D  E`F !%G`H %eI` ` `J )%K`L uM`N tO`P Q`R TS`T tU`V "5W`X #DY`Z %e[`\ &u]`^ '_`` $Ta`b !$c`d "5e`f #Eg`h +Ei`j k` `l %*',$"!&#(  ` ` `D   R=>  -4 3  &'.//07845567889GH#$%&*+;<;< &!1%q 21 8	
 9! :1 @ A! "1 #A $Q / %a &q '  "1!" %a#$ )*@A'  , $%%&67&'2345:;;<*+@AFG  12*+ 
 *+%&01*+	 O- -'A AF $!%"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..w779J9J79S9ST!..w779J9J89T9TU!..x88$:K:KG:T:TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mg<V<VW!..z::D<M<Mh<W<WX!..{;;T=N=Nx=X=XY" "..s33T5F5Fx5P5PQ!..w779J9J89T9TU!..w779J9J89T9TU!..x88$:K:KG:T:TU!..x88$:K:KH:U:UV!..x88$:K:KH:U:UV!..y994;L;LW;U;UV!..y994;L;LX;V;VW!..y994;L;LX;V;VW!..z::D<M<Mh<W<WX!..z::D<M<Mh<W<WX!..{;;T=N=Nv=V=VW" $ $&N ' !$-4=$$&( )'0''%(# #$&(;(- .| 5l	
 6| 6| 0 D\ *< .z -m /
 1, 1, /0A  5l!" .|#$ :F9E7@>O6F-  2 Q_NX#4(2,68B5?&0(1
 
5% %k[C
 [C
 [ [ [	    c                     t          |t                    r3t          |          }t          t	          j        |dz                      S dS )N   r   )
isinstancelistlenintmathceil)r   r   methodpathparamsconfiglengths          r   calculate_rate_limiter_costz$coinlist.calculate_rate_limiter_cost<  s@    fd## 	.[[Fty!,,---qr   c                     |                      |          }|                     |d          }|                     |          S )ac  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-system-time
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        iso)publicGetV1Timesafe_string	parse8601)r   r   responsestrings       r   
fetch_timezcoinlist.fetch_timeB  s@     ''// !!(E22~~f%%%r   returnc                    |                      |          }|                     |dg           }i }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |dd          }	|	}
|	}|	}|                     |d          }|                     |                     |                    }|                     |d          }|||||||
d|ddd	|dd	d
i d||<   |S )a,  
        fetches all available currencies on an exchange
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-supported-assets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        assetsr   assetis_transferableFdecimal_placesmin_withdrawalNminmax)amountr   )r   coder   infoactiver@   r   fee	precisionlimitsnetworks)	publicGetV1Assets
safe_valueranger   r   safe_currency_code	safe_boolr   parse_precision)r   r   r   
currenciesresulticurrencyr   r
  isTransferablewithdrawEnableddepositEnabledr  decimalPlacesr  minWithdrawals                   r   fetch_currencieszcoinlist.fetch_currenciesS  sN    ))&11. __Xx<<
q#j//** 	 	A!!}H!!(G44B**2..D!^^H6GOON,O+N#F ,,X7GHHM))$*>*>}*M*MNNI ,,X7GHHM  )+&&*488(5d C C   F4LL  r   c                     |                      |          }|                     |dg           }|                     |          S )a%  
        retrieves data on all markets for coinlist
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        symbols)publicGetV1Symbolsr  parse_markets)r   r   r   marketss       r   fetch_marketszcoinlist.fetch_markets  sB     **6224 //(Ir::!!'***r   c                    |                      |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }|                      |d          }|                      |d          }|                      |d          }	i d|d|dz   |z   d	|d
|dd d|d|dd dddddddddddddddddd d d d d d d |                     |          |                     |          dd d dd d dd d dd d dd|                     |	          |d
S )Nsymbolbase_currencyquote_currencyminimum_size_incrementminimum_price_increment	list_timer   /basequotesettlebaseIdquoteIdsettleIdtyper.   Tr/   Fr0   r1   r2   r  contractlinear)r	  pricer  )leverager	  r8  cost)
inversecontractSizeexpiryexpiryDatetimestrike
optionTyper  r  createdr  )r   r  r   r   )
r   marketr   r2  r3  r/  r0  amountPrecisionpricePrecisionrA  s
             r   parse_marketzcoinlist.parse_market  s:   fh//!!&/::""6+;<<&&v..''00**63KLL))&2KLL""6;770
"0
dSj5(0
 D0
 U	0

 d0
 f0
 w0
 0
 F0
 D0
 e0
 E0
 e0
 e0
 d0
  !0
" d#0
$  "++O<<**>::    
   
   
    $ ~~g.._0
 0
 0
 0	
r   Nr"  c                     |                                   i }|                     |                     ||                    }|                     |||          S )a$  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-symbol-summaries
        :param str[] [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>`
        )load_marketspublicGetV1SymbolsSummaryextendparse_tickers)r   r"  r   requesttickerss        r   fetch_tickerszcoinlist.fetch_tickers  sV     	00Wf1M1MNN. !!'7F;;;r   r(  c                     |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-market-summary
        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r(  r   )rG  rB  publicGetV1SymbolsSymbolSummaryrI  parse_ticker)r   r(  r   rB  rK  tickers         r   fetch_tickerzcoinlist.fetch_ticker  sr     	V$$fTl
 55dkk'66R6RSS*   000r   rB  c                    |                      |di           }|                     |                     |d                    }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d	          }|                     |d
          }|                     i d|d         d|d|                     |          dd d|	d|
d|d|dd d|dd dd dd dd d|dd d|||d|          S )N
last_tradelogicalTimehighest_bid
lowest_askvolume_base_24hvolume_quote_24hhighest_price_24hlowest_price_24h
last_priceprice_change_percent_24hr(  	timestampdatetimeopenhighlowclosebid	bidVolumeask	askVolumevwappreviousClosechanger   average
baseVolume)quoteVolumer  )r  r   r   safe_tickeriso8601)r   rQ  rB  	lastTrader^  rd  rf  rl  rm  ra  rb  rc  
changePcnts                r   rP  zcoinlist.parse_ticker6  s   * OOFL"==	NN4#3#3I}#M#MNN	v}55v|44%%f.?@@
&&v/ABB(;<<v'9::  66%%f.HII
 !
fX&!
!
 Y//!
 D	!

 D!
 3!
 U!
 3!
 !
 3!
 !
 D!
 T!
 d!
 *!
  t!!
" *#!
$ ''!
 !
 !
( )  	r   limitc                 H   |                                   |                     |          }d|d         i}|                     |                     ||                    }|                     |                     |d                    }|                     |||          }d|d<   |S )aa  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-order-book-level-2
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return(default 100, max 200)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r(  r   logical_timeNnonce)rG  rB  publicGetV1SymbolsSymbolBookrI  r   r   parse_order_book)	r   r(  rr  r   rB  rK  r   rt  	orderbooks	            r   fetch_order_bookzcoinlist.fetch_order_bookk  s     	V$$fTl
 44T[[&5Q5QRR$ ~~d&6&6x&P&PQQ))(FLII	!	'r   r   sincec                     |                                   |                     |          }|                     | j        |          }|d         |d}||                     |          |d<   |H|                     |          dz  }	|                     |                     ||	|z                      |d<   n*|                     |                                           |d<   |                     |dd          }
|
0| 	                    |ddg          }|                     |
          |d<   | 
                    |                     ||                    }|                     |d	g           }|                     |||||          S )
a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-candles
        :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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   )r(  granularityN
start_timei  end_timetilluntilcandles)rG  rB  r   r   ro  parse_timeframesummillisecondssafe_integer_2omitpublicGetV1SymbolsSymbolCandlesrI  	safe_listparse_ohlcvs)r   r(  	timeframerz  rr  r   rB  r|  rK  durationr  r   r  s                r   fetch_ohlcvzcoinlist.fetch_ohlcv  s}    	V$$&&t	BBTl&
 
 $(LL$7$7GL! //	::TA&*ll488E8uCU3V3V&W&W
##&*ll43D3D3F3F&G&G
###FFG<<YYv'899F"&,,u"5"5GJ77GV8T8TUU2 ..9b99  &)UEJJJr   c           	      (   |                      |                     |d                    |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r            )r   r   safe_number)r   ohlcvrB  s      r   parse_ohlcvzcoinlist.parse_ohlcv  s     NN4++E15566UA&&UA&&UA&&UA&&UA&&
 	
r   c                    |                                   |                     |          }d|d         i}||                     |          |d<   |t          |d          |d<   |                     |dd          }|0|                     |ddg          }|                     |          |d	<   |                     |                     ||                    }|                     |d
g           }	| 	                    |	|||          S )a  
        get the list of most recent trades for a particular symbol
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-auctions
        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r(  r   Nr}  i  countr  r  r~  auctions)
rG  rB  ro  r  r  r   publicGetV1SymbolsSymbolAuctionsrI  r  parse_trades)
r   r(  rz  rr  r   rB  rK  r  r   r  s
             r   fetch_tradeszcoinlist.fetch_trades  s
    	V$$fTl
 $(LL$7$7GL!"5#GG##FFG<<YYv'899F"&,,u"5"5GJ88Wf9U9UVV2 >>(J;;  65%@@@r   c                 4   |                      |d          }|                     ||          }|d         }|                      |d          }|                     |                      |d                    }|                      |d          }|                     |dd          }|                      |d          }	d }
d }|                      |d          }|Jt	          j        |d	          }|rd
}t	          j        |          }nd}||                      |d          d}
n0|                      |d          }t	          j        |d	          rd}nd
}|                      |d          }|                     ||	||                     |          |d ||||d |
|d|          S )Nr(  auction_codert  r8  volumequantityorder_idr  r   sellbuyfee_currencyr:  r  	imbalancefee_type)r   orderr^  r_  r(  r5  sidetakerOrMakerr8  r	  r:  r  r  )	r   safe_marketr   safe_string_2r&   	string_lt
string_neg
safe_tradero  )r   r   rB  marketIdr(  r   r^  priceStringamountStringr  r  r  feeCostamountIsNegativer  r  s                   r   parse_tradezcoinlist.parse_trade  s   4 ##E844!!(F33!e^44NN4#3#3E>#J#JKK	&&ug66))%:FF  
33""5%00&0sCC &1,?? ,,UNCC CC
 ((<<I C00 ''z::"Y//( " 
  
   	r   c           
         |                                   |                     |          }|                     |di           }i }t          |                                          }t          dt          |                    D ]}||         }|                     ||i           }|                     |          }	|                     |di           }
|                     |
di           }|                    d          }t          dt          |                    D ]c}||         }| 	                    |          }|d         }i }|||<   ||| 
                    |d          | 
                    |d          d	d	|	d
||<   d|S )a[  
        fetch the trading fees for multiple markets
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-fees
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        fees_by_symbolsr   r/  r   ,r(  r   r   T)r  r(  r   r   r   r   r   )rG  privateGetV1Feesr  r   keysr  r   parse_fee_tierssplitr  r  )r   r   r   r   r  groupsOfSymbolsr  groupfeeTiersr   	firstTierfirstTierFeesidsjr   rB  r(  r  s                     r   fetch_trading_feeszcoinlist.fetch_trading_fees[  s    	((00r x):B??tyy{{++q#o..// 	 	A#A&EtUB77H((22E&"==I OOIvrBBM++c""C1c#hh''  V))"--)&U $!--mWEE!--mWEE"&!%"" "v r   c                 Z   g }g }t          |                                          }t          |          }|dk    rt          d|          D ]}||         }|                     ||i           }	|                     |	di           }
|                     |
d          }|                     |
d          }|                    d |                     |          g           |                    d |                     |          g           |                     |dd          }|                     |dd          }| 	                    |dg           }| 	                    | di           }| 	                    |di           }| 	                    |di           }| 
                    |dg           }| 
                    |dg           }t          |          }t          |          }||k    rG|dk    rAt          d|          D ]0}||         d         ||         d<   ||         d         ||         d<   1||d	S )
Nr   r   r   r   r   Tr   r   )r   r   )r   r  r   r  r  r   appendr   sort_by	safe_dictr  )r   r  rB  	takerFees	makerFeesr  
keysLengthr  keytiertierFeesr   r   r  exchangeFeesexchangeFeesTradingexchangeFeesTradingTiersexchangeFeesTradingTiersTakerexchangeFeesTradingTiersMaker#exchangeFeesTradingTiersTakerLengthfirstTierLengths                        r   r  zcoinlist.parse_fee_tiers  sF   f 		HMMOO$$YY
>>1j)) C C1gxb99??4<<((7;;((7;;  $(9(9%(@(@!ABBB  $(9(9%(@(@!ABBBBY488IY488Iy!R88I>>$;;L"&..y""M"M'+~~6I7TV'W'W$,0NN;SU\^`,a,a),0NN;SU\^`,a,a)256S2T2T/!)nnOAAAZ[H[H[q*-- J JA&CA&Fq&IIaLO&CA&Fq&IIaLOO
 
 	
r   c                     |                                   |                     |          }|                     |dg           }|                     ||          S )an  
        fetch all the accounts associated with a profile
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-accounts
        :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
        accounts)rG  privateGetV1Accountsr  parse_accounts)r   r   r   r  s       r   fetch_accountszcoinlist.fetch_accounts
  sV     	,,V44 ??8Z<<""8V444r   c                 8    |                      |d          dd |dS )N	trader_idr   )r   r5  r
  r  r   )r   accounts     r   parse_accountzcoinlist.parse_account   s/     ""7K88	
 
 	
r   c                 ~    |                                   |                     |          }|                     |          S )ap  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-balances
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        )rG  privateGetV1Balancesparse_balance)r   r   r   s      r   fetch_balancezcoinlist.fetch_balance.  s=     	,,V44!!(+++r   c                    |d d d}|                      |di           }|                      |di           }t          |                                          }t          dt	          |                    D ]k}||         }|                     |          }|                                 }	|                     ||          |	d<   |                     ||d          |	d<   |	||<   l|                     |          S )N)r  r^  r_  asset_balancesasset_holdsr   totalr   used)	r  r   r  r  r   r  r  r   safe_balance)
r   r   r  totalBalancesusedBalancescurrencyIdsr  
currencyIdr
  r  s
             r   r  zcoinlist.parse_balance9  s     
 

 2BBGGxCC=--//00q#k**++ 	# 	#A$QJ**:66DllnnG#//zJJGG"..|ZMMGFO"F4LL  (((r   c                    |                                   i }d}| |                     |          }|d         |d<   ||                     |          |d<   |||d<   |                     |dd          }|0|                     |ddg          }|                     |          |d<   |                     |                     ||                    }|                     |d	g           }	|                     |	|||          S )
af  
        fetch all trades made by the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-fills
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr   r(  r}  r  r  r  r~  fills)	rG  rB  ro  r  r  privateGetV1FillsrI  r  r  )
r   r(  rz  rr  r   rK  rB  r  r   r  s
             r   fetch_my_tradeszcoinlist.fetch_my_tradesX  s    	[[((F &tGH$(LL$7$7GL!$GG##FFG<<YYv'899F"&,,u"5"5GJ))$++gv*F*FGG: x"55  u===r   r   c           	      b    d|i}|                      ||||                     ||                    S )a"  
        fetch all the trades made from a single order
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-fills
        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        r  )r  rI  )r   r   r(  rz  rr  r   rK  s          r   fetch_order_tradeszcoinlist.fetch_order_trades  s:     
 ##FE5$++gv:V:VWWWr   c                 6   |                                   |                     |d          }|g d}d|i}d}| |                     |          }|d         |d<   ||                     |          |d<   |||d<   |                     |dd	          }|0|                     |dd	g          }|                     |          |d
<   |                     |                     ||                    }	|                     |	dg           }
| 	                    |
|||          S )a\  
        fetches information on multiple orders made by the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param string|str[] [params.status]: the status of the order - 'accepted', 'done', 'canceled', 'rejected', 'pending'(default ['accepted', 'done', 'canceled', 'rejected', 'pending'])
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        statusN)accepteddonecanceledrejectedpendingr   r(  r}  r  r  r  r~  orders)
rG  r   rB  ro  r  r  privateGetV1OrdersrI  r  parse_orders)r   r(  rz  rr  r   r  rK  rB  r  r   r  s              r   fetch_orderszcoinlist.fetch_orders  s<    	!!&(33>LLLFf
 [[((F &tGH$(LL$7$7GL!$GG##FFG<<YYv'899F"&,,u"5"5GJ**4;;w+G+GHH6 (B77  >>>r   c                     |                                   d|i}|                     |                     ||                    }|                     |          S )a  
        fetches information on an order made by the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-specific-order-by-id
        :param int|str id: order id
        :param str symbol: not used by coinlist fetchOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  )rG  privateGetV1OrdersOrderIdrI  parse_orderr   r   r(  r   rK  r   s         r   fetch_orderzcoinlist.fetch_order  s[     	
 11$++gv2N2NOO2 )))r   c           	          |                                   ddi}|                     ||||                     ||                    S )aw  
        fetch all unfilled currently open orders
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of open order structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  rG  r  rI  r   r(  rz  rr  r   rK  s         r   fetch_open_orderszcoinlist.fetch_open_orders  L     	j
   t{{7F7S7STTTr   c           	          |                                   ddi}|                     ||||                     ||                    S )a  
        fetches information on multiple closed orders made by the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of closed order structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  r  s         r   fetch_closed_orderszcoinlist.fetch_closed_orders  sL     	f
   t{{7F7S7STTTr   c           	          |                                   ddi}|                     ||||                     ||                    S )a  
        fetches information on multiple canceled orders made by the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-orders
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of canceled order structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  r  s         r   fetch_canceled_orderszcoinlist.fetch_canceled_orders(  r  r   c                     |                                   d}i }| |                     |          }|d         |d<   |                     |                     ||                    }|g}|                     ||          S )ak  
        cancel open orders of market
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#cancel-all-orders
        :param str symbol: unified market symbol
        :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(  )rG  rB  privateDeleteV1OrdersrI  r  )r   r(  r   rB  rK  r   r  s          r   cancel_all_orderszcoinlist.cancel_all_orders9  s     	[[((F &tGH--dkk'6.J.JKK   000r   c                     |                                   d|i}|                     |                     ||                    }|                     |          S )a  
        cancels an open order
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#cancel-specific-order-by-id
        :param str id: order id
        :param str symbol: not used by coinlist cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  )rG  privateDeleteV1OrdersOrderIdrI  r  r  s         r   cancel_orderzcoinlist.cancel_orderQ  s[     	
 44T[[&5Q5QRR )))r   c                 \    |                                   |}|                     |          }|S )a  
        cancel multiple orders
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#cancel-specific-orders
        :param str[] ids: order ids
        :param str symbol: not used by coinlist cancelOrders()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        )rG  privateDeleteV1OrdersBulk)r   r  r(  r   r   s        r   cancel_orderszcoinlist.cancel_ordersh  s3     	11&99r   r5  r  r	  r8  c                    |                                   |                     |          }|d         |||                     ||          d}d}	|dk    s|dk    s|dk    r9|t          | j        dz   |z   d	z             |                     ||          |d
<   nd}	d}
|                     |	d|          \  }
}|
rd|d<   |                     |g d          }|I|                     |g d          }|                     ||          |d<   |dk    rd|d<   n;|dk    rd|d<   n/|dk    s|dk    s|dk    s|dk    rt          | j        dz             | 	                    |dd          }|||d<   |                     |ddg          }| 
                    |                     ||                    }|                     |di           }|                     ||          S )an  
        create a trade order
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#create-new-order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'stop_market' or 'stop_limit' or 'take_market' or 'take_limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.postOnly]: if True, the order will only be posted to the order book and not executed immediately(default False)
        :param float [params.triggerPrice]: only for the 'stop_market', 'stop_limit', 'take_market' or 'take_limit' orders(the price at which an order is triggered)
        :param str [params.clientOrderId]: client order id(default None)
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   )r(  r5  r  sizeFrr  
stop_limit
take_limitNz/ createOrder() requires a price argument for a z orderr8  T	post_only)triggerPricetrigger_price	stopPrice
stop_price)r  r  r  r  rB  stop_marketr5  take_marketzR createOrder() requires a stopPrice parameter for stop-loss and take-profit ordersclientOrderId	client_idr  )rG  rB  amount_to_precisionr   r   price_to_precisionhandle_post_onlysafe_number_nr  r  privatePostV1OrdersrI  r  r  )r   r(  r5  r  r	  r8  r   rB  rK  isMarketpostOnlyr  r  r   r  s                  r   create_orderzcoinlist.create_orderv  sO    	V$$Tl,,VV<<	
 
 GOO!5!54<;O;O}'2c(cfj(jmu(uvvv#66vuEEGGH005&II& 	(#'GK ))&2n2n2noo#YYv'U'U'UVVF$($;$;FL$Q$QGL!x"/".m##)=)=4=CXCX^bfr^r^r#DG  /C  %C  D  D  D**6?KPP$#0GK YYv'EFFF++DKK,H,HII x"55v...r   c                 p   |                                   |t          | j        dz             |                     |          }||||                     ||          d}	||                     ||          |	d<   |                     |                     |	|                    }
|                     |
|          S )a  
        create a trade order
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#modify-existing-order
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit' or 'stop_market' or 'stop_limit' or 'take_market' or 'take_limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz( editOrder() requires an amount argument)r  r5  r  r  r8  )	rG  r   r   rB  r   r!  privatePatchV1OrdersOrderIdrI  r  )r   r   r(  r5  r  r	  r8  r   rB  rK  r   s              r   
edit_orderzcoinlist.edit_order  s     	>#DG.X$XYYYV$$,,VV<<	
 
 #66vuEEGG33DKK4P4PQQ&111r   c           	      2   |                      |d          }|                      |d          }|                     ||          }|                      |d          }|                     |dd          }||                      |d          }|                     |          }|                     |                      |d                    }|                     |                      |d                    }	|                      |d	          }
|                      |d
          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                      |d          }|                     |d          }d }||d         |d d}|                     i d|d|d|d|                     |          dd d|d|d         d|	ddd	|
d
|d|d|d|d|dd d|d |d ||d|          S ) Nr  r(  r  
created_atepoch_timestampr^  r  r5  r  r8  r  average_fill_pricer  size_filled	fill_feesr  r0  )r  r:  rater   r  r_  lastTradeTimestamptimeInForceGTCr  r  rk  r	  r:  filled)	remainingr  tradesr  r&  )	r   r  r  r   parse_order_statusparse_order_typer  
safe_orderro  )r   r  rB  r   r  r  timestampStringr^  r  r5  r  r8  r  rk  r	  r5  r  r&  r  s                      r   r  zcoinlist.parse_order  s   T eZ00##E844!!(F33((<<,,ULBSTT""..ukBBONN?33	(()9)9%)J)JKK$$T%5%5eV%D%DEEv..  00$$UL99	""5*>??!!%00!!%77""5+66??5+66"7O C
   
" 
] 
  
 Y//	 

 !$ 
 f 
 fX& 
 D 
 5 
 D 
 U 
  
 I 
 w 
 f 
  D! 
" f# 
$  - 
  
  
. /  	r   c                 @    dddddd}|                      |||          S )Nr`  r  closedr  )r  r  r  r  r  r  r   r  statusess      r   r8  zcoinlist.parse_order_statusO  s7    ""
 
 &&999r   c                 B    ddddddd}|                      |||          S )NrB  rr  )rB  rr  r  r  r  r  r  r>  s      r   r9  zcoinlist.parse_order_typeY  s:    #!#!
 
 &&999r   r
  fromAccount	toAccountc                    |                                   |                     |          }|                     ||          }|d         |d}|                     | j        di           }|                     |||          }	|                     |||          }
d}|	dk    r0|
dk    r*|                     |                     ||                    }ni|	dk    r0|
dk    r*|                     |                     ||                    }n3|	|d<   |
|d<   | 	                    |                     ||                    }| 
                    ||          }|S )	a  
        transfer currency internally between wallets on the same account
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-between-entities
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-from-wallet-to-pro
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#transfer-funds-from-pro-to-wallet
        :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://docs.ccxt.com/#/?id=transfer-structure>`
        r   )r  r	  r   Nr   r   from_trader_idto_trader_id)rG  r  currency_to_precisionr  r   r    privatePostV1TransfersFromWalletrI  privatePostV1TransfersToWallet&privatePostV1TransfersInternalTransferparse_transfer)r   r
  r	  rA  rB  r   r  rK  r   fromAcctoAccr   r   s                r   r   zcoinlist.transferd  sd    	==&&++D&99d^
 
 7GLL"">;LL  IFFy  u	'9'9<<T[[RX=Y=YZZHH"")););::4;;wPV;W;WXXHH(/G$%&+GN#BB4;;wX^C_C_``H &&x::r   c                    |                                   d}||                     |          }i }||                     |          |d<   |||d<   |                     |dd          }|0|                     |ddg          }|                     |          |d<   |                     |                     ||                    }|                     |dg           }	|                     |	|||          S )a  
        fetch a history of internal transfers between CoinList.co and CoinList Pro. It does not return external deposits or withdrawals
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#list-transfers
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfer structures to retrieve(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        Nr}  r  r  r  r~  	transfers)	rG  r  ro  r  r  privateGetV1TransfersrI  r  parse_transfers)
r   r
  rz  rr  r   r  rK  r  r   rN  s
             r   fetch_transferszcoinlist.fetch_transfers  s     	}}T**H$(LL$7$7GL!$GG##FFG<<YYv'899F"&,,u"5"5GJ--dkk'6.J.JKK. NN8["==	##IxFFFr   r  c                 2   |                      |d          }|                      |d          }|                     |          }|                      |d          }|                      |d          }d }d }	d }
|It          j        |d          }|rd}d}	t          j        |          }nd}d}	|                     |          }
||                      |d          ||                     |          |                     ||          |
||	|                     |          d		S )
Nr  confirmed_atr  r	  r   r   r   transfer_id)	r  r   r^  r_  r  r	  rA  rB  r  )	r   r   r&   r  r  r   ro  r  parse_transfer_status)r   r   r  r  confirmedAt
timetstampr  r  rA  rB  r	  r  s               r   rJ  zcoinlist.parse_transfer  s6   2 %%h88
&&x@@^^K00
!!(H55''(;;	#&0sCC &'%	&1,??'%	&&|44F""8];;#Z00//
HEE&"0088

 

 
	
r   c                 8    ddi}|                      |||          S )N	confirmedokr  r>  s      r   rU  zcoinlist.parse_transfer_status  s(    
 &&999r   c                    |t          | j        dz             |                     |dd          }|t          | j        dz             |                                  |                     |          }|d         |d}|||d<   |                     |ddg          }|                     |                     ||                    }|                     ||||          S )	a  
        fetch history of deposits and withdrawals from external wallets and between CoinList Pro trading account and CoinList wallet
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-coinlist-wallet-ledger
        :param str [code]: unified currency code for the currency of the deposit/withdrawals
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal
        :param int [limit]: max number of deposit/withdrawals to return(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nz4 fetchDepositsWithdrawals() requires a code argumentr  traderIdzF fetchDepositsWithdrawals() requires a traderId argument in the paramsr   )r  r  r  )	r   r   r  rG  r  r  (privateGetV1AccountsTraderIdWalletLedgerrI  parse_transactions)	r   r
  rz  rr  r   r\  r  rK  r   s	            r   fetch_deposits_withdrawalsz#coinlist.fetch_deposits_withdrawals  s     <#DG.d$deee%%fk:FF#DG.v$vwww==&&d^!
 
 $GG6K#<==@@WV\A]A]^^\ &&x5%HHHr   c                 @   |                                   |                     |          }|d         |                     ||          |d}|                     |                     ||                    }|                     |di           }	|                     |	|          S )aJ  
        request a withdrawal from CoinList wallet.(Disabled by default. Contact CoinList to apply for an exception.)
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#request-withdrawal-from-wallet
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r   )r  r	  destination_addressdata)rG  r  rF  'privatePostV1TransfersWithdrawalRequestrI  r  parse_transaction)
r   r
  r	  addresstagr   r  rK  r   rb  s
             r   r   zcoinlist.withdrawL  s     	==&&d^00v>>#*
 

 ??GU[@\@\]] ~~h33%%dH555r   c                 j   |                      |d          }|                     ||          }|                     |dd          }|                     |d          }|                     |                      |d                    }|                      |dd           }|d}n|                     |          }d }	|                      |d          }
|
|
|d	}	i d
|d|dd d|d|                     |          dd dd dd dd dd dd dd d|d|d|dd dd |	|                      |d          d dS )Nr  r   rT  r	  r,  r5  
withdrawalwithdrawal_fee_amountr  r  txidr^  r_  networkaddressFromre  	addressTotagFromrf  tagTor  r  updateddescription)r  commentinternal)r   r  r  r  r   parse_transaction_typero  )r   transactionr  r  r
  r   r	  r^  r5  r  r  s              r   rd  zcoinlist.parse_transactiong  s   & %%k7;;
&&z8<<T=AA!!+x88NN4#3#3K#N#NOO	VT::<DD..t44D"";0GHH  C
K
"
 D
 	

 Y//
 t
 4
 t
 
 t
 4
 T
 D
 f
 
  d!
" t#
$ '']CC)
 
 
 	
r   c                 <    dddd}|                      |||          S )Nr@   rh  r   )CRYPTO_DEPOSITCRYPTO_WITHDRAWALPRO_TRANSFERr  r   r5  typess      r   rt  zcoinlist.parse_transaction_type  s1    '!-&
 

 tT222r   c                 x   |                      |dd          }|t          | j        dz             |                                  d|i}d}||                     |          }||                     |          |d<   |||d<   |                     |dd          }|0|                     |ddg          }|                     |          |d	<   |                     |ddg          }|                     | 	                    ||                    }	| 
                    |	d
g           }
|                     |
|||          S )a  
        fetch the history of changes, actions done by the user or operations that altered balance of the user
        :see: https://trade-docs.coinlist.co/?javascript--nodejs#get-account-history
        :param str code: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entrys to return(default 200, max 500)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
        r  r\  Nz9 fetchLedger() requires a traderId argument in the paramsr}  r  r  r  r~  transactions)r  r   r   rG  r  ro  r  r  "privateGetV1AccountsTraderIdLedgerrI  r  parse_ledger)r   r
  rz  rr  r   r\  rK  r  r  r   ledgers              r   fetch_ledgerzcoinlist.fetch_ledger  sV    %%fk:FF#DG.i$ijjj
 }}T**H$(LL$7$7GL!$GG##FFG<<YYv'899F"&,,u"5"5GJ6K#<==::4;;wPV;W;WXXD >2>>  5%@@@r   c                 .   |                      |d          }|                      |d          }|                     |          }|                      |d          }t          j        |d          }d }|rd}t          j        |          }nd}|                      |d          }	|                     |	|          }
|                     |                      |d                    }||||                     |          |d	d d ||
|                     |          d d d
d dS )Ntransaction_idr,  r	  r   outinr  r5  r   rZ  )r  r   r^  r_  	directionr  referenceIdreferenceAccountr5  r  r	  beforeafterr  r  )	r   r   r&   r  r  r  parse_ledger_entry_typero  r   )r   itemr  r   	createdAtr^  r	  r  r  r  r
  r5  s               r   parse_ledger_entryzcoinlist.parse_ledger_entry  s5   N d$455$$T<88	NN9--	!!$11",VS99	 	I'//FFI%%dG44
&&z8<<++D,<,<T6,J,JKK"Y//"  $''//
 
 	
r   c                 >    ddddd}|                      |||          S )Nr   r  r   )zatomic token swapr  r@   rh  r  rz  s      r   r  z coinlist.parse_ledger_entry_typet  s4    !(!$	
 
 tT222r   r   GETc                    |                      ||                     |                    }d|                     ||          z   }| j        d         |         |z   }	|                     |          }
|dk    r|                                  t          |                                           }||z   |z   }t          |t                    }|dk    s|dk    s|r| 
                    |          }||z  }n#t          |
          dk    r|d|
z   z  }|	d|
z   z  }	|                     |                     |          |                     | j                  t           j        d          }| j        ||d	d
}nt          |
          dk    r|	d|
z   z  }	|	|||dS )Nr.  r   r   POSTPATCHr   ?base64zapplication/json)zCL-ACCESS-KEYzCL-ACCESS-SIGzCL-ACCESS-TIMESTAMPzContent-Type)urlr   bodyheaders)r  extract_paramsimplode_paramsr   	urlencodecheck_required_credentialsstrsecondsr   r   jsonr   hmacencodebase64_to_binarysecrethashlibsha256apiKey)r   r   r   r   r   r  r  rK  endpointr  queryr^  authisBulk	signatures                  r   signzcoinlist.sign}  s   ))FD$7$7$=$=>>,,T6:::is#h.w'')++---DLLNN++Iv%0D--F&  f&7&7F&7yy))Uqe#sU{"		$++d"3"3T5J5J4;5W5WY`YgiqrrI!%!*'0 2	 GG ZZ1__3;CfdwOOOr   c
                 d   |o|dk    rg|                     d          dk    rN|dk    rH|                    d          }
|                     |
d          }t          | j        dz   |z   dz             d S |                     |d          }|                     |d	          }|||d
k    r|dk    r|dk    r||dk    rv| j        dz   |z   }|                     |d          }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Ni  z/orders/r   r  r   z order z, not found(or rejected on the exchange side)r  message_code      200202 messager   r   )	findr  r   r"   r   throw_broadly_matched_exceptionr   throw_exactly_matched_exceptionr   )r   r
  reasonr  r   r  r  r   requestHeadersrequestBodypartsorderIdresponseCodemessageCodefeedbackr  s                   r   handle_errorszcoinlist.handle_errors  sr    #((:"6"6!";";&E//		*--**5!44#DGi$7'$ADr$rsss4''(;;&&x@@#,*BQT[_cf[f[fmy  ~C  nC  nC  JV  Z_  J_  J_w}t+H&&x;;G001I7T\]]]001I;X`aaa)))tr   )N)K__name__
__module____qualname__r   r   r   r   r   r   r
   r&  rE  r   r   rM  r  r   rR  rP  r	   r   ry  r   r  r  r   r  r  r   r  r  r   r  r  r   r  r  r   r  r  r   r  r   r  r  r	  r  r  r  r   r   floatr   r'  r*  r  r8  r9  r   r   rQ  r   rJ  rU  r   r_  r   rd  rt  r  r  r  r  r  __classcell__)r   s   @r   r(   r(      s       \ \ \ \ \| MO     !# & & & &" ') ; ;Z ; ; ; ;z $& "+ "+$v, "+ "+ "+ "+H9
f 9
 9
 9
 9
v 04B !< !<W !<7 !< !< !< !<F 02 "1 "13 "1f "1 "1 "1 "1H3 36 3V 3 3 3 3j :>b # #s #3 #Y # # # #J 26DW[df 8K 8K# 8Kc 8KQT 8Kkoptku 8K 8K 8K 8Kt
 
 
4 
 
 
 
* 6:UW 2A 2A3 2As 2A# 2A\`af\g 2A 2A 2A 2AhF F F5 F F F FP )+ Z Z{ Z Z Z ZxQ
 Q
 Q
 Q
 Q
 Q
f %' 5 54= 5 5 5 5,
 
 
 $& 	, 	,( 	, 	, 	, 	,) ) ) ) )> -1tRV_a 7> 7>c 7> 7>C 7> 7> 7> 7>r 9=4^bkm X XS X# XS XX[ Xrvw|r} X X X X  *.Dt\^ ;? ;?3 ;?c ;? ;?cghmcn ;? ;? ;? ;?z 26b &* &*c &*3 &* &* &* &*P /3TXac U U U3 Uc Uhlmrhs U U U U" 154VZce U U# US UPS Ujnotju U U U U" 37TX\eg U UC Us URU U U U U" /32 1 1 1 1 1 10 37r * *s *C * * * *. 04B       gksu @/ @/3 @/i @/y @/RW @/`c @/ @/ @/ @/D `drv  @B 2 2S 2# 2Y 2i 2Y\ 2lo 2 2 2 26z z z5 z z z zx: : :	: 	: 	: [] / /S /% /c /c /an / / / /b +/TPT]_ 0G 0GC 0Gs 0G# 0G 0G 0G 0Gd5
 5
 5
 5
 5
 5
n: : : 6:[_hj FI FIs FI# FIUX FIost  pA FI FI FI FIP ?C2 6 6S 6% 6 6 6 669
 9
x 9
; 9
 9
 9
 9
v3 3 3 (,$TZ\ aA aA aAC aAs aA aA aA aAFe
 e
 e
 e
 e
 e
N3 3 3 &eBSW P P P P6      r   r(   ).ccxt.base.exchanger   ccxt.abstract.coinlistr   r  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    r!   r"   r#   r$   ccxt.base.decimal_to_precisionr%   ccxt.base.preciser&   r(    r   r   <module>r     s   ( ' ' ' ' ' . . . . . .   M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) * * * * * * 4 4 4 4 4 4 % % % % % %P" P" P" P" P"x P" P" P" P" P"r   