
    iO                         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 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)BalancesIntNumOrder	OrderBook	OrderSide	OrderTypeStrTickerTradeTradingFees)Client)List)ExchangeError)AuthenticationError)ArgumentsRequiredc                   F    e Zd Z fdZi fdZi fdedefdZdefd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$Z(defd%Z)di fd!ededefd&Z*dddi fded	e
d
e
dee         fd'Z+d( Z,dddi fded	e
d
e
dee         fd)Z-dddi fded	e
d
e
dee         fd*Z.defd+Z/di fd,efd-Z0defd.Z1dddi fd,ed	e
d
e
fd/Z2defd0Z3dddi fded	e
d
e
dee         fd1Z4dddi fd,ed	e
d
e
fd2Z5defd3Z6i fde7fd4Z8i fd5Z9i fd6Z:defd7Z;d8 Z<i fde=fd9Z>defd:Z?defd;Z@defd<ZAi fd=ZBd> ZCi fd?ZDi fd@ZEdefdAZFdefdBZGdefdCZHi fdDZIdefdEZJdefdFZKdefdGZL xZMS )Hbitvavoc           
      ^   |                      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%iidd&d&d&d'd(          S ))NwsTcancelOrdersWsFfetchTradesWswatchOrderBookwatchTradeswatchTicker
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    V/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/pro/bitvavo.pyrE   zbitvavo.describe   s	   gt 4 4 = = ? ?"d" %"  " !$	"
 t" t" d" t"  " $T"  "  " )$" *4" $T"  t!"" !$#" "$ $T%"& ('"( "4)"* -d+", "4-". /"0 $T1"2 3"4 #D5"6  7"8  9": !$;"< t="> %d?"@ %dA"B dC" "H 3 38##"	 S/B
 /B
 / / /	    c                 .  K   |                                   d {V  |                     |          }|dz   |d         z   }| j        d         d         }d||d         gdgd}|                     ||          }|                     ||||           d {V S )N@idr:   r   	subscribenamemarketsactionchannels)load_marketsmarketrA   extendwatch)	rF   rO   symbolparamsrU   messageHashurlrequestmessages	            rH   watch_publiczbitvavo.watch_publicE   s      !!!!!!!!!V$$Sj6$</it$! !t  

 

 ++gv..ZZ[';GGGGGGGGGrI   rX   returnc                 @   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
        :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)r^   )rF   rX   rY   s      rH   watch_tickerzbitvavo.watch_tickerX   s2       &&{FFCCCCCCCCCrI   clientc                    |                      |d          }|                     |dg           }t          dt          |                    D ]}}||         }|                      |d          }|                     |d d          }|dz   |z   }	|                     ||          }
|
d         }|
| j        |<   |                    |
|	           ~|S )Neventdatar   rU   -rK   rX   )safe_string
safe_valuerangelensafe_marketparse_tickertickersresolve)rF   rc   r]   re   rn   irf   marketIdrU   rZ   tickerrX   s               rH   handle_tickerzbitvavo.handle_tickera   s    ,   '22//'6266q#g,,'' 	0 	0A1:D''h77H%%hc::F#+0K&&tV44FH%F#)DL NN6;////rI   N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trades	timestampT)rT   rX   r^   
newUpdatesgetLimitfilter_by_since_limit)rF   rX   rt   ru   rY   rw   s         rH   watch_tradeszbitvavo.watch_trades   s       !!!!!!!!!V$$((66BBBBBBBB? 	3OOFE22E))&%TRRRrI   c                    |                      |d          }|                     |d d          }|d         }d}|dz   |z   }|                     ||          }|                     | j        |          }	|	+|                     | j        dd          }
t          |
          }	|	                    |           |	| j        |<   |	                    |	|           d S )NrU   rg   rX   rw   rK   r=   r;   )
rh   rl   parse_traderi   rw   safe_integerrB   r   appendro   )rF   rc   r]   rq   rU   rX   rO   rZ   tradetradesArrayru   s              rH   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0rI   1mc                   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
        NrX   candlesrL   rK   _r:   r   rM   )rO   intervalrP   rQ   r   T)
rT   rU   rh   
timeframesrA   rV   rW   ry   rz   r{   )rF   rX   	timeframert   ru   rY   rU   rO   rq   r   rZ   r[   r\   r]   ohlcvs                  rH   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GrI   c                     |                      |d          }|                     |d          }|                     |d d d           }|                     |          }|                    ||           d S NrR   response)rh   ri   parse_ohlcvsbuild_message_hashro   )rF   rc   r]   rR   r   r   rZ   s          rH   handle_fetch_ohlcvzbitvavo.handle_fetch_ohlcv   sr     !!'844??7J77!!(D$==--f55uk*****rI   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   rU   rg   rX   r   rK   r   candler?   r;   r   )rh   rl   find_timeframeri   ohlcvsr   rB   r   rj   rk   parse_ohlcvr   ro   )rF   rc   r]   rO   rq   rU   rX   r   r   rZ   r   storedru   rp   r   parseds                   rH   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{+++++rI   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
        NrX   bookrK   rL   r:   r   rM   rN   rQ   )rZ   rO   rX   rq   methodru   rY   )rT   rU   rA   handle_order_book_subscriptionrV   rW   ru   )rF   rX   ru   rY   rU   rO   rZ   r[   r\   subscriptionr]   	orderbooks               rH   watch_order_bookzbitvavo.watch_order_book  s      !!!!!!!!!V$$!Sj6$</it$! !t  

 

 't9
 
 ++gv..**S+w\ZZZZZZZZ	   rI   c                     |                      |d          }|                      |d          }|                    ||           d S )Nr      )
safe_floatstore)rF   booksidedeltapriceamounts        rH   handle_deltazbitvavo.handle_delta-  sB    q))**uf%%%%%rI   c                 ~    t          dt          |                    D ]}|                     |||                    d S )Nr   )rj   rk   r   )rF   r   deltasrp   s       rH   handle_deltaszbitvavo.handle_deltas2  sH    q#f++&& 	3 	3Ahq	2222	3 	3rI   c                    |                      |d          }||d         k    rg|                     |d         |                     |dg                      |                     |d         |                     |dg                      ||d<   |S )Nnonceasksbids)r   r   ri   )rF   rc   r]   r   r   s        rH   handle_order_book_messagez!bitvavo.handle_order_book_message6  s     !!'7339W%%%y0$//'6SU2V2VWWWy0$//'6SU2V2VWWW!&IgrI   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 )Nre   rU   rg   rX   rK   rL   r   watchingOrderBookSnapshotTwatchOrderBookSnapshotdelay)rh   rl   ri   
orderbookssubscriptionsrB   r   	rateLimitr   watch_order_book_snapshotcacher   r   ro   )rF   rc   r]   re   rq   rU   rX   rZ   r   r   r   rB   r   s                rH   handle_order_bookzbitvavo.handle_order_bookK  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2rI   c                 0  K   |                      |d          }|                     |d          }d}|dz   |z   }| j        d         d         }||d}	|                     |||                     |	|          ||           d {V }
|
                                S )NrY   rq   getBookrK   r:   r   )rR   rU   )ri   rh   rA   rW   rV   ru   )rF   rc   r]   r   rY   rq   rO   rZ   r[   r\   r   s              rH   r   z!bitvavo.watch_order_book_snapshotp  s      x88##L*==Sj8+it$
 
 **S+t{{7F7S7SU`bnoooooooo	   rI   c                    |                      |d          }|d S |                     |d          }|                     |d d          }d}|dz   |z   }| j        |         }|                     ||          }	|                     |d          |	d<   |                    |	           |j        }
t          dt          |
                    D ]!}|
|         }| 
                    |||           "|| j        |<   |                    ||           d S )Nr   rU   rg   r   rK   r   r   )ri   rh   safe_symbolr   parse_order_bookr   resetr   rj   rk   r   ro   )rF   rc   r]   r   rq   rX   rO   rZ   r   snapshotmessagesrp   messageItems                rH   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+.....rI   c                     |                      |d          }|                     |d          }|| j        v r| j        |= |                     i |          | j        |<   d S )NrX   ru   )rh   r   r   
order_book)rF   rc   r]   r   rX   ru   s         rH   r   z&bitvavo.handle_order_book_subscription  sc    !!,99!!,88T_$$'"&//"e"<"<rI   c                 F   d}t          dt          |                    D ]}|                     ||          }|                     |d d          }|dz   |z   }|| j        vr@|                     |j        |          }	|                     |	d          }
|
 |
|||	           d S )Nr   r   rg   rK   r   )rj   rk   rh   r   r   ri   r   )rF   rc   r]   	marketIdsrO   rp   rq   rX   rZ   r   r   s              rH   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	: 	:rI   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 argumentrX   rL   r:   r   accountorder:rM   rN   rQ   T
r   rL   rT   authenticaterU   rA   rW   ry   rz   filter_by_symbol_since_limit)rF   rX   rt   ru   rY   rU   rq   r[   rO   rZ   r\   orderss               rH   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TrI   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]{@link https://docs.ccxt.com/#/?id=ortradeder-structure
        Nz+ watchMyTrades() requires a symbol argumentrX   rL   r:   r   r   	myTrades:rM   rN   rQ   Tr   )rF   rX   rt   ru   rY   rU   rq   r[   rO   rZ   r\   rw   s               rH   watch_my_tradeszbitvavo.watch_my_trades  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TrI   typesider   r   c                    K   |                                   d{V  |                                  d{V  |                     ||||||          }|                     d|           d{V S )aI  
        create a trade order
        :see: 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 fullfilled, 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)rT   r   create_order_requestwatch_request)rF   rX   r   r   r   r   rY   r\   s           rH   create_order_wszbitvavo.create_order_ws  s      . !!!!!!!!!!!!!!!!!!++FD$vVV''(<gFFFFFFFFFrI   rL   c           	         K   |                                   d{V  |                                  d{V  |                     |||||||          }|                     d|           d{V S )a  
        edit a trade order
        :see: 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 fullfilled, in units of the base 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)rT   r   edit_order_requestr   )	rF   rL   rX   r   r   r   r   rY   r\   s	            rH   edit_order_wszbitvavo.edit_order_ws  s       !!!!!!!!!!!!!!!!!!))"fdD&%QWXX''(<gFFFFFFFFFrI   c                    K   |                                   d{V  |                                  d{V  |                     |||          }|                     d|           d{V S )a  
        :see: 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)rT   r   cancelOrderRequestr   )rF   rL   rX   rY   r\   s        rH   cancel_order_wszbitvavo.cancel_order_ws'  s       !!!!!!!!!!!!!!!!!!))"ff==''(<gFFFFFFFFFrI   c                   K   |                                   d{V  |                                  d{V  i }d}| |                     |          }|d         |d<   |                     d|                     ||                     d{V S )a  
        :see: 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>`
        NrL   rU   privateCancelOrders)rT   r   rU   r   rV   )rF   rX   rY   r\   rU   s        rH   cancel_all_orders_wszbitvavo.cancel_all_orders_ws5  s       !!!!!!!!!!!!!!!!!![[((F &tGH''(=t{{7TZ?[?[\\\\\\\\\rI   c                    |                      |d          }|                     |d          }|                     |di           }|                      |d          }|                     |          }|                     |d|i          }|                    ||           |                     ||          }|                    ||           d S NrR   r   r   rU   )rh   ri   parse_ordersr   ro   )	rF   rc   r]   rR   r   firstRawOrderrq   r   rZ   s	            rH   handle_multiple_orderszbitvavo.handle_multiple_ordersF  s     !!'844??7J77!R88##M8<<""8,,--fx6JKKv{+++--fg>>v{+++++rI   c                 @  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     |          }||d         d}|                     d|                     ||                     d{V S )a  
        :see: https://docs.bitvavo.com/#tag/General/paths/~1assets/get
        fetches information on an order made by the user
        :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 argumentrL   )orderIdrU   privateGetOrder)r   rL   rT   r   rU   r   rV   )rF   rL   rX   rY   rU   r\   s         rH   fetch_order_wszbitvavo.fetch_order_wsY  s       >#DG.X$XYYY!!!!!!!!!!!!!!!!!!V$$Tl
 
 ''(94;;wPV;W;WXXXXXXXXXrI   c                 8  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a2  
        :see: 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   rL   rT   r   fetchOrdersRequestr   r   )rF   rX   rt   ru   rY   r\   r   s          rH   fetch_orders_wszbitvavo.fetch_orders_wsl  s       >#DG.[$[\\\!!!!!!!!!!!!!!!!!!))&%GG))*<gFFFFFFFF00NNNrI   c                    K   ||d<   |                      ||          }|                     |           | j        d         d         }|                     ||||           d {V S )NrR   r:   r   )r   !check_message_hash_does_not_existrA   rW   )rF   rR   r\   rZ   r[   s        rH   r   zbitvavo.watch_request~  st      "--fg>>..{;;;it$ZZ[';GGGGGGGGGrI   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>`
        NrL   rU   privateGetOrdersOpen)rT   r   rU   r   rV   r   )rF   rX   rt   ru   rY   r\   rU   r   s           rH   fetch_open_orders_wszbitvavo.fetch_open_orders_ws  s       !!!!!!!!!!!!!!!!!!
 [[((F &tGH))*@$++gW]B^B^________00NNNrI   c                 8  K   |t          | j        dz             |                                  d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a  
        :see: 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   rL   rT   r   fetchMyTradesRequestr   r   )rF   rX   rt   ru   rY   r\   myTradess          rH   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PrI   c                 D   |                      |d          }|                     |d          }|                     |di           }|                      |d          }|                     |d d d           }|                     |d|i          }|                    ||           d S r   )rh   ri   parse_tradesr   ro   )	rF   rc   r]   rR   r   firstRawTraderq   rw   rZ   s	            rH   handle_my_tradeszbitvavo.handle_my_trades  s    , !!'844??7J77!R88##M8<<""8T4>>--fx6JKKv{+++++rI   codec                 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_addressrT   r   withdrawRequestr   )rF   r  r   addresstagrY   r\   s          rH   withdraw_wszbitvavo.withdraw_ws  s       99#vFFV7###!!!!!!!!!!!!!!!!!!&&tVWc6JJ''(?IIIIIIIIIrI   c                     |                      |d          }|                     ||          }|                     |d          }|                     |          }|                    ||           d S r   )rh   r   ri   parse_transactionro   )rF   rc   r]   rR   rZ   r   withdraws          rH   handle_withdrawzbitvavo.handle_withdraw  sn     !!'844--fg>>??7J77))(33x-----rI   c                   K   |                                   d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a#  
        :see: 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)rT   r   fetchWithdrawalsRequestr   filter_by_currency_since_limit)rF   r  rt   ru   rY   r\   	withdrawss          rH   fetch_withdrawals_wszbitvavo.fetch_withdrawals_ws  s       !!!!!!!!!!!!!!!!!!..tUE6JJ,,-JGTTTTTTTT	229dE5QQQrI   c                     |                      |d          }|                     ||          }|                     |d          }|                     |d d d ddi          }|                    ||           d S )NrR   r   r   
withdrawalrh   r   ri   parse_transactionsro   )rF   rc   r]   rR   rZ   r   withdrawalss          rH   handle_withdrawszbitvavo.handle_withdraws  s|      !!'844--fg>>??7J77--hdD6S_J`aa{K00000rI   c                    K   |                                   d{V  |                     |||||          }d}|                     ||           d{V }|                     |||dd          S )a  
        :see: 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)rT   fetchOHLCVRequestr   r{   )	rF   rX   r   rt   ru   rY   r\   rR   r   s	            rH   fetch_ohlcv_wszbitvavo.fetch_ohlcv_ws  s       !!!!!!!!!((E5&QQ((99999999))%q$GGGrI   c                   K   |                                   d{V  |                                  d{V  |                     ||||          }|                     d|           d{V }|                     ||||          S )a  
        :see: 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)rT   r   fetchDepositsRequestr   r  )rF   r  rt   ru   rY   r\   depositss          rH   fetch_deposits_wszbitvavo.fetch_deposits_ws#  s       !!!!!!!!!!!!!!!!!!++D%GG++,FPPPPPPPP228T5%PPPrI   c                     |                      |d          }|                     ||          }|                     |d          }|                     |d d d ddi          }|                    ||           d S )NrR   r   r   depositr  )rF   rc   r]   rR   rZ   r   r$  s          rH   handle_depositszbitvavo.handle_deposits3  s|      !!'844--fg>>??7J77**8T4PYGZ[[x-----rI   c                    K   |                                   d{V  |                                  d{V  |                     d|           d{V S )aW  
        :see: 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rT   r   r   rF   rY   s     rH   fetch_trading_fees_wszbitvavo.fetch_trading_fees_wsI  y       !!!!!!!!!!!!!!!!!!''(;VDDDDDDDDDrI   c                 >   K   |                      d|           d{V S )a  
        :see: 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     rH   fetch_markets_wszbitvavo.fetch_markets_wsT  s0       ''f=========rI   c                 r   K   |                                   d{V  |                     d|           d{V S )a  
        :see: 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)rT   r   r,  s     rH   fetch_currencies_wszbitvavo.fetch_currencies_ws]  sT       !!!!!!!!!''V<<<<<<<<<rI   c                     |                      |d          }|                     ||          }|                     |d          }|                     |          }|                    ||           d S r   )rh   r   ri   parseCurrenciesro   )rF   rc   r]   rR   rZ   r   
currenciess          rH   handle_fetch_currencieszbitvavo.handle_fetch_currenciesg  sn    * !!'844--fg>>??7J77))(33
z;/////rI   c                     |                      |d          }|                     ||          }|                     |d          }|                     |          }|                    ||           d S r   )rh   r   ri   parse_trading_feesro   )rF   rc   r]   rR   rZ   r   feess          rH   handle_trading_feeszbitvavo.handle_trading_fees  sn     !!'844--fg>>??7J77&&x00t[)))))rI   c                    K   |                                   d{V  |                                  d{V  |                     d|           d{V S )ay  
        :see: 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     rH   fetch_balance_wszbitvavo.fetch_balance_ws  r.  rI   c                     |                      |dd          }|                     ||          }|                     |dg           }|                     |          }|                    ||           d S )NrR   r>  r   )rh   r   ri   parse_balancero   )rF   rc   r]   rR   rZ   r   balances          rH   handle_fetch_balancezbitvavo.handle_fetch_balance  ss     !!'85HII--fg>>??7J;;$$X..w,,,,,rI   c                     |                      |d          }|                     |di           }|                     |          }|                     ||          }|                    ||           d S r   )rh   ri   parse_orderr   ro   )rF   rc   r]   rR   r   orderrZ   s          rH   handle_single_orderzbitvavo.handle_single_order  sp    : !!'844??7J;;  **--fh??uk*****rI   c                     |                      |d          }|                     |di           }|                     |          }|                     ||          }|                    ||           d S r   )rh   ri   parse_marketsr   ro   )rF   rc   r]   rR   r   rP   rZ   s          rH   handle_marketszbitvavo.handle_markets  sp    ( !!'844??7J;;$$X..--fh??w,,,,,rI   c                     | j         | j        | j        | j        | j         d}|                     ||          }|}| |||          }|S )N)r   r   r   r   r   )action_and_market_message_hash action_and_order_id_message_hashri   )rF   rR   rY   methodsr   rZ   s         rH   r   zbitvavo.build_message_hash  sc    "&"E"&"G"&"G#D $ C
 
 &11 &00KrI   c                    |                      | j        dd          }|sh|                     | j        | j        d         d                   }|<|                     |j        |          }|!t          | j        dz   |z   dz             d S d S d S )Nr<   Fr:   r   z$ a similar request with messageHash z is already pending, you must wait for a response, or turn off self error by setting supressMultipleWsRequestsError in the options to True)	safe_boolrB   ri   clientsrA   futuresr   rL   )rF   rZ   r<   rc   futures        rH   r   z)bitvavo.check_message_hash_does_not_exist  s    )-Ffhm)n)n&- 	w__T\49U3CD3IJJF!EE%'2X(X[f(f  jv  )v  w  w  w	w 	w!!%%rI   c                 :    |                      |dd          }||z   S )NrU    )rh   )rF   rR   rY   rX   s       rH   rL  z&bitvavo.action_and_market_message_hash  s#    !!&(B77rI   c                 j    |                      |d          }|t          | j        dz             ||z   S )Nr   z; privateUpdateOrderMessageHash requires a orderId parameter)rh   r   rL   )rF   rR   rY   r   s       rH   rM  z(bitvavo.action_and_order_id_message_hash  s=    ""6955?*g ghhhrI   c                    |                      |d          }|                     |d d          }|d         }d|z   }|                     ||          }| j        0|                     | j        dd          }t          |          | _        | j        }	|	                    |           |                    | j        |           d S )NrU   rg   rX   r   r>   r;   )	rh   rl   rE  r   r   rB   r   r   ro   )
rF   rc   r]   rq   rU   rX   rZ   rF  ru   r   s
             rH   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0rI   c                 x   |                      |d          }|                     |d d          }|d         }d|z   }|                     ||          }| j        0|                     | j        dd          }t          |          | _        | j        }	|	                    |           |                    |	|           d S )NrU   rg   rX   r   r=   r;   )	rh   rl   r~   r   r   rB   r   r   ro   )
rF   rc   r]   rq   rU   rX   rZ   r   ru   r   s
             rH   handle_my_tradezbitvavo.handle_my_trade3  s      ##GX66!!(D#66!!F*  &11= %%dlM4HHE&u--DMm5!!!{K00000rI   c                 N   |                      |di           }d| j        i}t          |                                          }t	          dt          |                    D ]E}||         }|                      ||          }|#|                      ||          }	 ||||	           F|S )Nr   r   r   )ri   r   listkeysrj   rk   )
rF   rc   r]   r   rN  namesrp   rO   r   r   s
             rH   handle_subscription_statusz"bitvavo.handle_subscription_statusO  s     "EED8
 ]''))**q#e**%% 	6 	6A8D__Wd33F!#}dCCvw555rI   c                 .  K   | j         d         d         }|                     |          }d}|                     |j        |          }||                                 }t          |          }|dz   | j        z   dz   }|                     |                     |          |                     | j	                  t          j                  }	d}
|
| j        |	|d}|                     ||          }|                     ||||           d {V }||j        |<   |S )Nr:   r   authenticatedzGET/z
/websocketr   )rR   key	signaturerx   )rA   rc   ri   r   millisecondsstrversionhmacencodesecrethashlibsha256apiKeyrV   rW   )rF   rY   r[   rc   rZ   rS  rx   stringTimestampauthrc  rR   r\   r]   s                rH   r   zbitvavo.authenticatee  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 -rI   c                    d}|                      |dd          }|r|                    ||           d S t          |                     |                    }|                    ||           ||j        v r
|j        |= d S d S )Nra  F)rP  ro   r   jsonrejectr   )rF   rc   r]   rZ   ra  errors         rH   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2rI   c                    |                      |d          }|                     |d          }|                      |d          }|                     ||          }d}	 |                     |||j        d d ||d d 	  	         n/# t
          $ r"}d}|                    ||           Y d }~nd }~ww xY w|s|                    ||           d S d S )Nrr  	errorCoderR   FT)rh   r   r   handle_errorsr[   	Exceptionrq  )	rF   rc   r]   rr  r  rR   rZ   rejectedes	            rH   handle_error_messagezbitvavo.handle_error_message  s      '22  44!!'844--fg>>	*tUFJdE7TXZ^____ 	* 	* 	*HMM![))))))))	*  	0MM';/////	0 	0s   "A? ?
B+	B&&B+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 )Nrr  
subscribedr   r   r   r   ra   r   rF  fillr   r   r>  r   r   r   r   r   )r*  r"  r  r  r   r3  r  r0  re   rR   )rh   rz  r_  r   r   r   r   rs   rs  rX  rZ  rG  rC  r   r<  r(  r  r  r  r8  r   rJ  ri   )rF   rc   r]   rr  rN  re   r   rR   s           rH   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#####rI   )N__name__
__module____qualname__rE   r^   re  r   rb   r   rs   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   r  r  r  r  r  r   r%  r(  r   r-  r1  r4  r8  r<  r   r?  rC  rG  rJ  r   r   rL  rM  rX  rZ  r_  r   rs  rz  r~  __classcell__)rG   s   @rH   r   r      sa	       0 0 0 0 0d 79 H H H H& 68 D D DF D D D D!F ! ! ! !F <@d[] S S SS S Sbfglbm S S S S 16 1 1 1 14 8<$]ajl  H  H  HC  HWZ  Hquvzq{  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8 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$H H H 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 , , , ,< AER J Jc J J J J".f . . . ." 6:[_hj R Rs R# RUX R R R R 1v 1 1 1 1, ;?T`dmo H H3 Hs HZ] Htxy}t~ 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 = = = =0f 0 0 0 06* * *& -/ 	E 	E8 	E 	E 	E 	E-6 - - - -&!+& !+ !+ !+ !+F-V - - - -4 13    w w w =?     ?A         16  1  1  1  1D1f 1 1 1 18    , )+    ,6F 6 6 6 6&06 0 0 0 0,R$V R$ R$ R$ R$ R$ R$ R$ R$rI   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   rj  ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr    rI   rH   <module>r     s&       f f f f f f f f f f  w w w w w w w w w w w w w w w w w w w w w w w w w w 4 4 4 4 4 4       * * * * * * 0 0 0 0 0 0 . . . . . .e$ e$ e$ e$ e$d ( e$ e$ e$ e$ e$rI   