
    E#i                         S SK rS SKJrJrJr  S SKJrJrJ	r	J
r
JrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr   " S S	\R2                  R4                  5      rg)
    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ExchangeError)ArgumentsRequiredc                   p  ^  \ rS rSrS\4U 4S jjr0 4S jr0 4S jrSSS0 4S\S	\S
\	S\	S\
\   4
S jjrS0 4S\S	\S\4S jjrSS0 4S\
\
\      S
\	S\	4S jjr0 4S\
\
\      S\4S jjrS\4S jr0 4S\S\4S jjr0 4S\S\4S jjrS0 4S\S\4S jjrS0 4S\S\4S jjrS\4S jrS0 4S\S\4S jjrS\4S jrS0S jrSS0 4S\S
\	S\	S\
\   4S jjr0 4S\S\4S jjrSS0 4S\
\   S
\	S\	S\
\   4S jjr 0 4S\
\   S\4S jjr!S\4S  jr"S0 4S\S\	S\#4S! jjr$0 4S\S\4S" jjr%S0 4S\
\   S\	S\#4S# jjr&0 4S\
\   S\4S$ jjr'S\4S% jr(0 4S& jr)0 4S' jr*0 4S\+4S( jjr,S\4S) jr-SSS0 4S\.S
\	S\	S\
\/   4S* jjr0S\4S+ jr1SSS0 4S\S
\	S\	S\
\2   4S, jjr3S- r4S\4S. jr5S/r6U =r7$ )1defx   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSSSS.SSSS.0SSS	S.0S
.SSSSSSSSSSSSSSS.0S.0 0 S.5      $ )NTF)wswatchBalancewatchTickerwatchTickerswatchBidsAskswatchTradeswatchTradesForSymbolswatchMyTradeswatchOrderswatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolsr   z'wss://stream.testnet.defx.com/pricefeedzwss://ws.testnet.defx.com/user)publicprivatez'wss://marketfeed.api.defx.com/pricefeedz wss://userfeed.api.defx.com/user)testapi 6 
timeframes1m3m5m15m30m1h2h4h12h1d1w1M)r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   )listenKeyRefreshRater   )hasurlsoptions	streaming
exceptions)deep_extendsuperr   describe)self	__class__s    G/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/defx.pyrA   defx.describe   s    dD : < $# $!%#)-!&#"&,0"(," "K#C "K#E )0 """$$"""$"""#&g5?
 5 5	    c                    #    U R                  5       I S h  vN   U R                  S   S   S   nSUS.nU R                  XS5      nU R                  XBXb5      I S h  vN $  NI N7f)Nr*   r   r'   	SUBSCRIBEmethodtopicsload_marketsr;   extendwatch_multiplerB   rK   messageHashesparamsurlrequestmessages          rD   watch_publicdefx.watch_publicI   sm     !!!iit$X.!
 ++g.((WTTT 	" U"   A$A AA$A"A$"A$c                    #    U R                  5       I S h  vN   U R                  S   S   S   nSUS.nU R                  XS5      nU R                  XBXb5      I S h  vN $  NI N7f)Nr*   r   r'   UNSUBSCRIBErI   rL   rP   s          rD   un_watch_publicdefx.un_watch_publicS   sm     !!!iit$X.#
 ++g.((WTTT 	" UrX   r-   Nsymbol	timeframesincelimitc                 V   #    U R                  X//X4U5      I Sh  vN nXa   U   $  N7f)ae  
watches historical candlestick data containing the open, high, low, close price, and the volume of a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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
N)watch_ohlcv_for_symbols)rB   r]   r^   r_   r`   rR   results          rD   watch_ohlcvdefx.watch_ohlcv]   s8      33f5H4I5Y_``~i(( as   )')c                 F   #    U R                  X//U5      I Sh  vN $  N7f)a  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
N)un_watch_ohlcv_for_symbols)rB   r]   r^   rR   s       rD   un_watch_ohlcvdefx.un_watch_ohlcvm   s&      44v6I5JFSSSS   !!symbolsAndTimeframesc                   #    [        U5      nUS:X  d  [        US   [        5      (       d  [        U R                  S-   5      eU R                  5       I Sh  vN   / n/ n[        S[        U5      5       H  nX   n	U R                  U	S5      n
U R                  U
5      nU R                  U	S5      nU R                  U R                  X5      nUR                  SUS   -   S-   U-   5        UR                  SU-   S	-   US
   -   5        M     U R                  XgU5      I Sh  vN u  pnU R                  (       a  UR                  X5      nU R                  UX#SS5      nU R                  XU5      $  GN NR7f)a  
watches historical candlestick data containing the open, high, low, close price, and the volume of a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
: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
r   zu watchOHLCVForSymbols() requires a an array of symbols and timeframes, like  [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]N   symbol:id:ohlc:candles::r]   T)len
isinstancelistr   ro   rM   rangesafe_stringmarketr,   appendrV   
newUpdatesgetLimitfilter_by_since_limitcreate_ohlcv_object)rB   rk   r_   r`   rR   symbolsLengthrK   rQ   isymbolAndTimeframemarketIdrx   tfintervalr]   r^   candlesfiltereds                     rD   rb   defx.watch_ohlcv_for_symbolsz   s|     01AZ0DQ0G%N%N#DGG  /f  %f  g  g!!!q#234A!5!8''(:A>H[[*F!!"4a8B''@HMM)fTl2X=HI  h!6!<vh?O!OP 5 ,0+<+<VTZ+[%["7??$$V3E--guQM''8DD 	" &\s&   AE5E0CE5 E3!AE53E5c                 V  #    [        U5      nUS:X  d  [        US   [        5      (       d  [        U R                  S-   5      eU R                  5       I Sh  vN   / n/ n[        S[        U5      5       H  nX   nU R                  US5      nU R                  U5      n	U R                  US5      n
U R                  U R                  X5      nUR                  SU	S   -   S-   U-   5        UR                  SU-   S	-   U	S
   -   5        M     U R                  XEU5      I Sh  vN $  N N7f)a  
unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[][] symbolsAndTimeframes: array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int[][]: A list of candles ordered, open, high, low, close, volume
r   zw unWatchOHLCVForSymbols() requires a an array of symbols and timeframes, like  [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]Nrm   rn   ro   rp   rq   rr   r]   )rs   rt   ru   r   ro   rM   rv   rw   rx   r,   ry   r[   )rB   rk   rR   r~   rK   rQ   r   r   r   rx   r   r   s               rD   rg   defx.un_watch_ohlcv_for_symbols   s7     01AZ0DQ0G%N%N#DGG  /h  %h  i  i!!!q#234A!5!8''(:A>H[[*F!!"4a8B''@HMM)fTl2X=HI  h!6!<vh?O!OP 5 ))&HHH 	" Is%   AD)D%CD) D'!D)'D)clientc                    U R                  US0 5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nX`R                  ;  a  0 U R                  U'   XpR                  U   ;  a9  U R	                  U R
                  SS5      n[        U5      n	XR                  U   U'   U R                  U   U   n
U R                  U5      nU
R                  U5        SU-   S-   U-   nUR                  XgU
/U5        g )Ndatar]   window
OHLCVLimit  rq   rr   )
	safe_dictrw   rx   ohlcvssafe_integerr<   r   parse_ohlcvry   resolve)rB   r   rU   r   r   rx   r]   r^   r`   storedohlcvparsedmessageHashs                rD   handle_ohlcvdefx.handle_ohlcv   s   0 ~~gvr2##D(3X&!$$T84	++%"$DKK[[00%%dllL$GE*51F-3KK	*F#I.!!$'V 9,s2V;51;?rF   c                    #    U R                  5       I Sh  vN   U R                  U5      nUS   nSUS   -   S-   nSU-   nU R                  U/U/U5      I Sh  vN $  NG N7f)a  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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>`
Nr]   rn   ro   :24hrTickerticker:)rM   rx   rV   )rB   r]   rR   rx   topicr   s         rD   watch_tickerdefx.watch_ticker   su      !!!V$!F4L(=8&(&&wvFFF 	"
 Gs"   A"AAA"A A" A"c                 D   #    U R                  U/U5      I Sh  vN $  N7f)aK  
unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.channel]: the channel to subscribe to, tickers by default. Can be tickers, sprd-tickers, index-tickers, block-tickers
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
N)un_watch_tickersrB   r]   rR   s      rD   un_watch_tickerdefx.un_watch_ticker   s"      **F8V<<<<     symbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HC  nX   nU R	                  U5      nUR                  SU-   S-   5        UR                  SU-   5        ME     U R                  X4U5      I Sh  vN   U R                  U R                  SU5      $  N N#7f)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://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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>`
NFr   rn   r   r   r]   )	rM   market_symbolsrv   rs   	market_idry   rV   filter_by_arraytickersrB   r   rR   rK   rQ   r   r]   r   s           rD   watch_tickersdefx.watch_tickers   s      !!!%%gtU;q#g,'AZF~~f-HMM)h.>?  V!34	 (
 v>>>##DLL(GDD 	" 	?"   C	CBC	#C$"C	C	c                 \  #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HC  nX   nU R	                  U5      nUR                  SU-   S-   5        UR                  SU-   5        ME     U R                  X4U5      I Sh  vN $  N N7f)a  
unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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>`
NFr   rn   r   r   )rM   r   rv   rs   r   ry   r[   r   s           rD   r   defx.un_watch_tickers  s      !!!%%gtU;q#g,'AZF~~f-HMM)h.>?  V!34	 (
 ))&HHH 	" Is"   B,B(BB,#B*$B,*B,c                    U R                  X5        U R                  US0 5      nU R                  U5      nUS   nU R                  US5      nXdS'   U R	                  U5      US'   X@R
                  U'   SU-   nUR                  XG5        g )Nr   r]   	timestampdatetimer   )handle_bid_askr   parse_tickerr   iso8601r   r   rB   r   rU   r   parsedTickerr]   r   r   s           rD   handle_tickerdefx.handle_ticker&  s    : 	F,~~gvr2((.h'%%g{;	$-[!#'<<	#:Z +V&(|1rF   c                   #    U R                  5       I Sh  vN   U R                  USS5      n/ n/ n[        S[        U5      5       HC  nX   nU R	                  U5      nUR                  SU-   S-   5        UR                  SU-   5        ME     U R                  X4U5      I Sh  vN   U R                  U R                  SU5      $  N N#7f)ag  
watches best bid & ask for symbols

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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>`
NFr   rn   r   bidask:r]   )	rM   r   rv   rs   r   ry   rV   r   bidsasksr   s           rD   watch_bids_asksdefx.watch_bids_asksN  s      !!!%%gtU;q#g,'AZF~~f-HMM)h.>?  V!34	 (
 v>>>##DMM8WEE 	" 	?r   c                     U R                  US0 5      nU R                  U5      nUS   nU R                  US5      nXdS'   U R                  U5      US'   X@R                  U'   SU-   nUR                  XG5        g )Nr   r]   r   r   r   )r   parse_ws_bid_askr   r   r   r   r   s           rD   r   defx.handle_bid_askd  s}    ~~gvr2,,T2h'%%g{;	$-[!#'<<	#:Z  ,f&(|1rF   c                 "   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US S U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.U5      $ )Nr]   bestAskPrice
bestAskQtybestBidPrice
bestBidQty)r]   r   r   ask	askVolumebid	bidVolumeinfo)rw   safe_marketsafe_ticker)rB   tickerrx   r   r]   s        rD   r   defx.parse_ws_bid_asko  s    ##FH5!!(3!!&(3##FN;))&,?##FN;))&,?	!
 	 		rF   c                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a   
watches information on multiple trades made in a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str symbol: unified symbol of the market to fetch the ticker for
: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 `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
N)watch_trades_for_symbols)rB   r]   r_   r`   rR   s        rD   watch_tradesdefx.watch_trades~  s$      22F8U6RRRRrj   c                 D   #    U R                  U/U5      I Sh  vN $  N7f)af  
unWatches from the stream channel

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str symbol: unified symbol of the market to fetch trades for
: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)un_watch_trades_for_symbolsr   s      rD   un_watch_tradesdefx.un_watch_trades  s"      55vhGGGGr   c                 `  #    U R                  5       I Sh  vN   U R                  U5      n[        U5      nUS:X  a  [        U R                  S-   5      e/ n/ n[        S[        U5      5       HC  nX   n	U R                  U	5      n
UR                  SU
-   S-   5        UR                  SU	-   5        ME     U R                  XgU5      I Sh  vN nU R                  (       a5  U R                  US5      nU R                  US5      nUR                  X5      nU R                  XUSS	5      $  GN Na7f)
a  
watches information on multiple trades made in a market

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[] symbols: unified symbol of the market to fetch trades for
: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 `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   z> watchTradesForSymbols() requires a non-empty array of symbolsrn   :tradestrade:r]   r   T)rM   r   rs   r   ro   rv   r   ry   rV   rz   
safe_valuerw   r{   r|   )rB   r   r_   r`   rR   r~   rK   rQ   r   r]   r   tradesfirsttradeSymbols                 rD   r   defx.watch_trades_for_symbols  s     !!!%%g.GA#DGG.n$nooq#g,'AZF~~f-HMM)h.:;  F!23	 (
 ((GG??OOFA.E**5(;KOOK7E))&TRR# 	" Hs#   D.D)B3D.
D,AD.,D.c                   #    U R                  5       I Sh  vN   U R                  U5      n[        U5      nUS:X  a  [        U R                  S-   5      e/ n/ n[        S[        U5      5       HC  nX   nU R                  U5      nUR                  SU-   S-   5        UR                  SU-   5        ME     U R                  XEU5      I Sh  vN $  N N7f)ai  
unWatches from the stream channel

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[] symbols: unified symbol of the market to fetch trades for
: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>`
Nr   z@ unWatchTradesForSymbols() requires a non-empty array of symbolsrn   r   r   )	rM   r   rs   r   ro   rv   r   ry   r[   	rB   r   rR   r~   rK   rQ   r   r]   r   s	            rD   r    defx.un_watch_trades_for_symbols  s      !!!%%g.GA#DGG.p$pqqq#g,'AZF~~f-HMM)h.:;  F!23	 (
 ))&HHH 	" I"   CCB3C
CCCc                 L   U R                  US0 5      nU R                  U5      nUS   nXPR                  ;  a6  U R                  U R                  SS5      n[        U5      nXpR                  U'   U R                  U   nUR                  U5        SU-   n	UR                  X5        g )Nr   r]   tradesLimitr   r   )r   parse_trader   r   r<   r   ry   r   )
rB   r   rU   r   parsedTrader]   r`   r   r   r   s
             rD   handle_tradesdefx.handle_trades  s     ~~gvr2&&t,X&++%%%dllM4HE&F"(KKV$k"'v+rF   c                 D   #    U R                  U/X#5      I Sh  vN $  N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

: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
N)watch_order_book_for_symbols)rB   r]   r`   rR   s       rD   watch_order_bookdefx.watch_order_book  s"      66xOOOOr   c                 D   #    U R                  U/U5      I Sh  vN $  N7f)a  
unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str symbol: unified array of symbols
: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
N)un_watch_order_book_for_symbolsr   s      rD   un_watch_order_bookdefx.un_watch_order_book  s"      996(FKKKKr   c                   #    U R                  5       I Sh  vN   [        U5      nUS:X  a  [        U R                  S-   5      eU R	                  U5      n/ n/ n[        S[        U5      5       HC  nX   nU R                  U5      n	UR                  SU	-   S-   5        UR                  SU-   5        ME     U R                  XVU5      I Sh  vN n
U
R                  5       $  N N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[] symbols: unified array of symbols
: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   zA watchOrderBookForSymbols() requires a non-empty array of symbolsrn   :depth:20:0.001
orderbook:)
rM   rs   r   ro   r   rv   r   ry   rV   r`   )rB   r   r`   rR   r~   rK   rQ   r   r]   r   	orderbooks              rD   r   !defx.watch_order_book_for_symbols  s      !!!GA#DGG.q$qrr%%g.q#g,'AZF~~f-HMM)h.1BBC  !67	 (
 ++F6JJ	   	" Ks"   C#CB3C#
C!C#!C#c                   #    U R                  5       I Sh  vN   [        U5      nUS:X  a  [        U R                  S-   5      eU R	                  U5      n/ n/ n[        S[        U5      5       HC  nX   nU R                  U5      nUR                  SU-   S-   5        UR                  SU-   5        ME     U R                  XEU5      I Sh  vN $  N N7f)a  
unWatches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9

:param str[] symbols: unified array of symbols
: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   zC unWatchOrderBookForSymbols() requires a non-empty array of symbolsrn   r   r   )	rM   rs   r   ro   r   rv   r   ry   r[   r   s	            rD   r   $defx.un_watch_order_book_for_symbols  s      !!!GA#DGG.s$stt%%g.q#g,'AZF~~f-HMM)h.1BBC  !67	 (
 ))&HHH 	" Ir   c           	         U R                  US0 5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nU R	                  X6USSSS5      nX`R
                  ;  a  U R                  U5      n	XR
                  U'   U R
                  U   n
U
R                  U5        SU-   nUR                  X5        g )	Nr   r]   r   bidsaskspriceqtyr   )	r   rw   rx   r   parse_order_book
orderbooks
order_bookresetr   )rB   r   rU   r   r   rx   r]   r   snapshotobr   r   s               rD   handle_order_bookdefx.handle_order_book5  s    6 ~~gvr2##D(3X&!%%dK8	((y&&RY[`a//)*B&(OOF#OOF+	!"V+y.rF   c                 d  #    U R                  U R                  S5      nUc  g  U R                  SU05      I S h  vN   U R                  U R                  SS	5      n	U R                  XR                  U5        g  N>! [         a  nU R                  S   S   S   S-   U-   nU R                  U5      n[        UR                  R                  5       5      n[        S[        U5      5       H  nXg   nUR                  X85        M     S U R                  S'   SU R                  S'    S nAg S nAff = f7f)
N	listenKeyr*   r   r(   ?listenKey=r   lastAuthenticatedTimer9   r+   )rw   r<   -v1PrivatePutApiUsersSocketListenKeysListenKey	Exceptionr;   r   ru   futureskeysrv   rs   rejectr   delaykeep_alive_listen_key)
rB   rR   r	  errorrS   r   rQ   jr   r9   s
             rD   r  defx.keep_alive_listen_key^  s    $$T\\;?		DDkS\E]^^^  $00?UW^_

')C)CVL _ 		))E"4(3mCiOC[[%F !4!4!67M1c-01+.e1 2 )-DLL%45DLL01		s>   !D0A; A9A; :D09A; ;
D-BD(#D0(D--D0c                 x  #    U R                  5       nU R                  U R                  SS5      nU R                  U R                  SS5      nX#-
  U:  ab  U R                  5       I S h  vN nU R	                  US5      U R                  S'   X R                  S'   U R                  X@R                  U5        g g  NO7f)Nr  r   r9   r+   r	  )millisecondsr   r<   %v1PrivatePostApiUsersSocketListenKeysrw   r  r  )rB   rR   timer  r9   responses         rD   authenticatedefx.authenticates  s       " $ 1 1$,,@WYZ [#00?UW^_'*>>!GGIIH(,(8(8;(ODLL%48LL01JJ+-G-GP	 ?Is   A&B:(B8)AB:c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  S   S   S   nSnUS-   U R                  S   -   nU R	                  XCSU5      I Sh  vN $  Nc NM N7f)a]  
query for balance and get the amount of funds available for trading or funds locked in orders

https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr*   r   r(   WALLET_BALANCE_UPDATEr
  r	  )rM   r  r;   r<   watch)rB   rR   baseUrlr   rS   s        rD   watch_balancedefx.watch_balance}  s      !!!!!!))E"4(3-%[(AAZZ$DDD 	"! Es2   B A:B A<AB 5A>6B <B >B c                 n   U R                  US5      nU R                  US/ 5      nU R                  US5      nU R                  c  0 U l        X@R                  S'   XPR                  S'   U R	                  U5      U R                  S'   U R                  US5      nU R                  U5      nXpR                  ;   a  U R                  U   OU R                  5       nU R                  US5      US'   XR                  U'   U R                  U R                  5      U l        UR                  U R                  U5        g )	Neventr   r   r   r   assetbalancefree)	rw   r   r   r&  r   safe_currency_codeaccountsafe_balancer   )	rB   r   rU   r   r   r   
currencyIdcoder)  s	            rD   handle_balancedefx.handle_balance  s    &&w8~~gvr2%%g{;	<<DL#V$-[!#'<<	#:Z %%dG4
&&z2)-)=$,,t$DLLN**4;$T((6t||[1rF   c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  S   S   S   nSnUb  U R                  U5      nUSUS   -   -  nUS-   U R                  S	   -   nU R                  XSU5      I Sh  vN n	U R                  (       a  U	R                  X5      nU R                  XX#S
5      $  N N N=7f)a  
watches information on multiple orders made by the user

https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809

:param str [symbol]: unified market symbol of the market the 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>`
Nr*   r   r(   ordersrr   r]   r
  r	  T)	rM   r  r;   rx   r<   r  rz   r{   filter_by_symbol_since_limit)
rB   r]   r_   r`   rR   r   r   rx   rS   r0  s
             rD   watch_ordersdefx.watch_orders  s      !!!!!!))E"4(3[[(F3!111K%[(AAzz#D+FF??OOF2E00tTT 	"! Gs2   CCCCA%CC:CCCc                 X   SnU R                  US0 5      nU R                  c-  U R                  U R                  SS5      n[	        U5      U l        U R                  nU R                  U5      nUR                  U5        US-   US   -   nUR                  Xc5        UR                  Xh5        g )Nr0  r   ordersLimitr   rr   r]   )r   r0  r   r<   r   parse_orderry   r   )	rB   r   rU   channelr   r`   r0  parsedOrderr   s	            rD   handle_orderdefx.handle_order  s    B ~~gvr2;;%%dllM4HE07DK&&t,k"mk(&;;v'v+rF   c                 @  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nU R                  S   S   S   nSnUS-   U R                  S   -   nSnUbU  / n	[        S[        U5      5       H  n
X   nU	R                  US	-   U-   5        M      U R                  XySU	5      I Sh  vN nOU R                  XvSU5      I Sh  vN nU R                  (       a  U$ U R                  U R                  XUS
5      $  N N NU N;7f)a  
watch all open positions

https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809

:param str[]|None symbols: list of unified market symbols
:param number [since]: since timestamp
:param number [limit]: limit
:param dict params: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
Nr*   r   r(   	positionsr
  r	  r   rr   T)rM   r  r   r;   r<   rv   rs   ry   rO   r  rz   filter_by_symbols_since_limitr<  )rB   r   r_   r`   rR   r   r7  rS   newPositionrQ   r   r]   s               rD   watch_positionsdefx.watch_positions  s     !!!!!!%%g.))E"4(3%[(AAM1c'l+ $$Ws]V%;< , !% 3 3Cm \\K $

3w GGK??11$..'RWY]^^# 	"! ]GsD   DDDDBDDD D!6DDDDc                 x   SnU R                  US0 5      nU R                  c  [        5       U l        U R                  nU R                  U5      nU R	                  US5      nXvS'   U R                  U5      US'   UR                  U5        US-   US   -   nUR                  U/U5        UR                  U/U5        g )Nr<  r   r   r   rr   r]   )r   r<  r   parse_positionr   r   ry   r   )	rB   r   rU   r7  r   cacheparsedPositionr   r   s	            rD   handle_positionsdefx.handle_positions  s    & ~~gvr2>>!35DN,,T2%%g{;	&/{#%)\\)%<z"^$mnX&>>'1'5rF   c                    U R                  US5      nUb-  U R                  US5      n[        U R                  S-   U-   5      eU R                  US5      nUbn  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  S.nU R                  Xe5      nUb	  U" X5        g g g )Nr,  msg r$  )ohlc
24hrTickerr   depthr  ORDER_UPDATEPOSITION_UPDATE)rw   r   ro   r   r   r   r  r-  r9  rE  r   )rB   r   rU   r  errorMsgr$  methods
exacMethods           rD   handle_messagedefx.handle_message-  s      &1''7H# 899  '2))"00,,//)-)<)< $ 1 1#'#8#8G 8J%6+ & rF   )r&  r0  r<  )N)8__name__
__module____qualname____firstlineno__r   rA   rV   r[   strr   r   ru   rd   rh   rb   rg   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	   r2  r9  r   r?  rE  rR  __static_attributes____classcell__)rC   s   @rD   r   r      s   6# 6p @B U CE U ?CQUdhqs ) ) )3 )^a )x|  ~B  yC )  BFb T3 T3 TUX T aesw  AC E$tCy/ EZ] Emp E@ ^` IT$s)_ Idg I4'@6 '@R 68 G GF G" 9; =C =s = 6:" E7 E E, 9=R Ig IC I*&2F &2P 8<B FW F7 F,	2V 	2 <@d[] S SS S Sbfglbm S 9; 
HC 
Hs 
H OSaenp Sd3i S S[^ Suyz  vA S> LN Ic IRU I0,F ,6 @DB PS P PS\ P =? 
L 
L3 
L SW_a !$s) !C !fo !4 PR IT#Y IVY I0'/ '/R 24 M* )+ Q *, E E 2V 24 04$UYbd U UC Us Uimnsit U2+,6 +,Z 8<$]ajl _W _C _WZ _quv~q _>6B,V , ,rF   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   async_supportr    rF   rD   <module>rd     sB     f f p p p p 4  * .p,4"" p,rF   