
    E#if                         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  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr   " S	 S
\R0                  R2                  5      rg)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)	AnyBalancesIntMarketOrder	OrderBookStrTickerTrade)Client)List)
BadRequest)NotSupported)NetworkErrorc                     ^  \ rS rSrS\4U 4S jjr0 4S\S\S\S\S\S	\S
\S\4S jjr0 4S\S\	4S jjr
0 4S\S\4S jjrS\4S jrS8S jrS8S\S\4S jjrS9S\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 rS\4S  jrS8S\4S! jjrS\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S0 4S\S\S\S\\"   4S' jjr#SSS0 4S\S\S\S\\   4S( jjr$0 4S\%4S) jjr&S\4S* jr'S+ r(S, r)0 4S- jr*0 4S. jr+S/ r,S0 r-S\4S1 jr.S\4S2 jr/S\4S3 jr0S\4S4 jr1S\S5\24S6 jr3S7r4U =r5$ ):bingx   returnc                   > U R                  [        [        U ]  5       0 SS_SS_SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSS.00SSS0SSSSSSS S!S"S#S$S%S&S'S(S).0SS*S+S,S-S.S/S0.0SSS1.S2S30S4S0S5.S6S70S8.5      $ )9NwsTwatchTradeswatchTradesForSymbolsFwatchOrderBookwatchOrderBookForSymbols
watchOHLCVwatchOHLCVForSymbolswatchOrderswatchMyTradeswatchTickerwatchTickerswatchBalanceunWatchOHLCVunWatchOrderBookunWatchTickerunWatchTradesapiz"wss://open-api-ws.bingx.com/marketz)wss://open-api-swap.bingx.com/swap-marketz(wss://open-api-cswap-ws.bingx.com/marketspotlinearinversei 6 gunzip
timeframes1m3m5m15m30m1h2h4h6h12h1d3d1w1M)r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   1min5min15min30min60min1day)r0   r2   r3   r4   r5   r:   )fetchBalanceSnapshotawaitBalanceSnapshotdepthd   ignoreDuplicates)listenKeyRefreshRater   swapr+   r$   r   r   	keepAlivei@w )hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    H/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/bingx.pyrR   bingx.describe   s   eT ; =dt ( !$	
 +E d ' t   t    #D     !&  D"M#M )0d !"""$$""""$""""#& !$$&&%$#	 -1,1!
 S#
 ' S,\ WSL@
 L L	    messageHashsubMessageHashsubscribeHashdataTypetopicmarket
methodNamec	                 "  #    S n	S n
S nU R                  XvU5      u  pU R                  XvUS5      u  pU	S:X  a#  U R                  U R                  S   S   U
5      nO"U R                  U R                  S   S   U	5      nU R	                  5       nUUSS.n/ nUb  UR                  US   5        SUU/U/UUS	.nU R                  US
5      nUb  UUS
'   U R                  US
5      nU R                  XU R                  X5      X?5      I S h  vN $  N7f)Nr,   rJ   r)   r   unsub)idr[   reqTypesymbolT)unsubscribera   subMessageHashesmessageHashessymbolsr\   symbolsAndTimeframes)
handle_market_type_and_paramshandle_sub_type_and_paramssafe_stringrM   uuidappend	safe_listomitwatchextend)rS   rX   rY   rZ   r[   r\   r]   r^   params
marketTypesubTypeurlra   requestrg   subscriptionrh   s                    rU   un_watchbingx.un_watcha   s9    
!??
TZ[
99*fV^_""499U#3D#97CC""499U#3D#9:FCYY[ 

 NN6(+,!/ 0)]
  $~~f6LM+3GL/0YYv'=>FZZ$++g2NP]lllls   DDD	Drc   c                 0  #    U R                  5       I Sh  vN   U R                  U5      nSnSnSnU R                  SX25      u  pBU R                  SX2S5      u  pRUS:X  a#  U R	                  U R
                  S   S   U5      nO"U R	                  U R
                  S   S   U5      nUS   S-   nU R                  S	US
   5      nU R                  5       n	U	US.n
US:X  a  SU
S'   SU	S.nU R                  XhU R                  X5      X5      I Sh  vN $  N 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://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change

: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"   r,   rJ   r)   r   ra   @tickertickerrc   ra   r[   subrb   Frd   ra   )
load_marketsr]   ri   rj   rk   rM   get_message_hashrl   rp   rq   )rS   rc   rr   r]   rs   rt   ru   r[   rX   rl   rv   rw   s               rU   watch_tickerbingx.watch_ticker   s5     !!!V$
!??v^
99-Yab""499U#3D#97CC""499U#3D#9:FC$<)+++HfX6FGyy{ 
 !&GI 
 ZZ$++g2NP[jjj1 	"0 ks"   DDC6DDDDc           
         #    U R                  5       I Sh  vN   U R                  U5      nUS   S-   nU R                  SUS   5      nSU-   nSnSnU R                  XeXdXsX5      I Sh  vN $  NW 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://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change

: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>`
Nra   r{   r|   rc   unsubscribe::r'   r   r]   r   rx   	rS   rc   rr   r]   r[   rY   rX   r\   r^   s	            rU   un_watch_tickerbingx.un_watch_ticker   s      !!!V$$<)+..x9IJ%6$
]];W\fpyyy 	" z"   A2A.AA2)A0*A20A2clientc                    U R                  US0 5      nU R                  US5      nUR                  R                  S5      S:  nU(       a  SOSnU R	                  US S U5      nUS   nU R                  X75      n	XR                  U'   UR                  XR                  SU5      5        U R                  US5      S	:X  a!  UR                  XR                  S5      5        g g )
NdatasrJ   r   r+   rc   r|   r[   z
all@ticker)	
safe_valuerk   ru   findsafe_marketparse_ws_tickertickersresolver   )
rS   r   messager   marketIdisSwaprs   r]   rc   r|   s
             rU   handle_tickerbingx.handle_ticker   s    n w3##D#.(A-%V6
!!(D$
C!%%d3%Vv44XvFGGZ0L@NN6#8#8#BC ArW   Nc                    U R                  US5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  0 SUS   _SU_SU R	                  U5      _SU R                  US5      _S	U R                  US
5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SS _SU R                  US5      _SU_SU_SS _SU R                  US5      _SS _SS _U R                  US5      U R                  US5      US.EU5      $ ) NCr   crc   	timestampdatetimehighhlowlbidB	bidVolumebaskA	askVolumeavwapopenocloselastpreviousClosechangep
percentageaveragevq)
baseVolumequoteVolumeinfo)safe_integerrk   r   safe_tickeriso8601)rS   r   r]   r   r   r   s         rU   r   bingx.parse_ws_ticker  s   . %%gs3	##GS1!!(3  #. !
fX&!
!
 Y/!
 D$$Wc2	!

 4##GS1!
 4##GS1!
 ))'37!
 4##GS1!
 ))'37!
 D!
 D$$Wc2!
 U!
 E!
 T!
 d&&w4!
  $!!
" t#!
$ **7C8++GS9)!
* + 	rW   rs   limitc                     Uc  SnU$ US:X  d  US:X  a  U R                  / SQU5      nU$ US:X  a  U R                  SS/U5      nU$ )NrG   rJ   future)   
      2   rG   r+   r   )find_nearest_ceiling)rS   rs   r   s      rU   #get_order_book_limit_by_market_type)bingx.get_order_book_limit_by_market_type3  sc    =E 	 V#zX'=112FN  v%112s)UCrW   unifiedChannelextrac                 B    UnUb	  USU-   -  nOUS-  nUb  USU-   -  nU$ )Nz::r    )rS   r   rc   r   hashs        rU   r   bingx.get_message_hash=  s=    D6M!DCKDD5L DrW   sincec                   #    U R                  5       I Sh  vN   U R                  U5      nUS   nSnSnSnU R                  SXT5      u  pdU R                  SXTS5      u  ptUS:X  a#  U R	                  U R
                  S   S   U5      nO"U R	                  U R
                  S   S   U5      nUS   S	-   n	S
U-   n
U R                  5       nUU	S.nUS:X  a  SUS'   SUS.nU R                  XU R                  X5      X5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      nU R                  SSS5      (       a%  U R                  U5      nU R                  US5      nU$ U$  GNf N|7f)a  
watches information on multiple trades made in a market

https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction

: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>`
Nrc   r   r,   rJ   r)   r   ra   @tradetrade::r}   r~   rb   Fr   r   TrH   )r   r]   ri   rj   rk   rM   rl   rp   rq   
newUpdatesgetLimitfilter_by_since_limithandle_option!remove_repeated_trades_from_arraysort_by)rS   rc   r   r   rr   r]   rs   rt   ru   rawHashrX   rl   rv   rw   tradesresultfiltereds                    rU   watch_tradesbingx.watch_tradesG  s     !!!V$!
!??v^
99-Yab""499U#3D#97CC""499U#3D#9:FC,)&(yy{
 !&GI 
 zz#DKK4PR]ll??OOF2E++F5+tTm-?FF==fEH||Hk:HOC 	"2 ms#   FE<C+FE?A:F?Fc           
         #    U R                  5       I Sh  vN   U R                  U5      nUS   S-   nU R                  SUS   5      nSU-   nSnSnU R                  XeXdXsX5      I Sh  vN $  NW N7f)	a  
unsubscribes from the trades channel

https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction

:param str symbol: unified symbol of the market to fetch trades for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.name]: the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
Nra   r   traderc   r   r   r(   r   r   s	            rU   un_watch_tradesbingx.un_watch_tradesx  s      !!!V$$<(*..wx8HI%6$
]];W\fpyyy 	" zr   c                    U R                  US/ 5      nU R                  US5      nUR                  S5      S   nUR                  R	                  S5      S:  nU(       a  SOSnU R                  US S U5      nUS   n	SU	-   n
S n[        U[        5      (       a  U R                  X85      nOU R                  X85      /nU R                  U R                  U	5      nUc6  U R                  U R                  S	S
5      n[        U5      nXR                  U	'   [        S[        U5      5       H  nUR!                  X   5        M     UR#                  X5        g )Nr   r[   @r   rJ   r+   rc   r   tradesLimit  )r   rk   splitru   r   r   
isinstancelistparse_tradesparse_trader   r   rN   r   rangelenrm   r   )rS   r   r   r   r   r   r   rs   r]   rc   rX   r   storedr   js                  rU   handle_tradesbingx.handle_trades  s1   d w3""7J7==%a((A-%V6
!!(D$
C!&(dD!!&&t4F&&t45Ff5>%%dllM4HE&F"(KKq#f+&AMM&)$ 'v+rW   c                   #    U R                  5       I Sh  vN   U R                  U5      nSnSnSnU R                  SXC5      u  pSU R                  SXCS5      u  pcUS:X  a#  U R	                  U R
                  S   S   U5      nO"U R	                  U R
                  S   S   U5      nU R                  U R                  S0 5      nU R                  USS5      n	US	   S
-   S-   U R                  U	5      -   n
U R                  SUS   5      nU R                  5       nUU
S.nUS:X  a  SUS'   0 nUS   (       a  USUUS.nOUSUUS.nU R                  X{U R                  X5      X5      I Sh  vN nUR                  5       $  GNg N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth

: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   r,   rJ   r)   r   rF   rG   ra   r   	orderbookrc   r}   r~   rb   r-   F)ra   rd   countrr   )ra   rd   levelrr   )r   r]   ri   rj   rk   rM   	safe_dictrN   r   number_to_stringr   rl   rp   rP   r   )rS   rc   r   rr   r]   rs   rt   ru   rN   rF   subscriptionHashrX   rl   rv   subscriptionArgsr   s                   rU   watch_order_bookbingx.watch_order_book  s     !!!V$
!??@PRXa
99:JF\de""499U#3D#97CC""499U#3D#9:FC../?D!!'7C8!$<#-7$:O:OPU:VV++K9IJyy{(
 !&GI!#)$ 	  $ 	  **St7G7G7XZj}}	  M 	"J ~s"   FE=EF(F )F Fc           
      H  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  S0 5      nU R	                  USS5      nUS   S-   S-   U R                  U5      -   nSU-   nSnS	n	U R                  XvXvXX5      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://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth

:param str symbol: unified symbol of the market
: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   rF   rG   ra   r   r   r   r&   )r   r]   r   rN   r   r   rx   )
rS   rc   rr   r]   rN   rF   rY   rX   r\   r^   s
             rU   un_watch_order_bookbingx.un_watch_order_book+  s      !!!V$../?D!!'7C8+g58M8Me8TT%6'
]];]blv 	" @s"   B"BBB"B B" B"c                 r    U R                  USS5      nU R                  USS5      nUR                  X45        g )Nr   r      r   )safe_float_2store)rS   booksidedeltapriceamounts        rU   handle_deltabingx.handle_deltaA  s6    !!%C0""5!S1u%rW   c           	         U R                  US0 5      nU R                  US5      nUR                  S5      nUS   nUS:H  nU R                  USU5      nUR                  R	                  S5      S:  n	U	(       a  SOSn
U R                  US S U
5      nUS   nU R                  U R                  U5      nUcB  UnUR                  U   nU R                  US	5      nU R                  0 U5      U R                  U'   U R                  U   nS nU R                  US
S5      nU R                  US
SU5      nUS   (       a  U R                  X<USSSS5      nOU R                  X<USSSS5      nU R                  US5      nUUS'   UR                  U5        U R                  SU5      nUR                  UU5        U(       a$  U R                  S5      nUR                  UU5        g g )Nr   r[   r   r   allrc   rJ   r+   r   r   tsr-   bidsasksr   r   r   lastUpdateIdnoncer   )r   rk   r   ru   r   r   r   
orderbookssubscriptionsr   
order_booksafe_integer_2parse_order_bookresetr   r   )rS   r   r   r   r[   parts	firstPartisAllEndpointr   r   rs   r]   rc   r   r   rw   r   snapshotr   r  rX   messageHashForAlls                         rU   handle_order_bookbingx.handle_order_bookF  s   H ~~gvr2##GZ8s#!H	"e+##D(I>(A-%V6
!!(D$
C!OODOOV<	'!//0@AL%%lG<E&*oob%&@DOOF#OOF+	''dC	''k4K	),,T9ffVY[^_H,,T9ffVWYZ[H!!$7!!++K@y+. $ 5 5k BNN9&78 rW   c           	         US   (       a  SOSnUS   (       a  US   (       a  SOSnU R                  X5      U R                  US5      U R                  US5      U R                  US5      U R                  US	5      U R                  US
5      /$ )Nr+   tTrJ   r-   r   r   r   r   r   )r   safe_number)rS   ohlcvr]   r   s       rU   parse_ws_ohlcvbingx.parse_ws_ohlcv  s     #6NC	&> &y 1Ie/UC(UC(UC(UC(UC(
 	
rW   c                    UR                   R                  S5      S:  nU R                  US5      nUR                  S5      nUS   nUS:H  nU R                  USU5      nU(       a  SOSn	U R	                  US S U	5      n
S nU(       a3  U
S   (       a  U R                  US	0 5      /nO;U R                  US	/ 5      nO'U R                  US	0 5      nU R                  US
0 5      /nU
S   nU R                  U R                  U0 5      U R                  U'   UR                  S5      S   nU R                  U R                  U	5      nU R                  US0 5      nU R                  UU5      nU R                  U R                  U   U5      c>  UnUR                  U   nU R                  US5      n[        U5      U R                  U   U'   U R                  U   U   n[        S[        U5      5       H+  nUU   nU R!                  UU
5      nUR#                  U5        M-     UUU/nU R%                  SUU5      nUR'                  UU5        U(       a&  U R%                  SS U5      nUR'                  UU5        g g )NrJ   r   r[   r   r	  r   r+   r-   r   Krc   _r   r/   r   r   )ru   r   rk   r   r   r   rn   r   ohlcvsrN   find_timeframer  r   r   r   r   r!  rm   r   r   )rS   r   r   r   r[   r  r  r  r   rs   r]   candlesr   rc   rawTimeframemarketOptionsr/   unifiedTimeframer   rw   r   r   icandleparsedresolveDatarX   r  s                               rU   handle_ohlcvbingx.handle_ohlcv  s`   B (A-##GZ8s#!H	"e+##GS)<%V6
!!(D$
Ci >>'62>?..&"=>>'626D~~dC45G!"oodkk62FF~~c*1-t||Z@^^M<D
..|ZH??4;;v.=E'!//0@AL%%lG<E4I%4PDKK 01V$%56q#g,'AQZF((8FMM&! ( /8++GV=MN{K0 $ 5 5gtEU VNN;(9: rW   r0   	timeframec                 ~  #    U R                  5       I Sh  vN   U R                  U5      nSnSnSn	U R                  SXe5      u  puU R                  SXeS5      u  pUS:X  a#  U R	                  U R
                  S   S   U5      n	O"U R	                  U R
                  S   S   U5      n	U	c  [        U R                  S-   U-   S-   5      eU R                  U R                  U0 5      n
U R                  U
S	0 5      nU R	                  XU5      nU R                  S
US   U5      nUS   S-   U-   nU R                  5       nUUS.nUS:X  a  SUS'   USUUS.nU R                  XU R                  UU5      UU5      I Sh  vN nUS   nU R                  (       a  UR                  X5      nU R!                  UX4SS5      $  GN NB7f)a6  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line

: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   r,   rJ   r)   r   z! watchOHLCV is not supported for z	 markets.r/   r   rc   ra   @kline_r}   r~   rb   F)ra   rd   intervalrr      r   T)r   r]   ri   rj   rk   rM   r   ra   r   rN   r   rl   rp   rq   r   r   r   )rS   rc   r2  r   r   rr   r]   rs   rt   ru   rN   r/   r)  rX   r   rl   rv   r   r   r   s                       rU   watch_ohlcvbingx.watch_ohlcv1  s     !!!V$
!??f]
99,X`a""499U#3D#97CC""499U#3D#9:FC;TWW'JJZWZeeff//$,,
B?__WlB?
''
yI++GVH5EyQ!$<)3lByy{(
 !&GI $	"
 zz#DKK4PRbdtuuq	??NN61E))%q$GGG 	"> vs#   F=F8E!F=8F;9A F=;F=c           
      f  #    U R                  5       I Sh  vN   U R                  U5      nU R                  U R                  US   0 5      nU R                  US0 5      nU R	                  XbU5      nUS   S-   U-   nSU-   n	Sn
SnUS	   U//nXS
'   U R                  XXXX5      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://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line

: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typer/   ra   r4  r   r   r%   rc   rh   )r   r]   r   rN   rk   rx   )rS   rc   r2  rr   r]   rN   r/   r)  rY   rX   r\   r^   rh   s                rU   un_watch_ohlcvbingx.un_watch_ohlcve  s      !!!V$//$,,vC__WlB?
''
yI	1L@%6#
!'!19 =>)=%&]];]blv 	" @s"   B1B-BB1(B/)B1/B1c                 F  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnSnSnUb  U R                  U5      nUS   nU R                  SXt5      u  pTU R	                  SXtS5      u  pdUS:H  nSn	Sn
U(       a  U	OU
nSnS	nU(       a  UOUnUb  US
U-   -  nU R                  5       nSnSnUS:X  aA  US:X  a  [        U R                  S-   5      eU R                  U R                  S   S   U5      nO(U R                  U R                  S   S   U5      nUSSS.nUS-   U R                  S   -   nSUS.nU R                  UUUUU5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  UXUS5      $  GN GNn N@7f)a  
watches information on multiple orders made by the user

https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push

:param str [symbol]: unified market symbol of the market orders are made in
:param int [since]: the earliest time in ms to watch 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>`
Nrc   r    r,   r+   spot:privateswap:private
spot:order
swap:order:rJ   r-   z: watchOrders is not supported for inverse swap markets yetr)   r   r~   spot.executionReportra   rb   r[   ?listenKey=	listenKeyFr   Tr   authenticater]   ri   rj   rl   r   ra   rk   rM   rN   rp   r   r   filter_by_symbol_since_limit)rS   rc   r   r   rr   r:  rt   r]   isSpotspotHashswapHashr   spotMessageHashswapMessageHashrX   rl   baseUrlrv   ru   rw   orderss                        rU   watch_ordersbingx.watch_orders  s     !!!!!![[(FH%F99-X99-Yab&.!!'-88&&)/o_3<'Kyy{6>)#"477-i#ijj&&tyy'7'=wGG&&tyy'7'=tDG 2G
 %[(AA 
 zz#{G=M|\\??OOF2E00tTTS 	"!J ]2   F!FF!FD/F!F;F!F!F!c                 F  #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnSnSnUb  U R                  U5      nUS   nU R                  SXt5      u  pTU R	                  SXtS5      u  pdUS:H  nSn	Sn
U(       a  U	OU
nSnS	nU(       a  UOUnUb  US
U-   -  nU R                  5       nSnSnUS:X  aA  US:X  a  [        U R                  S-   5      eU R                  U R                  S   S   U5      nO(U R                  U R                  S   S   U5      nUSSS.nUS-   U R                  S   -   nSUS.nU R                  UUUUU5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  UXUS5      $  GN GNn N@7f)a  
watches information on multiple trades made by the user

https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push

:param str [symbol]: unified market symbol of the market the trades are made in
:param int [since]: the earliest time in ms to watch 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>`
Nrc   r!   r,   r+   r>  r?  spot:mytradesswap:mytradesrB  rJ   r-   z< watchMyTrades is not supported for inverse swap markets yetr)   r   r~   rC  rD  rE  rF  Fr   TrG  )rS   rc   r   r   rr   r:  rt   r]   rJ  rK  rL  r   rM  rN  rX   rl   rO  rv   ru   rw   r   s                        rU   watch_my_tradesbingx.watch_my_trades  s     !!!!!![[(FH%F99/6Z99/6[cd&.!!'-88)))/o_3<'Kyy{6>)#"477-k#kll&&tyy'7'=wGG&&tyy'7'=tDG 2G
 %[(AA 
 zz#{G=M|\\??OOF2E00tTTS 	"!J ]rS  c                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SnSnU R                  SSU5      u  p!U R                  SSUS5      u  p1US:H  nSnSnSnSnU(       a  UOUn	U(       a  UOUn
SnSnU R	                  5       nUS:X  aA  US	:X  a  [        U R                  S
-   5      eU R                  U R                  S   S   U5      nO'U R                  U R                  S   S   U5      nUSS.nUS-   U R                  S   -   nU R                  U5      nU R                  XX:U5        SnSnU R                  USSS5      u  nnU R                  USSS5      u  nnU(       a#  U(       a  UR                  US-   5      I Sh  vN   SUS.nU R                  XXU5      I Sh  vN $  GN GN N* N7f)aZ  
query for balance and get the amount of funds available for trading or funds locked in orders

https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20account%20balance%20push
https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Account%20balance%20and%20position%20update%20push

: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+   zspot:balancer?  zswap:balancerJ   r-   z; watchBalance is not supported for inverse swap markets yetr)   r   ACCOUNT_UPDATEr}   rE  rF  rD   TrE   F:fetchBalanceSnapshotr   )r   rH  ri   rj   rl   r   ra   rk   rM   rN   r   set_balance_cachehandle_option_and_paramsr   rp   )rS   rr   r:  rt   rJ  spotSubHashswapSubHashrM  rN  rX   r   rv   rO  rl   ru   r   rD   rE   rw   s                      rU   watch_balancebingx.watch_balance  s     !!!!!!99.$PVW99.$PVX`a&.$$(()/o_*0;kyy{6>)#"477-j#jkk&&tyy'7'=wGG&&tyy'7'=tDG,G %[(AAS!vWO##'+'D'DV^]suy'z$f'+'D'DV^]suz'{$f$8--'> >??? 
 ZZ'\ZZZO 	"!B @
 [sD   GF<GF?E(GGG7G8G?GGGc                     XAR                   ;   a  g U R                  USSS5      nU(       aD  US-   nXqR                  ;  a/  UR                  U5        U R	                  U R
                  XX#5        g g 0 U R                  U'   g )Nr$   rD   Tr[  )r  r]  futuresr   spawnload_balance_snapshotbalance)rS   r   r:  rt   r   rr   rD   rX   s           rU   r\  bingx.set_balance_cache%  sy    333#<<V^Ukmqr!88K>>1k*

455vDZ 2 "$DLLrW   c                 :  #    U R                  X4S.5      I S h  vN nU R                  XPR                  U R                  U0 5      5      U R                  U'   UR                  U   nUR                  5         UR                  U R                  U   US-   5        g  N7f)N)r:  rt   :balance)fetch_balancerq   r   rf  rc  r   )rS   r   rX   r:  rt   responser   s          rU   re  bingx.load_balance_snapshot1  s     ++T,NOO![[??4<<QUWY3Z[T,t||D)4*+<= Ps   BBB Bc                     U R                  US5      n Ub@  U R                  S-   U R                  U5      -   nU R                  U R                  S   X45        g! [
         a  nUR                  U5         S nAgS nAff = f)Ncode exactT)rk   ra   jsonthrow_exactly_matched_exception
exceptions	Exceptionreject)rS   r   r   rn  feedbackes         rU   handle_error_messagebingx.handle_error_message9  s~     0	77S=499W+==44T__W5Mt^   	MM!	s   AA 
A="A88A=c                   #    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/ SQn[	        S[        U5      5       H  nXE   nU R                  S   S   U   S-   U-   nU R                  U5      n[        UR                  R                  5       5      n	[	        S[        U	5      5       H  n
X   nUR                  X;5        M     M     S U R                  S'   SU R                  S'    S nAg S nAff = f7f)
NrF  r*   r   r)   r   rE  lastAuthenticatedTimerI   6 )rk   rN    userAuthPrivatePutUserDataStreamrt  r   r   rM   r   r   rc  keysru  r   delaykeep_alive_listen_key)rS   rr   rF  errortypesr,  r:  ru   r   rf   r   rX   rI   s                rU   r  bingx.keep_alive_listen_keyL  s=    $$T\\;?		77i8PQQQ  $00?UW^_

')C)CVL! R 	1E1c%j)xii&t,T2]BYNS) $V^^%8%8%: ;q#m"45A"/"2KMM%5 6 * )-DLL%45DLL01	s>   !EA; A9A; :E9A; ;
ECEEEE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   rI   r|  rF  )millisecondsr   rN   !userAuthPrivatePostUserDataStreamrk   r  r  )rS   rr   timer{  rI   rk  s         rU   rH  bingx.authenticated  s       " $ 1 1$,,@WYZ [#00?UW^_'*>>!CCEEH(,(8(8;(ODLL%48LL01JJ+-G-GP	 ?Es   A&B:(B8)AB:c                 z  #     US:X  a  UR                  S5      I S h  vN   g U R                  US5      nU R                  US5      nUR                  UUS.5      I S h  vN   g  NF N! [         aE  n[        U R                  S-   U R                  U5      -   5      nUR                  U5         S nAg S nAff = f7f)NPingPongpingr  )pongr  z pong failed with error )sendrk   rt  r   ra   rq  r  )rS   r   r   r  r  rw  r  s          rU   r  
bingx.pongn  s     	 & kk&)))''8''8kk  #   	 *  	  +E!E		RS!TUELL	 sZ   B;A) A%A) B;;A) A' A) $B;%A) 'A) )
B83;B3.B;3B88B;c                 ~   SU;   nU R                  US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   nSn	Sn
U(       a  U	OU
nUR                  Xk5        UR                  XkS	-   U-   5        g )
Nr[   r   r   ordersLimitr   rc   r@  rA  rB  )safe_value_2rP  r   rN   r   parse_orderrm   r   )rS   r   r   rJ  r   r   r   parsedOrderrc   rK  rL  rX   s               rU   handle_orderbingx.handle_order  s    h '  &#r:;;%%dllM4HE07DK&&t,k"X&#)hv+vS069:rW   c                    SU;   nU R                  USS0 5      nU R                  nUc.  U R                  U R                  SS5      n[	        U5      nXPl        U(       a  SOSnU R                  US5      nU R                  US S	U5      n	U R                  XI5      n
U
S
   nSnSnU(       a  UOUnUR                  U
5        UR                  X^5        UR                  X^S-   U-   5        g )Nr[   r   r   r   r   r+   rJ   r   -rc   rU  rV  rB  )
safe_dict_2myTradesr   rN   r   rk   r   r   rm   r   )rS   r   r   rJ  r   cachedTradesr   r:  r   r]   r.  rc   rK  rL  rX   s                  rU   handle_my_tradesbingx.handle_my_trades  s    r '!!'63;}}%%dllM4HE1%8L(MvV##FC0!!(D#t<!!&1!"""(hhF#|1|3%6%?@rW   c                 
   U R                  US0 5      nU R                  US/ 5      nU R                  USS5      nSU;   a  SOSnX`R                  ;  a  0 U R                  U'   X@R                  U   S'   XPR                  U   S	'   U R	                  U5      U R                  U   S
'   [        S[        U5      5       Hy  nXG   nU R                  US5      n	U R                  U	5      n
U R                  5       nXS'   U R                  US5      US'   U R                  US5      US'   XR                  U   U
'   M{     U R                  U R                  U   5      U R                  U'   UR                  U R                  U   US-   5        g )Nr   r   r  EPrJ   r+   r   r   r   r   lkusedwbfreeri  )r   rn   r  rf  r   r   r   rk   safe_currency_codeaccountsafe_balancer   )rS   r   r   r   r   r   r:  r,  rf  
currencyIdrn  r  s               rU   handle_balancebingx.handle_balance5  sm   J NN7C,~~ab)''c:	(v$!#DLL%)T6"*3T;')-i)@T:&q#d)$AgG))'37J**:6DllnG%FO"..w=GFO"..w=GFO'.LLt$ % "..t||D/ABTt||D)4*+<=rW   c                    U R                  X5      (       d  g US:X  d  SU;   a  U R                  U R                  X5        g U R                  USS5      nUR	                  S5      S:  a  U R                  X5        g UR	                  S5      S:  a  U R                  X5        g UR	                  S5      S:  a  U R                  X5        g UR	                  S	5      S:  a  U R                  X5        g UR	                  S
5      S:  aN  U R                  US0 5      nU R                  US5      nUS:X  a  U R                  X5        U R                  X5        g U R                  US5      nUS:X  a  U R                  X5        US:X  ae  U R                  X5        U R                  US0 5      nU R                  US5      nU R                  US5      nUS:X  a  US:X  a  U R                  X5        U R                  US5      nU R                  US5      n	U	S:X  a  U R                  X5        US:X  a  U	c  Uc  U R                  X5        g g g g )Nr  r  r[    z@depthr   r{   r   z@klineexecutionReportr   xTRADErw  rZ  ORDER_TRADE_UPDATEr   XFILLED	24hTicker)rx  rd  r  rk   r   r  r   r   r0  r   r  r  r  handle_subscription_status)
rS   r   r   r[   r   r:  rw  statusmsgDatamsgEvents
             rU   handle_messagebingx.handle_messageo  s$   ((99v6W#4JJtyy&2##GZ<=="a'""63==#q(v/=="a'v/=="a'f.==*+q0??7FB7D##D#.Dw%%f6f.Wc*  0$$f.??7C4D##D#.D%%dC0Ff&8%%f6//'62##GS1{"v/r>h.19++F< 4=.>rW   c                     U R                  US5      nU R                  UR                  S5      nU R                  XC0 5      nU R	                  USS5      nU(       a  U R                  X5        U$ )Nra   rd   F)rk   index_byr  r   	safe_boolhandle_un_subscription)rS   r   r   ra   subscriptionsByIdrw   isUnSubMessages          rU   r   bingx.handle_subscription_status  sf     gt, MM&*>*>E~~&7R@mUK''=rW   rw   c                     U R                  US/ 5      nU R                  US/ 5      n[        S[        U5      5       H  nX5   nXE   nU R                  XU5        M     U R	                  U5        g )Nrf   re   r   )rn   r   r   clean_unsubscriptionclean_cache)rS   r   rw   rf   re   r,  	unsubHashsubHashs           rU   r  bingx.handle_un_subscription  sn    |_bI>>,8JBOq#m,-A%(I&)G%%fyA . 	&rW   )r  rP  )N)NN)6__name__
__module____qualname____firstlineno__r   rR   strr	   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r!  r0  r7  r;  r
   rQ  rW  r   r`  r\  re  rx  r  rH  r  r  r  r  r  r  dictr  __static_attributes____classcell__)rT   s   @rU   r   r      sB   M# M^ \^ m# ms mSV mbe mnq m  |B m  PS m  cf mB 68 $k $kF $kL 9; zC zs z*BDF BDH0dc # s C s  <@d[] / /S / /bfglbm /b 9; zC zs z,f,F f,P @DB 3!S 3! 3!S\ 3!j =? @ @3 @,&
e9 e9N
D 
4h;6 h;T ?CQUdhqs 2H 2H 2H3 2H^a 2Hx|  ~B  yC 2Hh BFb @3 @3 @UX @4 04$UYbd 7U 7UC 7Us 7Uimnsit 7Ur 37TX\eg 7UC 7Us 7URU 7Ulpqvlw 7Ur *, 2[ 2[h
$ 
$>& 24 M0 )+ Q 0a;FJAv JAX8>V 8>t*=V *=X "'V '4 ' 'rW   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   ccxt.base.typesr   r   r   r	   r
   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   async_supportr   r   rW   rU   <module>r     sB     f f \ \ \ 4  ' ) )c'D$$ c'rW   