
    ei'                         d dl Zd dlmZmZ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 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j         j!                  Z!dS )    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesBool
CurrenciesIntNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFees)Client)List)ExchangeError)AuthenticationError)ArgumentsRequiredc                       e Zd Zdef fdZi fdZi fdefdZi fdedefdZ	di fd	e
defd
ZdefdZdi fd	e
defdZdefdZdRdZddi fdedededee         fdZ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efdZdefdZdi fdededefdZd Zd ZdefdZdefdZ d Z!defdZ"defd Z#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i fded$e)d%e*d&e+d'e,de&fd(Z-ddi fd)eded$e)d%e*d&e,d'e,de&fd*Z.di fd)ede%fd+Z/di fde%fd,Z0defd-Z1di fd)ede%de&fd.Z2dddi fde%dededee&         fd/Z3d0 Z4d1 Z5dddi fde%dededee&         fd2Z6dddi fde%dededee         fd3Z7defd4Z8di fd5ed&e+d6ed7e%fd8Z9defd9Z:dddi fd5e%dedefd:Z;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d5e%dedefd=Z>defd>Z?i fde@fd?ZAi fd@ZBi fdeCfdAZDdefdBZEdC ZFi fdeGfdDZHdefdEZIdefdFZJdefdGZKi fdHZLi fdIZMi fdJZNdefdKZOdefdLZPdefdMZQi fdNZRdefdOZSdedeTfdPZUdefdQZV xZWS )Sbitvavoreturnc           
      l   |                      t          t          |                                           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d%did&dd'iidd(d(d(d)d*          S )+NwsTcancelOrdersWsFfetchTradesWswatchOrderBookwatchTradeswatchTickerwatchTickerswatchBidsAsks
watchOHLCVwatchOrderswatchMyTradescancelAllOrdersWscancelOrderWscreateOrderWscreateStopLimitOrderWscreateStopMarketOrderWscreateStopOrderWseditOrderWsfetchBalanceWsfetchCurrenciesWSfetchDepositAddressWsfetchDepositsWsfetchDepositWithdrawFeesWsfetchMyTradesWsfetchOHLCVWsfetchOpenOrdersWsfetchOrderWsfetchOrderBookWsfetchOrdersWsfetchTickerWsfetchTickersWsfetchTimeWsfetchTradingFeesWsfetchWithdrawalsWs
withdrawWsapizwss://ws.bitvavo.com/v2  )supressMultipleWsRequestsErrortradesLimitordersLimit
OHLCVLimit)hasurlsoptions)deep_extendsuperr   describe)self	__class__s    N/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/bitvavo.pyrM   zbitvavo.describe   s*   gt 4 4 = = ? ?$d$ %$  $ !$	$
 t$ t$ $  $ d$ t$  $ $T$  $  $ )$$  *4!$" $T#$ $$ t%$& !$'$( $T)$* (+$, "4-$. -e/$0 "41$2 3$4 $T5$6 7$8 #E9$:  ;$<  =$> !%?$@ uA$B %dC$D %dE$ $F dG$ $L 3 38##"	 W1B
 1B
 1 1 1	    c                 .  K   |                                   d {V  |                     |          }|dz   |d         z   }| j        d         d         }d||d         gdgd}|                     ||          }|                     ||||           d {V S )N@idrB   r   	subscribenamemarketsactionchannels)load_marketsmarketrI   extendwatch)	rN   rW   symbolparamsr]   messageHashurlrequestmessages	            rP   watch_publiczbitvavo.watch_publicG   s      !!!!!!!!!V$$Sj6$</it$! !t  

 

 ++gv..ZZ[';GGGGGGGGGrQ   channelNamec                   K   |                                   d {V  |                     |          }|g}g }t          dt          |                    D ]8}|                     ||                   }|                    |d                    9| j        d         d         }	d||dgd}
|                     |
|          }|                     |	|||           d {V S )Nr   rT   rB   r   rU   rV   rY   )	r\   market_symbolsrangelenr]   appendrI   r^   watch_multiple)rN   
methodNamerg   symbolsra   messageHashesargsir]   rc   rd   re   s               rP   watch_public_multiplezbitvavo.watch_public_multipleZ   s     !!!!!!!!!%%g..#q#g,,'' 	& 	&A[[,,FKKt%%%%it$! (# 
 
 ++gv..((mWmTTTTTTTTTrQ   r`   c                 @   K   |                      d||           d{V S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post

        :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>`
        	ticker24hN)rf   )rN   r`   ra   s      rP   watch_tickerzbitvavo.watch_tickero   s2       &&{FFCCCCCCCCCrQ   Nro   c                    K   |                                   d{V  |                     |dd          }d}|                     ||||           d{V }|                     |d|          S )a  
        watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

        https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post

        :param str[] [symbols]: 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>`
        NFru   r`   r\   ri   rs   filter_by_arrayrN   ro   ra   channeltickerss        rP   watch_tickerszbitvavo.watch_tickers{   s       !!!!!!!!!%%gtU;;227GWfUUUUUUUU##GXw???rQ   clientc                    |                      ||           |                     |d          }|                     |dg           }g }t          dt	          |                    D ]}||         }|                     |d          }|                     |d d          }	|dz   |z   }
|                     ||	          }|d         }|| j        |<   |                    |           |	                    ||
           |	                    ||           d S )Neventdatar   r]   -rS   r`   )
handle_bid_asksafe_string
safe_valuerj   rk   safe_marketparse_tickerr|   rl   resolve)rN   r~   re   r   r|   resultrr   r   marketIdr]   rb   tickerr`   s                rP   handle_tickerzbitvavo.handle_ticker   s   , 	FG,,,  '22//'6266q#g,,'' 		0 		0A1:D''h77H%%hc::F#+0K&&tV44FH%F#)DL MM&!!!NN6;////vu%%%%%rQ   c                    K   |                                   d{V  |                     |dd          }d}|                     d|||           d{V }|                     |d|          S )a  
        watches best bid & ask for symbols

        https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post

        :param str[] symbols: 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>`
        NFru   bidaskr`   rx   rz   s        rP   watch_bids_askszbitvavo.watch_bids_asks   s       !!!!!!!!!%%gtU;;228WgvVVVVVVVV##GXw???rQ   c                 l   d}|                      |dg           }g }t          dt          |                    D ]d}||         }|                     |          }|d         }	|| j        |	<   |                    |           |dz   |	z   }
|                    ||
           e|                    ||           d S )Nr   r   r   r`   :)r   rj   rk   parse_ws_bid_askbidsasksrl   r   )rN   r~   re   r   r|   r   rr   r   r   r`   rb   s              rP   r   zbitvavo.handle_bid_ask   s    //'6266q#g,,'' 	0 	0A1:D**400FH%F$*DM&!MM&!!!#+.KNN6;////vu%%%%%rQ   c                    |                      |d          }|                     |d d          }|                      |d          }|                     |d          }|                     |||                     |          |                     |d          |                     |d          |                     |d          |                     |d          |d	|          S )
Nr]   r   r`   	timestampaskaskSizebidbidSize)r`   r   datetimer   	askVolumer   	bidVolumeinfo)r   r   safe_integersafe_tickeriso8601safe_number)rN   r   r]   r   r`   r   s         rP   r   zbitvavo.parse_ws_bid_ask   s    ##FH55!!(D#66!!&(33%%fk::	"Y//##FE22))&)<<##FE22))&)<<	!
 	!
 	 	 		rQ   sincelimitc                 
  K   |                                   d{V  |                     |          }|                     d||           d{V }| j        r|                    ||          }|                     |||dd          S )a  
        get the list of most recent trades for a particular symbol
        :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
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Ntradesr   T)r\   r`   rf   
newUpdatesgetLimitfilter_by_since_limit)rN   r`   r   r   ra   r   s         rP   watch_tradeszbitvavo.watch_trades   s       !!!!!!!!!V$$((66BBBBBBBB? 	3OOFE22E))&%TRRRrQ   c                    |                      |d          }|                     |d d          }|d         }d}|dz   |z   }|                     ||          }|                     | j        |          }	|	+|                     | j        dd          }
t          |
          }	|	                    |           |	| j        |<   |	                    |	|           d S )Nr]   r   r`   r   rS   rE   rC   )
r   r   parse_trader   r   r   rJ   r   rl   r   )rN   r~   re   r   r]   r`   rW   rb   tradetradesArrayr   s              rP   handle_tradezbitvavo.handle_trade   s     ##GX66!!(D#66!Sj8+  &11oodk6::%%dlM4HHE$U++K5!!!)F{K00000rQ   1m	timeframec                   K   |                                   d{V  |                     |          }|d         }d}|d         }|                     | j        ||          }	|dz   |z   dz   |	z   }
| j        d         d         }d	d|	g|gd
gd}|                     ||          }|                     ||
||
           d{V }| j        r|                    ||          }| 	                    |||dd          S )aQ  
        watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr`   candlesrT   rS   _rB   r   rU   )rW   intervalrX   rY   r   T)
r\   r]   r   
timeframesrI   r^   r_   r   r   r   )rN   r`   r   r   r   ra   r]   rW   r   r   rb   rc   rd   re   ohlcvs                  rP   watch_ohlcvzbitvavo.watch_ohlcv	  s;      !!!!!!!!!V$$!$<##DOY	JJSj8+c1H<it$! &!)
 (z 	
 	
 ++gv..jjk7KHHHHHHHH? 	2NN6511E))%q$GGGrQ   c                     |                      |d          }|                     |d d d           }|                     |d          }|                    ||           d S Nresponse	requestId)r   parse_ohlcvsr   r   )rN   r~   re   r   r   rb   s         rP   handle_fetch_ohlcvzbitvavo.handle_fetch_ohlcv+  s_     ??7J77!!(D$==&&w<<uk*****rQ   c                    d}|                      |d          }|                     |d d          }|d         }|                      |d          }|                     |          }|dz   |z   dz   |z   }	|                     |d          }
|                     | j        |i           | j        |<   |                     | j        |         |          }|;|                     | j        d	d
          }t          |          }|| j        |         |<   t          dt          |
                    D ]5}|
|         }| 
                    ||          }|                    |           6|                    ||	           d S )Nr   r]   r   r`   r   rS   r   candlerG   rC   r   )r   r   find_timeframer   ohlcvsr   rJ   r   rj   rk   parse_ohlcvrl   r   )rN   r~   re   rW   r   r]   r`   r   r   rb   r   storedr   rr   r   parseds                   rP   handle_ohlcvzbitvavo.handle_ohlcv:  sr   $ ##GX66!!(D#66!##GZ88''11	Sj8+c1H<//'844"oodk62FFFV!4i@@>%%dlL$GGE*511F-3DK	*q#g,,'' 	" 	"AQZF%%ff55FMM&!!!!v{+++++rQ   c                   K   |                                   d{V  |                     |          }|d         }d}|dz   |d         z   }| j        d         d         }d||d         gd	gd
}||||d         | j        ||d}	|                     ||          }
|                     |||
||	           d{V }|                                S )a  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nr`   bookrS   rT   rB   r   rU   rV   rY   )rb   rW   r`   r   methodr   ra   )r\   r]   rI   handle_order_book_subscriptionr^   r_   r   )rN   r`   r   ra   r]   rW   rb   rc   rd   subscriptionre   	orderbooks               rP   watch_order_bookzbitvavo.watch_order_booka  s      !!!!!!!!!V$$!Sj6$</it$! !t  

 

 't9
 
 ++gv..**S+w\ZZZZZZZZ	   rQ   c                     |                      |d          }|                      |d          }|                    ||           d S )Nr      )
safe_floatstore)rN   booksidedeltapriceamounts        rP   handle_deltazbitvavo.handle_delta  sB    q))**uf%%%%%rQ   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )rj   rk   r   )rN   r   deltasrr   s       rP   handle_deltaszbitvavo.handle_deltas  sH    q#f++&& 	3 	3Ahq	2222	3 	3rQ   c                    |                      |d          }||d         k    rg|                     |d         |                     |dg                      |                     |d         |                     |dg                      ||d<   |S )Nnonceasksbids)r   r   r   )rN   r~   re   r   r   s        rP   handle_order_book_messagez!bitvavo.handle_order_book_message  s     !!'7339W%%%y0$//'6SU2V2VWWWy0$//'6SU2V2VWWW!&IgrQ   c                    |                      |d          }|                      |d          }|                     |d d          }|d         }|dz   |d         z   }|                     | j        |          }|d S |d         |                     |j        |i           }	|                     |	d          }
|
ed	|	d<   |	|j        |<   |                     | j        d
i           }|                     |d| j                  }|                     || j	        |||	           |j
                            |           d S |                     |||           |                    ||           d S )Nr   r]   r   r`   rS   rT   r   watchingOrderBookSnapshotTwatchOrderBookSnapshotdelay)r   r   r   
orderbookssubscriptionsrJ   r   	rateLimitr   watch_order_book_snapshotcacherl   r   r   )rN   r~   re   r   r   r]   r`   rb   r   r   r   rJ   r   s                rP   handle_order_bookzbitvavo.handle_order_book  su      '22##GX66!!(D#66!ckF4L0OODOV<<	FW%??6+?bQQL(,Fa(b(b%(0<@894@$[1//$,8PRTUU))'7DNKK

5$"@&'S_```O""7+++++**67IFFFNN9k22222rQ   c                 0  K   |                      |d          }|                     |d          }d}|dz   |z   }| j        d         d         }||d}	|                     |||                     |	|          ||           d {V }
|
                                S )Nra   r   getBookrS   rB   r   )rZ   r]   )r   r   rI   r_   r^   r   )rN   r~   re   r   ra   r   rW   rb   rc   rd   r   s              rP   r   z!bitvavo.watch_order_book_snapshot  s      x88##L*==Sj8+it$
 
 **S+t{{7F7S7SU`bnoooooooo	   rQ   c                    |                      |d          }|d S |                     |d          }|                     |d d          }d}|dz   |z   }| j        |         }|                     ||          }	|                     |d          |	d<   |                    |	           |j        }
t          dt          |
                    D ]!}|
|         }| 
                    |||           "|| j        |<   |                    ||           d S )Nr   r]   r   r   rS   r   r   )r   r   safe_symbolr   parse_order_bookr   resetr   rj   rk   r   r   )rN   r~   re   r   r   r`   rW   rb   r   snapshotmessagesrr   messageItems                rP   handle_order_book_snapshotz"bitvavo.handle_order_book_snapshot  s    ( ??7J77F##Hh77!!(D#66Sj8+OF+	((6:: --h@@!!!?q#h--(( 	K 	KA"1+K**6;	JJJJ"+y+.....rQ   c                     |                      |d          }|                     |d          }|| j        v r| j        |= |                     i |          | j        |<   d S )Nr`   r   )r   r   r   
order_book)rN   r~   re   r   r`   r   s         rP   r   z&bitvavo.handle_order_book_subscription  sc    !!,99!!,88T_$$'"&//"e"<"<rQ   c                 F   d}t          dt          |                    D ]}|                     ||          }|                     |d d          }|dz   |z   }|| j        vr@|                     |j        |          }	|                     |	d          }
|
 |
|||	           d S )Nr   r   r   rS   r   )rj   rk   r   r   r   r   r   )rN   r~   re   	marketIdsrW   rr   r   r`   rb   r   r   s              rP   handle_order_book_subscriptionsz'bitvavo.handle_order_book_subscriptions  s    q#i..)) 	: 	:A''	155H%%hc::F*x/Kdo--#v/C[QQx@@%F67L999	: 	:rQ   c                   K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     |          }|d         }|d         }| j        d         d         }d}d|z   }	d	||gd
gd}
|                     ||	|
|	           d{V }| j        r|                    ||          }| 	                    ||||d          S )a  
        watches information on multiple orders made by the user
        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz) watchOrders() requires a symbol argumentr`   rT   rB   r   accountorder:rU   rV   rY   T
r   rT   r\   authenticater]   rI   r_   r   r   filter_by_symbol_since_limit)rN   r`   r   r   ra   r]   r   rc   rW   rb   rd   orderss               rP   watch_orderszbitvavo.watch_orders  s;      >#DG.Y$YZZZ!!!!!!!!!!!!!!!!!!V$$!$<it$'! ! (z 
 
 zz#{G[IIIIIIII? 	3OOFE22E00tTTTrQ   c                   K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     |          }|d         }|d         }| j        d         d         }d}d|z   }	d	||gd
gd}
|                     ||	|
|	           d{V }| j        r|                    ||          }| 	                    ||||d          S )a  
        watches information on multiple trades made by the user
        :param str symbol: unified market symbol of the market trades were made in
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trade structures 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>`
        Nz+ watchMyTrades() requires a symbol argumentr`   rT   rB   r   r   	myTrades:rU   rV   rY   Tr   )rN   r`   r   r   ra   r]   r   rc   rW   rb   rd   r   s               rP   watch_my_tradeszbitvavo.watch_my_trades2  s;      >#DG.[$[\\\!!!!!!!!!!!!!!!!!!V$$!$<it$!F*! ! (z 
 
 zz#{G[IIIIIIII? 	3OOFE22E00tTTTrQ   typesider   r   c                    K   |                                   d{V  |                                  d{V  |                     ||||||          }|                     d|           d{V S )aB  
        create a trade order

        https://docs.bitvavo.com/#tag/Orders/paths/~1order/post

        :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 bitvavo api endpoint
        :param str [params.timeInForce]: "GTC", "IOC", or "PO"
        :param float [params.stopPrice]: The price at which a trigger order is triggered at
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param bool [params.postOnly]: If True, the order will only be posted to the order book and not executed immediately
        :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
        :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
        :param str [params.triggerType]: "price"
        :param str [params.triggerReference]: "lastTrade", "bestBid", "bestAsk", "midPrice" Only for stop orders: Use self to determine which parameter will trigger the order
        :param str [params.selfTradePrevention]: "decrementAndCancel", "cancelOldest", "cancelNewest", "cancelBoth"
        :param bool [params.disableMarketProtection]: don't cancel if the next fill price is 10% worse than the best fill price
        :param bool [params.responseRequired]: Set self to 'false' when only an acknowledgement of success or failure is required, self is faster.
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NprivateCreateOrder)r\   r   create_order_requestwatch_request)rN   r`   r  r  r   r   ra   rd   s           rP   create_order_wszbitvavo.create_order_wsS  s      2 !!!!!!!!!!!!!!!!!!++FD$vVV''(<gFFFFFFFFFrQ   rT   c           	         K   |                                   d{V  |                                  d{V  |                     |||||||          }|                     d|           d{V S )a  
        edit a trade order

        https://docs.bitvavo.com/#tag/Orders/paths/~1order/put

        :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 bitvavo api endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NprivateUpdateOrder)r\   r   edit_order_requestr  )	rN   rT   r`   r  r  r   r   ra   rd   s	            rP   edit_order_wszbitvavo.edit_order_wsq  s       !!!!!!!!!!!!!!!!!!))"fdD&%QWXX''(<gFFFFFFFFFrQ   c                    K   |                                   d{V  |                                  d{V  |                     |||          }|                     d|           d{V S )a  

        https://docs.bitvavo.com/#tag/Orders/paths/~1order/delete

        cancels an open order
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        NprivateCancelOrder)r\   r   cancel_order_requestr  )rN   rT   r`   ra   rd   s        rP   cancel_order_wszbitvavo.cancel_order_ws  s       !!!!!!!!!!!!!!!!!!++B??''(<gFFFFFFFFFrQ   c                   K   |                                   d{V  |                                  d{V  i }d}| |                     |          }|d         |d<   |                     d|                     ||                     d{V S )a  

        https://docs.bitvavo.com/#tag/Orders/paths/~1orders/delete

        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 bitvavo api endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NrT   r]   privateCancelOrders)r\   r   r]   r  r^   )rN   r`   ra   rd   r]   s        rP   cancel_all_orders_wszbitvavo.cancel_all_orders_ws  s       !!!!!!!!!!!!!!!!!![[((F &tGH''(=t{{7TZ?[?[\\\\\\\\\rQ   c                     |                      |d          }|                     |          }|                     |d          }|                    ||           d S r   )	safe_listparse_ordersr   r   )rN   r~   re   r   r   rb   s         rP   handle_multiple_orderszbitvavo.handle_multiple_orders  s]     >>':66 ""8,, &&w<<v{+++++rQ   c                 @  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     |          }||d         d}|                     d|                     ||                     d{V S )a  

        https://docs.bitvavo.com/#tag/General/paths/~1assets/get

        fetches information on an order made by the user
        :param str id: the order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nz( fetchOrder() requires a symbol argumentrT   )orderIdr]   privateGetOrder)r   rT   r\   r   r]   r  r^   )rN   rT   r`   ra   r]   rd   s         rP   fetch_order_wszbitvavo.fetch_order_ws  s       >#DG.X$XYYY!!!!!!!!!!!!!!!!!!V$$Tl
 
 ''(94;;wPV;W;WXXXXXXXXXrQ   c                 8  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a,  

        https://docs.bitvavo.com/#tag/Orders/paths/~1orders/get

        fetches information on multiple orders made by the user
        :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  orde structures to retrieve
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        Nz+ fetchOrdersWs() requires a symbol argumentprivateGetOrders)r   rT   r\   r   fetchOrdersRequestr  r   )rN   r`   r   r   ra   rd   r   s          rP   fetch_orders_wszbitvavo.fetch_orders_ws  s       >#DG.[$[\\\!!!!!!!!!!!!!!!!!!))&%GG))*<gFFFFFFFF00NNNrQ   c                     t          |                                           }|                     d          }t          |          }t          ||z             S )N   )strmillisecondsrand_numberint)rN   tsrandomNumber
randomParts       rP   
request_idzbitvavo.request_id  sM    ""$$%%''**&&
2
?###rQ   c                    K   |                                  }t          |          }||d<   ||d<   | j        d         d         }|                     ||||           d {V S )NrZ   r   rB   r   )r)  r"  rI   r_   )rN   rZ   rd   rb   messageHashStrrc   s         rP   r  zbitvavo.watch_request  sq      oo''[))"*it$ZZ^WnMMMMMMMMMrQ   c                 J  K   |                                   d{V  |                                  d{V  i }d}| |                     |          }|d         |d<   |                     d|                     ||                     d{V }|                     ||||          S )a  
        fetch all unfilled currently open 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 orders structures to retrieve
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NrT   r]   privateGetOrdersOpen)r\   r   r]   r  r^   r   )rN   r`   r   r   ra   rd   r]   r   s           rP   fetch_open_orders_wszbitvavo.fetch_open_orders_ws  s       !!!!!!!!!!!!!!!!!!
 [[((F &tGH))*@$++gW]B^B^________00NNNrQ   c                 8  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a  

        https://docs.bitvavo.com/#tag/Trades

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nz- fetchMyTradesWs() requires a symbol argumentprivateGetTrades)r   rT   r\   r   fetchMyTradesRequestr  r   )rN   r`   r   r   ra   rd   myTradess          rP   fetch_my_trades_wszbitvavo.fetch_my_trades_ws	  s       >#DG.]$]^^^!!!!!!!!!!!!!!!!!!++FE5&II++,>HHHHHHHH0065%PPPrQ   c                     |                      |d          }|                     |d d d           }|                     |d          }|                    ||           d S r   )r  parse_tradesr   r   )rN   r~   re   r   r   rb   s         rP   handle_my_tradeszbitvavo.handle_my_trades  s_    . >>':66""8T4>>&&w<<v{+++++rQ   codeaddresstagc                 4  K   |                      ||          \  }}|                     |           |                                  d{V  |                                  d{V  |                     |||||          }|                     d|           d{V S )a  
        make a withdrawal
        :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 bitvavo api endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/?id=transaction-structure>`
        NprivateWithdrawAssets)handle_withdraw_tag_and_paramscheck_addressr\   r   withdrawRequestr  )rN   r7  r   r8  r9  ra   rd   s          rP   withdraw_wszbitvavo.withdraw_ws;  s       99#vFFV7###!!!!!!!!!!!!!!!!!!&&tVWc6JJ''(?IIIIIIIIIrQ   c                     |                      |d          }|                     |d          }|                     |          }|                    ||           d S Nr   r   )r   r   parse_transactionr   )rN   r~   re   rb   r   withdraws         rP   handle_withdrawzbitvavo.handle_withdrawL  sY     &&w<<??7J77))(33x-----rQ   c                   K   |                                   d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a  

        https://docs.bitvavo.com/#tag/Account/paths/~1withdrawalHistory/get

        fetch all withdrawals made from an account
        :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 bitvavo api endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        NprivateGetWithdrawalHistory)r\   r   fetchWithdrawalsRequestr  filter_by_currency_since_limit)rN   r7  r   r   ra   rd   	withdrawss          rP   fetch_withdrawals_wszbitvavo.fetch_withdrawals_ws^  s       !!!!!!!!!!!!!!!!!!..tUE6JJ,,-JGTTTTTTTT	229dE5QQQrQ   c                     |                      |d          }|                     |d          }|                     |d d d ddi          }|                    ||           d S )Nr   r   r  
withdrawal)r  r   parse_transactionsr   )rN   r~   re   r   rb   withdrawalss         rP   handle_withdrawszbitvavo.handle_withdrawsp  sg    $ >>':66&&w<<--hdD6S_J`aa{K00000rQ   c                    K   |                                   d{V  |                     |||||          }d}|                     ||           d{V }|                     |||dd          S )a  

        https://docs.bitvavo.com/#tag/Market-Data/paths/~1{market}~1candles/get

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :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 bitvavo api endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        N
getCandlesr   T)r\   fetchOHLCVRequestr  r   )	rN   r`   r   r   r   ra   rd   rZ   r   s	            rP   fetch_ohlcv_wszbitvavo.fetch_ohlcv_ws  s       !!!!!!!!!((E5&QQ((99999999))%q$GGGrQ   c                   K   |                                   d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a  

        https://docs.bitvavo.com/#tag/Account/paths/~1depositHistory/get

        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 bitvavo api endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        NprivateGetDepositHistory)r\   r   fetchDepositsRequestr  rH  )rN   r7  r   r   ra   rd   depositss          rP   fetch_deposits_wszbitvavo.fetch_deposits_ws  s       !!!!!!!!!!!!!!!!!!++D%GG++,FPPPPPPPP228T5%PPPrQ   c                     |                      |d          }|                     |d d d ddi          }|                     |d          }|                    ||           d S )Nr   r  depositr   )r   rM  r   r   )rN   r~   re   r   rW  rb   s         rP   handle_depositszbitvavo.handle_deposits  sg      ??7J77**8T4PYGZ[[&&w<<x-----rQ   c                    K   |                                   d{V  |                                  d{V  |                     d|           d{V S )aQ  

        https://docs.bitvavo.com/#tag/Account/paths/~1account/get

        fetch the trading fees for multiple markets
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/?id=fee-structure>` indexed by market symbols
        NprivateGetAccountr\   r   r  rN   ra   s     rP   fetch_trading_fees_wszbitvavo.fetch_trading_fees_ws  y       !!!!!!!!!!!!!!!!!!''(;VDDDDDDDDDrQ   c                 >   K   |                      d|           d{V S )a  

        https://docs.bitvavo.com/#tag/General/paths/~1markets/get

        retrieves data on all markets for bitvavo
        :param dict [params]: extra parameters specific to the exchange api endpoint
        :returns dict[]: an array of objects representing market data
        
getMarketsN)r  r_  s     rP   fetch_markets_wszbitvavo.fetch_markets_ws  s0       ''f=========rQ   c                 r   K   |                                   d{V  |                     d|           d{V S )a  

        https://docs.bitvavo.com/#tag/General/paths/~1assets/get

        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns dict: an associative dictionary of currencies
        N	getAssets)r\   r  r_  s     rP   fetch_currencies_wszbitvavo.fetch_currencies_ws  sT       !!!!!!!!!''V<<<<<<<<<rQ   c                     |                      |d          }|                     |d          }|                     |          }|                    ||           d S rA  )r   r   parse_currenciesr   )rN   r~   re   rb   r   
currenciess         rP   handle_fetch_currencieszbitvavo.handle_fetch_currencies  sY    * &&w<<??7J77**844
z;/////rQ   c                     |                      |d          }|                     |d          }|                     |          }|                    ||           d S rA  )r   r   parse_trading_feesr   )rN   r~   re   rb   r   feess         rP   handle_trading_feeszbitvavo.handle_trading_fees  sY     &&w<<??7J77&&x00t[)))))rQ   c                    K   |                                   d{V  |                                  d{V  |                     d|           d{V S )au  

        https://docs.bitvavo.com/#tag/Account/paths/~1balance/get

        query for balance and get the amount of funds available for trading or funds locked in orders
        :param dict [params]: extra parameters specific to the bitvavo api endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/en/latest/manual.html?#balance-structure>`
        NprivateGetBalancer^  r_  s     rP   fetch_balance_wszbitvavo.fetch_balance_ws  ra  rQ   c                     |                      |d          }|                     |dg           }|                     |          }|                    ||           d S rA  )r   r   parse_balancer   )rN   r~   re   rb   r   balances         rP   handle_fetch_balancezbitvavo.handle_fetch_balance  s[     &&w<<??7J;;$$X..w,,,,,rQ   c                     |                      |di           }|                     |          }|                     |d          }|                    ||           d S r   )r   parse_orderr   r   )rN   r~   re   r   orderrb   s         rP   handle_single_orderzbitvavo.handle_single_order0  s[    : ??7J;;  **&&w<<uk*****rQ   c                     |                      |di           }|                     |          }|                     |d          }|                    ||           d S r   )r   parse_marketsr   r   )rN   r~   re   r   rX   rb   s         rP   handle_marketszbitvavo.handle_marketsR  s[    ( ??7J;;$$X..&&w<<w,,,,,rQ   c                     | j         | j        | j        | j        | j         d}|                     ||          }|}| |||          }|S )N)r  r
  r  r  r0  )action_and_market_message_hash action_and_order_id_message_hashr   )rN   rZ   ra   methodsr   rb   s         rP   build_message_hashzbitvavo.build_message_hashk  sc    "&"E"&"G"&"G#D $ C
 
 &11 &00KrQ   c                 :    |                      |dd          }||z   S )Nr]    )r   )rN   rZ   ra   r`   s       rP   r  z&bitvavo.action_and_market_message_hashy  s#    !!&(B77rQ   c                 j    |                      |d          }|t          | j        dz             ||z   S )Nr  z; privateUpdateOrderMessageHash requires a orderId parameter)r   r   rT   )rN   rZ   ra   r  s       rP   r  z(bitvavo.action_and_order_id_message_hash}  s=    ""6955?*g ghhhrQ   c                    |                      |d          }|                     |d d          }|d         }d|z   }|                     ||          }| j        0|                     | j        dd          }t          |          | _        | j        }	|	                    |           |                    | j        |           d S )Nr]   r   r`   r   rF   rC   )	r   r   rx  r   r   rJ   r   rl   r   )
rN   r~   re   r   r]   r`   rb   ry  r   r   s
             rP   handle_orderzbitvavo.handle_order  s    , ##GX66!!(D#66!'  &11;%%dlM4HHE077DKet{K00000rQ   c                 x   |                      |d          }|                     |d d          }|d         }d|z   }|                     ||          }| j        0|                     | j        dd          }t          |          | _        | j        }	|	                    |           |                    |	|           d S )Nr]   r   r`   r   rE   rC   )	r   r   r   r2  r   rJ   r   rl   r   )
rN   r~   re   r   r]   r`   rb   r   r   r   s
             rP   handle_my_tradezbitvavo.handle_my_trade  s      ##GX66!!(D#66!!F*  &11= %%dlM4HHE&u--DMm5!!!{K00000rQ   c                 N   |                      |di           }d| j        i}t          |                                          }t	          dt          |                    D ]E}||         }|                      ||          }|#|                      ||          }	 ||||	           F|S )Nr   r   r   )r   r   listkeysrj   rk   )
rN   r~   re   r   r  namesrr   rW   r   r   s
             rP   handle_subscription_statusz"bitvavo.handle_subscription_status  s     "EED8
 ]''))**q#e**%% 	6 	6A8D__Wd33F!#}dCCvw555rQ   c                 .  K   | j         d         d         }|                     |          }d}|                     |j        |          }||                                 }t          |          }|dz   | j        z   dz   }|                     |                     |          |                     | j	                  t          j                  }	d}
|
| j        |	|d}|                     ||          }|                     ||||           d {V }||j        |<   |S )NrB   r   authenticatedzGET/z
/websocketr   )rZ   key	signaturer   )rI   r~   r   r   r#  r"  versionhmacencodesecrethashlibsha256apiKeyr^   r_   )rN   ra   rc   r~   rb   futurer   stringTimestampauthr  rZ   rd   re   s                rP   r   zbitvavo.authenticate  s     it$S!!%!5{CC>))++I!)nnO"V+dl:\ID		$++d"3"3T[[5M5Mw~^^I#F {&&	 G kk'622G::c;MMMMMMMMF06F -rQ   c                    d}|                      |dd          }|r|                    ||           d S t          |                     |                    }|                    ||           ||j        v r
|j        |= d S d S )Nr  F)	safe_boolr   r   jsonrejectr   )rN   r~   re   rb   r  errors         rP   handle_authentication_messagez%bitvavo.handle_authentication_message  s     &wGG 	6NN7K00000'		'(:(:;;EMM%---f222(555 32rQ   c                    |                      |d          }|                     |d          }|                      |d          }|                     ||          }|                      |d|          }d}	 |                     |||j        di ||i i 	  	         n/# t
          $ r"}	d}|                    |	|           Y d }	~	nd }	~	ww xY w|s|                    ||           dS d S )Nr  	errorCoderZ   r   Fr  T)r   r   r  handle_errorsrc   	Exceptionr  )
rN   r~   re   r  r7  rZ   buildMessagerb   rejectedes
             rP   handle_error_messagezbitvavo.handle_error_message   s       '22  44!!'844..vw??&&w\JJ	*tUFJBwPRTVWWWW 	* 	* 	*HMM![))))))))	*  	MM';///4ts   3"B 
C B==Cc           
         |                      |d          }||                     ||           i d| j        d| j        d| j        d| j        d| j        d| j        d| j        d	| j	        d
| j
        d| j        d| j        d| j        d| j        d| j        d| j        d| j        d| j        | j        | j        | j        | j        | j        | j        | j        | j        d}|                      |d          }|                     ||          }|>|                      |d          }|                     ||          }| |||           d S d S  |||           d S )Nr  
subscribedr   r   r   r   ru   r   ry  fillr  r
  rq  r  r  r  r  r-  )r]  rU  rF  r;  r0  rf  rQ  rc  r   rZ   )r   r  r  r   r   r   r   r   r  r  r  rz  rv  r  ro  r[  rO  rD  r6  rk  r   r}  r   )rN   r~   re   r  r  r   r   rZ   s           rP   handle_messagezbitvavo.handle_message   s   X   '22%%fg666
$9
D*
 t6
 T&	

 d'
 +
 D>
 T&
 D(
 !$":
 !$":
  !:
 "4#>
  ;
 t7
  !$":!
" #D$?#
$ "&!9(,(<+/+@%)%9 $ 551-3
 
 
6   '22%00>%%gx88F__Wf55F!vw''''' "! F67#####rQ   )N)X__name__
__module____qualname__r   rM   rf   r"  rs   r   rv   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   r   r  r   r   floatr   r  r  r  r  r  r  r  r)  r  r.  r3  r6  r?  rD  rJ  rO  rS  rX  r[  r   r`  rd  r	   rg  rk  ro  r   rr  rv  rz  r}  r  r  r  r  r  r  r   r  r   r  r  __classcell__)rO   s   @rP   r   r      s
       2# 2 2 2 2 2 2h 79 H H H H& Y[ U U3 U U U U* 68 
D 
D 
DF 
D 
D 
D 
D 6:" @ @7 @ @ @ @ @ $&F $& $& $& $&L 8<B @ @W @7 @ @ @ @ &V & & & &     <@d[] S S SS S Sbfglbm S S S S 16 1 1 1 14 ?CQUdhqs  H  H  H  H3  H^a  Hx|  ~B  yC  H  H  H  HD+ + + + +%,6 %, %, %, %,N @DB $! $!S $! $!S\ $! $! $! $!L& & &
3 3 3    *#3 #3 #3 #3 #3J! ! !%/ %/ %/ %/ %/N=V = = = =
:f 
: 
: 
: 
: 04$UYbd U U UC Us Uimnsit U U U UB 37TX\eg U UC Us URU Ulpqvlw U U U UB pt|~ G GC Gy G	 G[` Gil G  DI G G G G< im{  IK G Gc G3 Gi Gy Gbe Gux G  PU G G G G( <@ G G GS G G G G  8<B ] ] ] ] ] ]&,V , , , ,( ;?r Y Ys YC Ye Y Y Y Y, 37TX\eg O OC Os ORU Olpqvlw O O O O($ $ $N N N 8<$]ajl O O OC OWZ Oquv{q| O O O O* 6:[_hj Q Qs Q# QUX Qostyoz Q Q Q Q(,v , , , ,< TX`b J Jc J5 J3 JS J J J J".f . . . .$ 6:[_hj R Rs R# RUX R R R R$1v 1 1 1 1. BFTXgktv H H3 H3 Hc Had H{  AE  |F H H H H& 37TX\eg Q QC Qs QRU Q Q Q Q$.f . . . .* 24 E E E E E E -/ 	> 	> 	> 	> 02 
= 
=j 
= 
= 
= 
=0f 0 0 0 04* * *$ -/ E E8 E E E E-6 - - - -$ +&  +  +  +  +D-V - - - -2 13     =?     ?A         16  1  1  1  1D1f 1 1 1 18    , )+    ,6F 6 6 6 6&6 t    @R$V R$ R$ R$ R$ R$ R$ R$ R$rQ   r   )"ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r  ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr    rQ   rP   <module>r     s       f f f f f f f f f f  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a 4 4 4 4 4 4       * * * * * * 0 0 0 0 0 0 . . . . . .a$ a$ a$ a$ a$d ( a$ a$ a$ a$ a$rQ   