
    ":h                         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 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y)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesIntNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFees)Client)List)ExchangeError)AuthenticationError)ArgumentsRequiredc                   l    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dOd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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.Z3d/ Z4d0 Z5dddi fde%dededee&   fd1Z6dddi fde%dededee   fd2Z7defd3Z8di fd4efd5Z9defd6Z:dddi fd4e%dedefd7Z;defd8Z<dddi fdedededee   fd9Z=dddi fd4e%dedefd:Z>defd;Z?i fde@fd<ZAi fd=ZBi fd>ZCdefd?ZDd@ ZEi fdeFfdAZGdefdBZHdefdCZIdefdDZJi fdEZKi fdFZLi fdGZMdefdHZNdefdIZOdefdJZPi fdKZQdefdLZRdefdMZSdefdNZT xZUS )Pbitvavoreturnc           
      :   | j                  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    J/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/bitvavo.pyrK   zbitvavo.describe   s   gt = ?$d$ %$  $ !$	$
 t$ t$ $  $ d$ t$  $ $T$  $  $ )$$  *4!$" $T#$$ t%$& !$'$( $T)$* (+$, "4-$. -d/$0 "41$2 3$4 $T5$6 7$8 #D9$:  ;$<  =$> !$?$@ tA$B %dC$D %dE$F dG$L 3 38##"	W1B
 1 1	    c                   K   | j                          d {    | j                  |      }|dz   |d   z   }| j                  d   d   }d||d   gdgd}| j                  ||      }| j	                  ||||       d {   S 7 m7 w)N@idr@   r   	subscribenamemarketsactionchannels)load_marketsmarketrG   extendwatch)	rL   rU   symbolparamsr[   messageHashurlrequestmessages	            rN   watch_publiczbitvavo.watch_publicG   s     !!!V$Sj6$</iit$! !t 

 ++gv.ZZ[';GGG! 	"  Hs"   BBA(B?B BBchannelNamec                   K   | j                          d {    | j                  |      }|g}g }t        dt        |            D ]*  }| j	                  ||         }|j                  |d          , | j                  d   d   }	d||dgd}
| j                  |
|      }| j                  |	|||       d {   S 7 7 w)Nr   rR   r@   r   rS   rT   rW   )	rZ   market_symbolsrangelenr[   appendrG   r\   watch_multiple)rL   
methodNamere   symbolsr_   messageHashesargsir[   ra   rb   rc   s               rN   watch_public_multiplezbitvavo.watch_public_multipleZ   s     !!!%%g.#q#g,' 	&A[[,FKKt%	& iit$! (#
 ++gv.((mWmTTT% 	"$ Us"   C B<B C 7B>8C >C r^   c                 D   K   | j                  d||       d{   S 7 w)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)rd   )rL   r^   r_   s      rN   watch_tickerzbitvavo.watch_tickero   s#      &&{FFCCCCs     Nrm   c                    K   | j                          d{    | j                  |dd      }d}| j                  ||||       d{   }| j                  |d|      S 7 H7 w)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>`
        NFrs   r^   rZ   rg   rq   filter_by_arrayrL   rm   r_   channeltickerss        rN   watch_tickerszbitvavo.watch_tickers{   sm      !!!%%gtU;227GWfUU##GXw??	 	" V!   A#A0A#A!A#!A#clientc                    | j                  ||       | j                  |d      }| j                  |dg       }g }t        dt	        |            D ]}  }||   }| j                  |d      }| j                  |d d      }	|dz   |z   }
| j                  ||	      }|d   }|| j                  |<   |j                  |       |j                  ||
        |j                  ||       y )Neventdatar   r[   -rQ   r^   )
handle_bid_asksafe_string
safe_valuerh   ri   safe_marketparse_tickerrz   rj   resolve)rL   r}   rc   r   rz   resultrp   r   marketIdr[   r`   tickerr^   s                rN   handle_tickerzbitvavo.handle_ticker   s    , 	FG,  '2//'626q#g,' 		0A1:D''h7H%%hc:F#+0K&&tV4FH%F#)DLL MM&!NN6;/		0 	vu%rO   c                    K   | j                          d{    | j                  |dd      }d}| j                  d|||       d{   }| j                  |d|      S 7 H7 w)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>`
        NFrs   bidaskr^   rv   rx   s        rN   watch_bids_askszbitvavo.watch_bids_asks   sm      !!!%%gtU;228WgvVV##GXw??	 	" Wr|   c                 4   d}| j                  |dg       }g }t        dt        |            D ]W  }||   }| j                  |      }|d   }	|| j                  |	<   |j                  |       |dz   |	z   }
|j                  ||
       Y |j                  ||       y )Nr   r   r   r^   :)r   rh   ri   parse_ws_bid_askbidsasksrj   r   )rL   r}   rc   r   rz   r   rp   r   r   r^   r`   s              rN   r   zbitvavo.handle_bid_ask   s    //'626q#g,' 	0A1:D**40FH%F$*DMM&!MM&!#+.KNN6;/	0 	vu%rO   c                 h   | j                  |d      }| j                  |d d      }| j                  |d      }| j                  |d      }| j                  ||| j	                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |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)rL   r   r[   r   r^   r   s         rN   r   zbitvavo.parse_ws_bid_ask   s    ##FH5!!(D#6!!&(3%%fk:	"Y/##FE2))&)<##FE2))&)<	!
 	 		rO   sincelimitc                    K   | j                          d{    | j                  |      }| j                  d||       d{   }| j                  r|j	                  ||      }| j                  |||dd      S 7 c7 9w)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)rZ   r^   rd   
newUpdatesgetLimitfilter_by_since_limit)rL   r^   r   r   r_   r   s         rN   watch_tradeszbitvavo.watch_trades   sx      !!!V$((66BB??OOFE2E))&%TRR 	"Bs!   A>A:+A>A<8A><A>c                    | j                  |d      }| j                  |d d      }|d   }d}|dz   |z   }| j                  ||      }| j                  | j                  |      }	|	(| j                  | j                  dd      }
t        |
      }	|	j                  |       |	| j                  |<   |j                  |	|       y )Nr[   r   r^   r   rQ   rC   rA   )
r   r   parse_trader   r   r   rH   r   rj   r   )rL   r}   rc   r   r[   r^   rU   r`   tradetradesArrayr   s              rN   handle_tradezbitvavo.handle_trade   s     ##GX6!!(D#6!Sj8+  &1oodkk6:%%dllM4HE$U+K5!)F{K0rO   1mc                   K   | j                          d{    | j                  |      }|d   }d}|d   }| j                  | j                  ||      }	|dz   |z   dz   |	z   }
| j                  d   d   }d	d|	g|gd
gd}| j                  ||      }| j                  ||
||
       d{   }| j                  r|j                  ||      }| j                  |||dd      S 7 7 9w)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^   candlesrR   rQ   _r@   r   rS   )rU   intervalrV   rW   r   T)
rZ   r[   r   
timeframesrG   r\   r]   r   r   r   )rL   r^   	timeframer   r   r_   r[   rU   r   r   r`   ra   rb   rc   ohlcvs                  rN   watch_ohlcvzbitvavo.watch_ohlcv	  s     !!!V$!$<##DOOY	JSj8+c1H<iit$! &!)
 (z	
 ++gv.jjk7KHH??NN651E))%q$GG- 	"& Is"   C&C"BC&*C$+8C&$C&c                     | j                  |d      }| j                  |d d d       }| j                  |d      }|j                  ||       y Nresponse	requestId)r   parse_ohlcvsr   r   )rL   r}   rc   r   r   r`   s         rN   handle_fetch_ohlcvzbitvavo.handle_fetch_ohlcv+  sJ     ??7J7!!(D$=&&w<uk*rO   c                    d}| j                  |d      }| j                  |d d      }|d   }| j                  |d      }| j                  |      }|dz   |z   dz   |z   }	| j                  |d      }
| j                  | j                  |i       | j                  |<   | j                  | j                  |   |      }|:| j                  | j                  d	d
      }t        |      }|| j                  |   |<   t        dt        |
            D ]*  }|
|   }| j                  ||      }|j                  |       , |j                  ||	       y )Nr   r[   r   r^   r   rQ   r   candlerE   rA   r   )r   r   find_timeframer   ohlcvsr   rH   r   rh   ri   parse_ohlcvrj   r   )rL   r}   rc   rU   r   r[   r^   r   r   r`   r   storedr   rp   r   parseds                   rN   handle_ohlcvzbitvavo.handle_ohlcv:  sF   $ ##GX6!!(D#6!##GZ8''1	Sj8+c1H<//'84"oodkk62FFV!4i@>%%dllL$GE*51F-3DKK	*q#g,' 	"AQZF%%ff5FMM&!	" 	v{+rO   c                 r  K   | j                          d{    | j                  |      }|d   }d}|dz   |d   z   }| j                  d   d   }d||d   gd	gd
}||||d   | j                  ||d}	| j	                  ||      }
| j                  |||
||	       d{   }|j                         S 7 7 w)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^   bookrQ   rR   r@   r   rS   rT   rW   )r`   rU   r^   r   methodr   r_   )rZ   r[   rG   handle_order_book_subscriptionr\   r]   r   )rL   r^   r   r_   r[   rU   r`   ra   rb   subscriptionrc   	orderbooks               rN   watch_order_bookzbitvavo.watch_order_booka  s      !!!V$!Sj6$</iit$! !t 

 't99
 ++gv.**S+w\ZZ	  9 	"6 [s"   B7B3BB7B5B75B7c                 p    | j                  |d      }| j                  |d      }|j                  ||       y )Nr      )
safe_floatstore)rL   booksidedeltapriceamounts        rN   handle_deltazbitvavo.handle_delta  s0    q)*uf%rO   c                 b    t        dt        |            D ]  }| j                  |||           y )Nr   )rh   ri   r   )rL   r   deltasrp   s       rN   handle_deltaszbitvavo.handle_deltas  s0    q#f+& 	3Ahq	2	3rO   c                     | j                  |d      }||d   kD  rQ| j                  |d   | j                  |dg              | j                  |d   | j                  |dg              ||d<   |S )Nnonceasksbids)r   r   r   )rL   r}   rc   r   r   s        rN   handle_order_book_messagez!bitvavo.handle_order_book_message  sy     !!'739W%%y0$//'6SU2VWy0$//'6SU2VW!&IgrO   c                    | j                  |d      }| j                  |d      }| j                  |d d      }|d   }|dz   |d   z   }| j                  | j                  |      }|y |d   | j                  |j                  |i       }	| j                  |	d      }
|
md	|	d<   |	|j                  |<   | j                  | j
                  d
i       }| j                  |d| j                        }| j                  || j                  |||	       |j                  j                  |       y | j                  |||       |j                  ||       y )Nr   r[   r   r^   rQ   rR   r   watchingOrderBookSnapshotTwatchOrderBookSnapshotdelay)r   r   r   
orderbookssubscriptionsrH   r   	rateLimitr   watch_order_book_snapshotcacherj   r   r   )rL   r}   rc   r   r   r[   r^   r`   r   r   r   rH   r   s                rN   handle_order_bookzbitvavo.handle_order_book  sH      '2##GX6!!(D#6!ckF4L0OODOOV<	W%??6+?+?bQL(,Fa(b%(0<@894@$$[1//$,,8PRTU))'7DNNK

5$"@"@&'S_`OO""7+**67IFNN9k2rO   c                   K   | j                  |d      }| j                  |d      }d}|dz   |z   }| j                  d   d   }||d}	| j                  ||| j	                  |	|      ||       d {   }
|
j                         S 7 w)Nr_   r   getBookrQ   r@   r   )rX   r[   )r   r   rG   r]   r\   r   )rL   r}   rc   r   r_   r   rU   r`   ra   rb   r   s              rN   r   z!bitvavo.watch_order_book_snapshot  s     x8##L*=Sj8+iit$
 **S+t{{7F7SU`bnoo	   ps   A.B0B1Bc                    | j                  |d      }|y | j                  |d      }| j                  |d d      }d}|dz   |z   }| j                  |   }| j	                  ||      }	| j                  |d      |	d<   |j                  |	       |j                  }
t        dt        |
            D ]  }|
|   }| j                  |||        || j                  |<   |j                  ||       y )Nr   r[   r   r   rQ   r   r   )r   r   safe_symbolr   parse_order_bookr   resetr   rh   ri   r   r   )rL   r}   rc   r   r   r^   rU   r`   r   snapshotmessagesrp   messageItems                rN   handle_order_book_snapshotz"bitvavo.handle_order_book_snapshot  s    ( ??7J7##Hh7!!(D#6Sj8+OOF+	((6: --h@!??q#h-( 	KA"1+K**6;	J	K #,y+.rO   c                     | j                  |d      }| j                  |d      }|| j                  v r| j                  |= | j                  i |      | j                  |<   y )Nr^   r   )r   r   r   
order_book)rL   r}   rc   r   r^   r   s         rN   r   z&bitvavo.handle_order_book_subscription  sW    !!,9!!,8T__$'"&//"e"<rO   c                 *   d}t        dt        |            D ]y  }| j                  ||      }| j                  |d d      }|dz   |z   }|| j                  vs?| j                  |j                  |      }	| j                  |	d      }
|
p |
|||	       { y )Nr   r   r   rQ   r   )rh   ri   r   r   r   r   r   )rL   r}   rc   	marketIdsrU   rp   r   r^   r`   r   r   s              rN   handle_order_book_subscriptionsz'bitvavo.handle_order_book_subscriptions  s    q#i.) 	:A''	15H%%hc:F*x/Kdoo-#v/C/C[Qx@%67L9	:rO   c                   K   |t        | j                  dz         | j                          d{    | j                          d{    | j	                  |      }|d   }|d   }| j
                  d   d   }d}d|z   }	d	||gd
gd}
| j                  ||	|
|	       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 7 ;w)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^   rR   r@   r   accountorder:rS   rT   rW   T
r   rR   rZ   authenticater[   rG   r]   r   r   filter_by_symbol_since_limit)rL   r^   r   r   r_   r[   r   ra   rU   r`   rb   orderss               rN   watch_orderszbitvavo.watch_orders  s      >#DGG.Y$YZZ!!!!!!V$!$<iit$'! ! (z
 zz#{G[II??OOFE2E00tTT) 	"!  J4   .C CC C	AC "C#8C C C c                   K   |t        | j                  dz         | j                          d{    | j                          d{    | j	                  |      }|d   }|d   }| j
                  d   d   }d}d|z   }	d	||gd
gd}
| j                  ||	|
|	       d{   }| j                  r|j                  ||      }| j                  ||||d      S 7 7 7 ;w)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^   rR   r@   r   r   	myTrades:rS   rT   rW   Tr   )rL   r^   r   r   r_   r[   r   ra   rU   r`   rb   r   s               rN   watch_my_tradeszbitvavo.watch_my_trades2  s      >#DGG.[$[\\!!!!!!V$!$<iit$!F*! ! (z
 zz#{G[II??OOFE2E00tTT) 	"!  Jr   typesider   r   c                    K   | j                          d{    | j                          d{    | j                  ||||||      }| j                  d|       d{   S 7 L7 67 w)aD  
        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)rZ   r   create_order_requestwatch_request)rL   r^   r  r  r   r   r_   rb   s           rN   create_order_wszbitvavo.create_order_wsS  sj     2 !!!!!!++FD$vV''(<gFFF 	"!Fs1   A)A#A)A%/A)A'A)%A)'A)rR   c           	         K   | j                          d{    | j                          d{    | j                  |||||||      }| j                  d|       d{   S 7 M7 77 w)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)rZ   r   edit_order_requestr  )	rL   rR   r^   r  r  r   r   r_   rb   s	            rN   edit_order_wszbitvavo.edit_order_wsq  sm      !!!!!!))"fdD&%QWX''(<gFFF 	"!Fs1   A*A$A*A&0A*A( A*&A*(A*c                    K   | j                          d{    | j                          d{    | j                  |||      }| j                  d|       d{   S 7 I7 37 w)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)rZ   r   cancel_order_requestr  )rL   rR   r^   r_   rb   s        rN   cancel_order_wszbitvavo.cancel_order_ws  sd      !!!!!!++B?''(<gFFF 	"!Fs1   A&A A&A",A&A$A&"A&$A&c                   K   | j                          d{    | j                          d{    i }d}|| j                  |      }|d   |d<   | j                  d| j	                  ||             d{   S 7 e7 O7 w)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>`
        NrR   r[   privateCancelOrders)rZ   r   r[   r  r\   )rL   r^   r_   rb   r[   s        rN   cancel_all_orders_wszbitvavo.cancel_all_orders_ws  s      !!!!!![[(F &tGH''(=t{{7TZ?[\\\ 	"! ]s2   BA<BA>AB7B 8B>B Bc                     | j                  |d      }| j                  |      }| j                  |d      }|j                  ||       y r   )	safe_listparse_ordersr   r   )rL   r}   rc   r   r   r`   s         rN   handle_multiple_orderszbitvavo.handle_multiple_orders  sH     >>':6 ""8, &&w<v{+rO   c                 0  K   |t        | j                  dz         | j                          d{    | j                          d{    | j	                  |      }||d   d}| j                  d| j                  ||             d{   S 7 _7 I7 w)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 argumentrR   )orderIdr[   privateGetOrder)r   rR   rZ   r   r[   r  r\   )rL   rR   r^   r_   r[   rb   s         rN   fetch_order_wszbitvavo.fetch_order_ws  s      >#DGG.X$XYY!!!!!!V$Tl
 ''(94;;wPV;WXXX 	"! Ys4   .BBBB	ABBBBBc                 .  K   |t        | j                  dz         | j                          d{    | j                          d{    | j	                  ||||      }| j                  d|       d{   }| j                  ||||      S 7 ^7 H7 w)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   rR   rZ   r   fetchOrdersRequestr  r   )rL   r^   r   r   r_   rb   r   s          rN   fetch_orders_wszbitvavo.fetch_orders_ws  s      >#DGG.[$[\\!!!!!!))&%G))*<gFF00NN	 	"!F3   .BBBB	-B6B7BBBc                     t        | j                               }| j                  d      }t        |      }t        ||z         S )N   )strmillisecondsrand_numberint)rL   tsrandomNumber
randomParts       rN   
request_idzbitvavo.request_id  s>    ""$%''*&
2
?##rO   c                    K   | j                         }t        |      }||d<   ||d<   | j                  d   d   }| j                  ||||       d {   S 7 w)NrX   r   r@   r   )r*  r#  rG   r]   )rL   rX   rb   r`   messageHashStrra   s         rN   r  zbitvavo.watch_request  s^     oo'[)"*iit$ZZ^WnMMMMs   AAAAc                 0  K   | j                          d{    | j                          d{    i }d}|| j                  |      }|d   |d<   | j                  d| j	                  ||             d{   }| j                  ||||      S 7 y7 c7 w)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>`
        NrR   r[   privateGetOrdersOpen)rZ   r   r[   r  r\   r   )rL   r^   r   r   r_   rb   r[   r   s           rN   fetch_open_orders_wszbitvavo.fetch_open_orders_ws  s      !!!!!!
 [[(F &tGH))*@$++gW]B^__00NN 	"! `s2   BBBBAB7B8BBBc                 .  K   |t        | j                  dz         | j                          d{    | j                          d{    | j	                  ||||      }| j                  d|       d{   }| j                  ||||      S 7 ^7 H7 w)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   rR   rZ   r   fetchMyTradesRequestr  r   )rL   r^   r   r   r_   rb   myTradess          rN   fetch_my_trades_wszbitvavo.fetch_my_trades_ws	  s      >#DGG.]$]^^!!!!!!++FE5&I++,>HH0065%PP	 	"!Hr   c                     | j                  |d      }| j                  |d d d       }| j                  |d      }|j                  ||       y r   )r  parse_tradesr   r   )rL   r}   rc   r   r   r`   s         rN   handle_my_tradeszbitvavo.handle_my_trades  sJ    . >>':6""8T4>&&w<v{+rO   codec                    K   | j                  ||      \  }}| j                  |       | j                          d{    | j                          d{    | j	                  |||||      }| j                  d|       d{   S 7 K7 57 w)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_addressrZ   r   withdrawRequestr  )rL   r8  r   addresstagr_   rb   s          rN   withdraw_wszbitvavo.withdraw_ws;  s      99#vFV7#!!!!!!&&tVWc6J''(?III 	"!Is3   :BBBB
.BBB
BBc                     | j                  |d      }| j                  |d      }| j                  |      }|j                  ||       y Nr   r   )r   r   parse_transactionr   )rL   r}   rc   r`   r   withdraws         rN   handle_withdrawzbitvavo.handle_withdrawL  sD     &&w<??7J7))(3x-rO   c                    K   | j                          d{    | j                          d{    | j                  ||||      }| j                  d|       d{   }| j	                  ||||      S 7 ^7 H7 w)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)rZ   r   fetchWithdrawalsRequestr  filter_by_currency_since_limit)rL   r8  r   r   r_   rb   	withdrawss          rN   fetch_withdrawals_wszbitvavo.fetch_withdrawals_ws^  s|      !!!!!!..tUE6J,,-JGTT	229dE5QQ	 	"!T1   A;A5A;A7-A;A9A;7A;9A;c                     | j                  |d      }| j                  |d      }| j                  |d d d ddi      }|j                  ||       y )Nr   r   r  
withdrawal)r  r   parse_transactionsr   )rL   r}   rc   r   r`   withdrawalss         rN   handle_withdrawszbitvavo.handle_withdrawsp  sR    $ >>':6&&w<--hdD6S_J`a{K0rO   c                    K   | j                          d{    | j                  |||||      }d}| j                  ||       d{   }| j                  |||dd      S 7 J7 w)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)rZ   fetchOHLCVRequestr  r   )	rL   r^   r   r   r   r_   rb   rX   r   s	            rN   fetch_ohlcv_wszbitvavo.fetch_ohlcv_ws  sp      !!!((E5&Q((99))%q$GG	 	" :s!   A%A!0A%A#A%#A%c                    K   | j                          d{    | j                          d{    | j                  ||||      }| j                  d|       d{   }| j	                  ||||      S 7 ^7 H7 w)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)rZ   r   fetchDepositsRequestr  rI  )rL   r8  r   r   r_   rb   depositss          rN   fetch_deposits_wszbitvavo.fetch_deposits_ws  s|      !!!!!!++D%G++,FPP228T5%PP	 	"!PrL  c                     | j                  |d      }| j                  |d d d ddi      }| j                  |d      }|j                  ||       y )Nr   r  depositr   )r   rO  r   r   )rL   r}   rc   r   rY  r`   s         rN   handle_depositszbitvavo.handle_deposits  sR      ??7J7**8T4PYGZ[&&w<x-rO   c                    K   | j                          d{    | j                          d{    | j                  d|       d{   S 7 67  7 w)aS  

        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rZ   r   r  rL   r_   s     rN   fetch_trading_fees_wszbitvavo.fetch_trading_fees_ws  P      !!!!!!''(;VDDD 	"!D1   AAAAAA	AAAc                 B   K   | j                  d|       d{   S 7 w)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  ra  s     rN   fetch_markets_wszbitvavo.fetch_markets_ws  s!      ''f====s   c                 v   K   | j                          d{    | j                  d|       d{   S 7 7 w)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)rZ   r  ra  s     rN   fetch_currencies_wszbitvavo.fetch_currencies_ws  s9      !!!''V<<< 	"<s   959799c                     | j                  |d      }| j                  |d      }| j                  |      }|j                  ||       y rB  )r   r   parse_currenciesr   )rL   r}   rc   r`   r   
currenciess         rN   handle_fetch_currencieszbitvavo.handle_fetch_currencies  sD    * &&w<??7J7**84
z;/rO   c                     | j                  |d      }| j                  |d      }| j                  |      }|j                  ||       y rB  )r   r   parse_trading_feesr   )rL   r}   rc   r`   r   feess         rN   handle_trading_feeszbitvavo.handle_trading_fees  sD     &&w<??7J7&&x0t[)rO   c                    K   | j                          d{    | j                          d{    | j                  d|       d{   S 7 67  7 w)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`  ra  s     rN   fetch_balance_wszbitvavo.fetch_balance_ws  rc  rd  c                     | j                  |d      }| j                  |dg       }| j                  |      }|j                  ||       y rB  )r   r   parse_balancer   )rL   r}   rc   r`   r   balances         rN   handle_fetch_balancezbitvavo.handle_fetch_balance  sF     &&w<??7J;$$X.w,rO   c                     | j                  |di       }| j                  |      }| j                  |d      }|j                  ||       y r   )r   parse_orderr   r   )rL   r}   rc   r   orderr`   s         rN   handle_single_orderzbitvavo.handle_single_order0  sF    : ??7J;  *&&w<uk*rO   c                     | j                  |di       }| j                  |      }| j                  |d      }|j                  ||       y r   )r   parse_marketsr   r   )rL   r}   rc   r   rV   r`   s         rN   handle_marketszbitvavo.handle_marketsR  sF    ( ??7J;$$X.&&w<w,rO   c                     | j                   | j                  | j                  | j                  | j                   d}| j                  ||      }|}|	 |||      }|S )N)r  r
  r  r  r1  )action_and_market_message_hash action_and_order_id_message_hashr   )rL   rX   r_   methodsr   r`   s         rN   build_message_hashzbitvavo.build_message_hashk  se    "&"E"E"&"G"G"&"G"G#DD $ C C
 &1 0KrO   c                 2    | j                  |dd      }||z   S )Nr[    )r   )rL   rX   r_   r^   s       rN   r  z&bitvavo.action_and_market_message_hashy  s     !!&(B7rO   c                 d    | j                  |d      }|t        | j                  dz         ||z   S )Nr  z; privateUpdateOrderMessageHash requires a orderId parameter)r   r   rR   )rL   rX   r_   r  s       rN   r  z(bitvavo.action_and_order_id_message_hash}  s9    ""695?*g ghhrO   c                 j   | j                  |d      }| j                  |d d      }|d   }d|z   }| j                  ||      }| j                  -| j	                  | j
                  dd      }t        |      | _        | j                  }	|	j                  |       |j                  | j                  |       y )Nr[   r   r^   r   rD   rA   )	r   r   r{  r   r   rH   r   rj   r   )
rL   r}   rc   r   r[   r^   r`   r|  r   r   s
             rN   handle_orderzbitvavo.handle_order  s    , ##GX6!!(D#6!'  &1;;%%dllM4HE07DKet{{K0rO   c                 V   | j                  |d      }| j                  |d d      }|d   }d|z   }| j                  ||      }| j                  -| j	                  | j
                  dd      }t        |      | _        | j                  }	|	j                  |       |j                  |	|       y )Nr[   r   r^   r   rC   rA   )	r   r   r   r3  r   rH   r   rj   r   )
rL   r}   rc   r   r[   r^   r`   r   r   r   s
             rN   handle_my_tradezbitvavo.handle_my_trade  s      ##GX6!!(D#6!!F*  &1== %%dllM4HE&u-DMmm5!{K0rO   c                    | j                  |di       }d| j                  i}t        |j                               }t	        dt        |            D ]8  }||   }| j                  ||      }|| j                  ||      }	 ||||	       : |S )Nr   r   r   )r   r   listkeysrh   ri   )
rL   r}   rc   r   r  namesrp   rU   r   r   s
             rN   handle_subscription_statusz"bitvavo.handle_subscription_status  s     "ED88
 ]'')*q#e*% 	6A8D__Wd3F!#}dCvw5	6 rO   c                 *  K   | j                   d   d   }| j                  |      }d}| j                  |j                  |      }|| j	                         }t        |      }|dz   | j                  z   dz   }| j                  | j                  |      | j                  | j                        t        j                        }	d}
|
| j                  |	|d}| j                  ||      }| j                  ||||       d {   }||j                  |<   |S 7 w)Nr@   r   authenticatedzGET/z
/websocketr   )rX   key	signaturer   )rG   r}   r   r   r$  r#  versionhmacencodesecrethashlibsha256apiKeyr\   r]   )rL   r_   ra   r}   r`   futurer   stringTimestampauthr  rX   rb   rc   s                rN   r   zbitvavo.authenticate  s    iit$S!%!5!5{C>))+I!)nO"V+dll:\ID		$++d"3T[[5Mw~~^I#F {{&&	G kk'62G::c;MMF06F  - Ns   C9D;D<Dc                     d}| j                  |dd      }|r|j                  ||       y t        | j                  |            }|j	                  ||       ||j
                  v r|j
                  |= y y )Nr  F)	safe_boolr   r   jsonrejectr   )rL   r}   rc   r`   r  errors         rN   handle_authentication_messagez%bitvavo.handle_authentication_message  sn     &wGNN7K0'		'(:;EMM%-f222((5 3rO   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  |d|      }d}	 | j                  |||j                  d d ||d d 	       |s|j                  ||       y y # t
        $ r}	d}|j                  |	|       Y d }	~	8d }	~	ww xY w)Nr  	errorCoderX   r   FT)r   r   r  handle_errorsra   	Exceptionr  )
rL   r}   rc   r  r8  rX   buildMessager`   rejectedes
             rN   handle_error_messagezbitvavo.handle_error_message   s        '2  4!!'84..vw?&&w\J	*tUFJJdE7TXZ^_ MM';/   	*HMM![))	*s   #B 	B?!B::B?c           
         | j                  |d      }|| j                  ||       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}| j                  |d      }| j-                  ||      }|1| j                  |d      }| j-                  ||      }|
 |||       y y  |||       y )Nr  
subscribedr   r   r   r   rs   r   r|  fillr  r
  rt  r  r  r  r  r.  )r_  rW  rG  r:  r1  ri  rS  rf  r   rX   )r   r  r  r   r   r   r   r   r  r  r  r}  ry  r  rr  r]  rQ  rE  r7  rn  r   r  r   )rL   r}   rc   r  r  r   r   rX   s           rN   handle_messagezbitvavo.handle_message  s   X   '2%%fg6
$99
D**
 t66
 T&&	

 d''
 ++
 D>>
 T&&
 D((
 !$":":
 !$":":
  !:!:
 "4#>#>
  ; ;
 t77
  !$":":!
" #D$?$?#
$ "&!9!9(,(<(<+/+@+@%)%9%9 $ 5 55511--3
6   '2%0>%%gx8F__Wf5F!vw' " 67#rO   )N)V__name__
__module____qualname__r   rK   rd   r#  rq   r   rt   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/  r4  r7  r@  rE  rK  rQ  rU  rZ  r]  r   rb  rg  rj  rn  rr  r   ru  ry  r}  r  r  r  r  r  r  r  r   r  r  r  __classcell__)rM   s   @rN   r   r      s   2# 2h 79 H& Y[ U3 U* 68 
D 
DF 
D 6:" @7 @ @ $&F $&L 8<B @W @7 @ &V &  <@d[] S SS S Sbfglbm S 16 14 8<$]ajl  H  HC  HWZ  Hquvzq{  HD+ +%,6 %,N @DB $!S $! $!S\ $!L&
3 *#3 #3J!%/ %/N=V =
:f 
: 04$UYbd U UC Us Uimnsit UB 37TX\eg UC Us URU Ulpqvlw UB pt|~ GC Gy G	 G[` Gil G  DI G< im{  IK Gc G3 Gi Gy Gbe Gux G  PU G( <@ G GS G  8<B ] ]&,V ,( ;?r Ys YC Ye Y, 37TX\eg OC Os ORU Olpqvlw O($N 8<$]ajl O OC OWZ Oquv{q| O* 6:[_hj Qs Q# QUX Qostyoz Q(,v ,< AER Jc J".f .$ 6:[_hj Rs R# RUX R$1v 1. ;?T`dmo H3 Hs HZ] Htxy}t~ H& 37TX\eg QC Qs QRU Q$.f .* 24 E E -/ 	> 02 
=0f 04*$ -/ E8 E-6 -$ +&  +D-V -2 13  =?  ?A   16  1D1f 18 , )+ ,6F 6&06 0<R$V R$rO   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   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr    rO   rN   <module>r     sT     f f  O  O  O  O 4  * 0 ._$d  (( _$rO   