
    E#i                       S SK rS SKJrJrJrJr  S SK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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	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\RF                  RH                  5      r$g)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesBoolIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)ArgumentsRequired)
BadRequest)RateLimitExceeded)ChecksumError)UnsubscribeError)Precisec                   @  ^  \ rS rSrS\4U 4S jjrS0 4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
0 4S\S\4S jjrS\4S jrSGS jrS
0 4S\S\4S jjrS\4S jrSGS 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\4S jrSGS\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0 4S\S\S\S\4S jjrS
0 4S\\   S\S\4S  jjr S\4S! jr!S\S\S"\4S# jr"S$ r#S% r$S
S
0 4S\S\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)SGS* jr*S
S
S
0 4S\S\S\S\\+   4S+ jjr,S\4S, jr-SGS- jr.S
S
S
0 4S\/S\S\S\\0   4S. jjr1S\4S/ jr2SGS0 jr3S1 r4S
S
S
0 4S\/S\S\S\\%   4S2 jjr5S\4S3 jr60 4S\74S4 jjr8S\4S5 jr90 4S6 jr:0 4S7 jr;0 4S8 jr<0 4S9 jr=0 4S: jr>S\4S; jr?S\S\@4S< jrAS\4S= jrBS\4S> jrCS\4S? jrDS\4S@ jrES\4SA jrFS\4SB jrGS\4SC jrHS\4SD jrIS\4SE jrJSFrKU =rL$ )Hbitget   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S.ESSSSSS.SSSSS.S.0S S S!S"S#S$S%S&S'S(S)S*S+S,.S-S0S.S0S/.S0U R                  0S[
        [        [
        [        [        [        [        [        [        [        [
        [        [
        S1.0 S2.0S3.5      $ )4NwsTcreateOrderWsFeditOrderWsfetchOpenOrdersWsfetchOrderWscancelOrderWscancelOrdersWscancelAllOrdersWswatchBalancewatchMyTrades
watchOHLCVwatchOHLCVForSymbolswatchOrderBookwatchOrderBookForSymbolswatchOrderswatchTickerwatchTickers)watchBidsAskswatchTradeswatchTradesForSymbolswatchPositionsapiz wss://ws.bitget.com/v2/ws/publicz!wss://ws.bitget.com/v2/ws/privatez wss://ws.bitget.com/v3/ws/publicz!wss://ws.bitget.com/v3/ws/private)publicprivate	utaPublic
utaPrivatez#wss://wspap.bitget.com/v2/ws/publicz$wss://wspap.bitget.com/v2/ws/privatez#wss://wspap.bitget.com/v3/ws/publicz$wss://wspap.bitget.com/v3/ws/private)r"   demo  1m3m5m15m30m1H4H6H12H1D1W)r>   r?   r@   rA   rB   1h4h6h12h1d1wchecksumignoreDuplicates)tradesLimit
OHLCVLimit
timeframesr.   r4   ping)30001300023000330004300053000630007300113001230013300143001530016)exactbroad)hasurlsoptions	streaming
exceptions)deep_extendsuperr   describerT   r   r   r   )self	__class__s    I/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/bitget.pyrk   bitget.describe   s   fd < >d u $U	
    !% $U    d ' !$ +D t  t!" #$ "&#)-"&+0 "D#F%G&I	 #H#I%J&L	"  $"     # ' )2 		 !+!4!+!4!4!2!2!4!4!4!+!4!+  !GWA
 W W	    Futac                 2   Ub  U(       d  U R                  USSS5      u  p#S nUc  U R                  S U5      u  pCO*US   (       d
  US   (       a  U R                  X5      u  pCOSnS nU R                  USSU5      u  pSUnU(       a  UR                  5       nXC/$ )NgetInstTyperq   FswapfutureSPOTinstType)handle_option_and_paramshandleProductTypeAndParamslower)rl   marketrq   paramsrw   
instypeAuxs         rn   get_inst_typebitget.get_inst_typer   s    K77uV[\KC>#>>tVLHfVn&"2#>>vNHfH
!::6=R\^fg
~~'H!!rp   symbolc                 R  #    U R                  5       I Sh  vN   U R                  U5      nUS   nSU-   nSnSnU R                  USSS5      u  pbU R                  X6U5      u  pRSU0nU(       a  SOS	nU(       a  SOS
n	SXx'   US   Xy'   U R	                  XGU5      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://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel

:param str symbol: unified symbol of the market to watch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   ticker:r1   rq   Frw   topicchannelinstIdtickerid)load_marketsr{   rx   r~   watch_public)
rl   r   r|   r{   messageHashrw   rq   argstopicOrChannelsymbolOrInstIds
             rn   watch_tickerbitget.watch_ticker   s      !!!V$!&(33FM5RWX--f6B
 %(Y%(h'%d|&&{&AAA 	" Bs"   B'B#BB'B%B'%B'c                 z   #    U R                  5       I Sh  vN   U R                  USSU5      I Sh  vN $  N  N7f)ax  
unsubscribe from the ticker channel

https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel

:param str symbol: unified symbol of the market to unwatch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns any: status of the unwatch request
Nr   )r   un_watch_channel)rl   r   r|   s      rn   un_watch_tickerbitget.un_watch_ticker   s;      !!!**68XvNNN 	"Ns   ;7;9;;Nsymbolsc                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  US   5      nSnSnU R                  USSS5      u  pRU R	                  X5U5      u  pB/ n/ n[        S[        U5      5       Hb  nX   n	U R                  U	5      n
SU0nU(       a  SOSnU(       a  S	OS
nSX'   U
S   X'   UR                  U5        UR                  SU	-   5        Md     U R                  XvU5      I Sh  vN nU R                  (       a  0 nXUS	   '   U$ U R                  U R                  S	U5      $  G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.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel

:param str[] symbols: unified symbol of the market to watch the tickers for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr   r2   rq   rw   r   r   r   r   r   r   r   )r   market_symbolsr{   rx   r~   rangelenappendwatch_public_multiple
newUpdatesfilter_by_arraytickersrl   r   r|   r{   rw   rq   topicsmessageHashesir   marketInnerr   r   r   r   results                   rn   watch_tickersbitget.watch_tickers   sX     !!!%%gtU;WQZ(33FNESXY--f6Bq#g,'AZF++f-KHD ),WN),X(N#+D #.t#4D MM$  V!34 ( 22=&QQ??F(/78$%M##DLL(GDD5 	"* R"   EEC-EE>EEclientc                     U R                  X5        U R                  U5      nUS   nX0R                  U'   SU-   nUR                  X55        g )Nr   r   )handle_bid_askparse_ws_tickerr   resolverl   r   messager   r   r   s         rn   handle_tickerbitget.handle_ticker   sO    p 	F,%%g.!%V&(v+rp   c           	         U R                  US0 5      nU R                  US/ 5      nU R                  US0 5      nU R                  US5      nU R                  USU5      nU R                  US5      nUS:X  a  SOSn	U R                  US5      n
U R                  US	U
5      nU R	                  XS U	5      nU R                  US
S5      nU R                  USS5      nU R                  US[        R                  " US5      5      nU R                  0 SUS   _SU_SU R                  U5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  USS 5      _S!U R                  US"S#5      _S$S _S%U R                  US&S'5      _S(U_S)U_S*S _S+S _S,U_S-S _U R                  US.S/5      U R                  US0S15      US2.EU5      $ )3Nargdatar   tsrw   spotcontractr   r   lastPr	lastPrice	change24h price24hPcnt100	timestampdatetimehighhigh24hhighPrice24hlowlow24hlowPrice24hbidbidPr	bid1Price	bidVolumebidSzbid1SizeaskaskPr	ask1Price	askVolumeaskSzask1Sizevwapopenopen24hopenPrice24hcloselastpreviousClosechange
percentageaverage
baseVolume	volume24hquoteVolumeturnover24h)r   r   info)

safe_valuesafe_integersafe_string_lowersafe_stringsafe_marketsafe_string_2r   
string_mulsafe_tickeriso8601)rl   r   r{   r   r   r   utaTimestampr   rw   
marketTypeutaMarketIdmarketIdr   changeDecimalr   s                  rn   r   bitget.parse_ws_ticker  s   | oogub1w3q"-(($7%%fdLA	))#z: (F 2V
&&sH5##FHkB!!(D*E""68[A((bA!!&.':L:L]\a:bc !
fX&!
!
 Y/!
 D&&vy.I	!

 4%%fhF!
 4%%fg{C!
 ++FGZH!
 4%%fg{C!
 ++FGZH!
 D!
 D&&vy.I!
 U!
 E!
 T!
 d!
  &!!
" t#!
$ ,,V\;O--fm]S)!
* + 	rp   c                   #    U R                  5       I Sh  vN   U R                  USS5      nU R                  US   5      nSnSnU R                  USSS5      u  pRU R	                  X5U5      u  pB/ n/ n[        S[        U5      5       Hb  nX   n	U R                  U	5      n
SU0nU(       a  SOSnU(       a  S	OS
nSX'   U
S   X'   UR                  U5        UR                  SU	-   5        Md     U R                  XvU5      I Sh  vN nU R                  (       a  0 nXUS	   '   U$ U R                  U R                  S	U5      $  GN, N@7f)aD  
watches best bid & ask for symbols

https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Tickers-Channel

:param str[] symbols: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NFr   r3   rq   rw   r   r   r   r   r   r   bidask:)r   r   r{   rx   r~   r   r   r   r   r   r   bidsasksr   s                   rn   watch_bids_asksbitget.watch_bids_asks  sX     !!!%%gtU;WQZ(33FOUTYZ--f6Bq#g,'AZF++f-KHD ),WN),X(N#+D #.t#4D MM$  V!34 ( 22=&QQ??F(/78$%M##DMM8WEE5 	"* Rr   c                 x    U R                  U5      nUS   nX0R                  U'   SU-   nUR                  X55        g )Nr   r   )parse_ws_bid_askr   r   r   s         rn   r   bitget.handle_bid_ask  s>    &&w/! &f&(v+rp   c                 H   U R                  US0 5      nU R                  US/ 5      nU R                  US0 5      nU R                  US5      nU R                  USU5      nU R                  US5      nUS:X  a  SOSn	U R                  US5      n
U R                  US	U
5      nU R	                  XS U	5      nU R                  US   UU R                  U5      U R                  US
S5      U R                  USS5      U R                  USS5      U R                  USS5      US.U5      $ )Nr   r   r   r   rw   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   )rl   r   r{   r   r   r   r   r   rw   r   r   r   s               rn   r   bitget.parse_ws_bid_ask  s7   oogub1w3q"-(($7%%fdLA	))#z: (F 2V
&&sH5##FHkB!!(D*EX&"Y/%%fg{C++FGZH%%fg{C++FGZH	!
 	 		rp   r>   	timeframesincelimitc                 l  #    U R                  5       I Sh  vN   U R                  U5      nUS   nU R                  U R                  S5      nU R	                  Xr5      nSn	Sn
SnU R                  USSS5      u  pU R                  XkU5      u  pSU
0nU(       a+  SUS	'   US
   US'   XS'   U R                  USS05      nSU-   n	OSU-   US'   US
   US'   SU-   S-   U-   n	U R                  XU5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  GN N=7f)aQ  
watches historical candlestick data containing the open, high, low, close price, and the volume of a market

https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Candlesticks-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Candlesticks-Channel

: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
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns int[][]: A list of candles ordered, open, high, low, close, volume
Nr   rS   r,   rq   Frw   kliner   r   intervalTkline:candler   r   candles::r   )r   r{   r   rf   r   rx   r~   extendr   r   getLimitfilter_by_since_limit)rl   r   r   r   r   r|   r{   rS   r   r   rw   rq   r   ohlcvs                 rn   watch_ohlcvbitget.watch_ohlcv  sZ      !!!V$!__T\\<@
##J:33FL%QVW--f6B
 #DM#D\DN'[[%7F"V+K&1DO#D\DN$y036?K''6BB??NN61E))%q$GG5 	". Cs"   D4D/CD44D25;D42D4c                    #    U R                  5       I Sh  vN   U R                  U R                  S5      nU R                  XB5      nSnSnUb  U R	                  U5      nSnSn	Sn
U R                  USSS5      u  pU R                  XzU5      u  pSU0nU
(       a/  SnXkS'   US	   US
'   X[S'   U R                  USS05      nXSS'   Xa-   n	OSU-   nXkS'   US	   US'   SU-   n	U R                  XX5      I Sh  vN $  N N7f)a  
unsubscribe from the ohlcv channel

https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Candlesticks-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Candlesticks-Channel

:param str symbol: unified symbol of the market to unwatch the ohlcv for
:param str [timeframe]: the period for the ratio, default is 1 minute
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
NrS   unWatchOHLCVrq   Frw   r   r   r   r   r   Tr   r   r   r   )	r   	safe_dictrf   r   r{   rx   r~   r  r   )rl   r   r   r|   rS   r   r   r{   rw   r   rq   r   s               rn   un_watch_ohlcvbitget.un_watch_ohlcv  s7     !!!^^DLL,?
##J:[[(F33FNESXY--f6B
 G#M#D\DN'[[%7F!):!*K)G%O#D\DN$x/K**6KPPP9 	"8 Qs"   C>C:CC>5C<6C><C>c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  US S U5      nUS   nU R                  U R                  U0 5      U R                  U'   U R                  USS5      n	U R                  US	5      n
S nU
c  S
nU	R                  SS5      n
OSnU R                  U R                  S5      nU R                  X5      nU R                  U R                  U   U5      nUc9  U R                  U R                  SS5      n[        U5      nXR                  U   U'   U R                  US/ 5      n[        S[        U5      5       H)  nU R                  UU   U5      nUR                  U5        M+     S nU(       a  SU-   nOSU-   S-   U-   nUR                  UU5        g )Nr   rw   r   r   r   r   r   r   r   Fr   r   TrS   rR   r=   r   r   r   r   r  )r   r   r   r   ohlcvsr   replacerf   find_timeframer   r   r   r   parse_ws_ohlcvr   r   )rl   r   r   r   rw   r   r   r{   r   r   r   isUtarS   r   storedr   r   r   parsedr   s                       rn   handle_ohlcvbitget.handle_ohlcv7  s   t oogub1))#z: (F 2V
%%c8X>!!(D$
C!"oodkk62FF$$S)W=##C4Ex4HE__T\\<@
''=	V!4i@>%%dllL$GE*51F-3KK	*w3q#d)$A((a&9FMM&! % "V+K$y036?Kv{+rp   c           
          US   (       a  SOSnU R                  USS5      U R                  USS5      U R                  USS	5      U R                  US
S5      U R                  USS5      U R                  USU5      /$ )Ninverse      startr   r      r      r      r      volume)safe_integer_2safe_number_2)rl   r  r{   volumeIndexs       rn   r  bitget.parse_ws_ohlcv  s    2 #9-aAw2ufa0ufa0ueQ/ugq1uh<
 	
rp   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.bitget.com/api-doc/spot/websocket/public/Depth-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel

: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
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
: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)rl   r   r   r|   s       rn   watch_order_bookbitget.watch_order_book  s"      66xOOOOs     c                   #    U R                  5       I Sh  vN   SnU R                  US5      nUS:X  d  US:X  d  US:X  d  US:X  a   U R                  US5      nU[        U5      -  nU R	                  XSU5      I Sh  vN $  Nk N7f)	a  
unsubscribe from the orderbook channel

https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel

:param str symbol: unified symbol of the market to fetch the order book for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.limit]: orderbook limit, default is None
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nbooksr   r  r     2   	orderbook)r   r   omitstrr   )rl   r   r|   r   r   s        rn   un_watch_order_bookbitget.un_watch_order_book  s      !!!!!&'2QJEQJERKUb[YYvw/Fs5z!G**6KPPP 	" Qs"   BBA&B=B>BBr   messageHashTopicc                   #    U R                  5       I S h  vN   U R                  U5      nSU-   S-   US   -   nS nS nU R                  USSS5      u  pU R                  XXU5      u  ptSU0n	U(       aI  X)S'   US	   U	S'   U R	                  US
S5      U	S
'   U R                  USS05      nU R                  US
5      nOX)S'   US	   U	S'   U R                  XiU5      I S h  vN $  N N7f)Nzunsubscribe:r  r   unWatchChannelrq   Frw   r   r   r   r>   Tr   r   )r   r{   rx   r~   r   r  r.  un_watch_public)
rl   r   r   r2  r|   r{   r   rw   rq   r   s
             rn   r   bitget.un_watch_channel  s    !!!V$$'77#=x@PP33F<LeUZ[--f6B
 #M#D\DN#//
DID[[%7FYYvz2F%O#D\DN))+VDDD' 	"& Es"   C&C"CC&C$C&$C&c                   #    U R                  5       I Sh  vN   U R                  U5      nSnSnUS:X  d  US:X  d  US:X  d  US:X  a  U[        U5      -  nSn/ n/ nSnU R                  US	S
S5      u  p[	        S[        U5      5       Hx  n	X   n
U R                  U
5      nSnU R                  XU5      u  pSU0nU(       a  SOSnU(       a  SOSnXMU'   US   X'   UR                  U5        UR                  SU
-   5        Mz     U(       a  SUS
'   U R                  XvU5      I Sh  vN nU(       a  UR                  5       $ U$  GN. N 7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
https://www.bitget.com/api-doc/uta/websocket/public/Order-Book-Channel

: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
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr*  Tr  r  r+  r,  Fr/   rq   r   rw   r   r   r   r   r   
orderbook:)r   r   r/  rx   r   r   r{   r~   r   r   r   )rl   r   r   r|   r   incrementalFeedr   r   rq   r   r   r{   rw   r   r   r   r-  s                    rn   r&  #bitget.watch_order_book_for_symbols  sd     !!!%%g.QJEQJERKUb[s5z!G#O33F<VX]_deq#g,'AZF[[(FH#11&vFHHD ),WN),X(N#* #)$<D MM$  !67 (  F5M44]FSS	??$$? 	"6 Ts"   E	EDE	&E'E	E	c                    U R                  US5      nU R                  USS5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  US S U5      nUS   n	S	U	-   n
U R                  US
5      nU R                  US5      nU R	                  US5      nUS:H  nU(       Ga  XR
                  ;  a#  U R                  0 5      nXS'   XR
                  U	'   U R
                  U	   nU R                  USS/ 5      nU R                  USS/ 5      nU R                  US   U5        U R                  US   U5        UUS'   U R                  U5      US'   U R                  SSS5      nU R                  US5      S:H  nU(       Gd  U(       Ga  US   nUS   n[        U5      n[        U5      n/ n[        SS5       Hy  nUU:  a4  UR                  UU   S   S   5        UR                  UU   S   S   5        UU:  d  ME  UR                  UU   S   S   5        UR                  UU   S   S   5        M{     SR                  U5      nU R!                  US5      nU R	                  US5      nUU:w  a  U R#                  U R$                  XU
5        g OCU R'                  0 5      nU R)                  XU5      nUR+                  U5        UU R
                  U	'   UR-                  U R
                  U	   U
5        g )Nr   r   r   rw   r   r   r   r   r8  r   r   r   r*  asksabidsbr   r   r.   rO   Tactionsnapshot   r  r  r  )r   r   r   r   r   
orderbookscounted_order_booksafe_list_2handle_deltasr   handle_optionr   r   r   r   joincrc32spawnhandle_check_sum_error
order_bookparse_order_bookresetr   ) rl   r   r   r   r   rw   r   r   r{   r   r   r   rawOrderBookr   incrementalBookobstoredOrderBookr<  r>  rO   
isSnapshot
storedAsks
storedBids
asksLength
bidsLengthpayloadArrayr   payloadcalculatedChecksumresponseChecksumr-  parsedOrderbooks                                    rn   handle_order_bookbitget.handle_order_book   s   ^ oogu-$$S)W=))#z: (F 2V
%%c8X>!!(D$
C!"V+w/tQ/%%lD9	!W,oo-,,R0%8*,'"oof5O##L&#rBD##L&#rBDv6=v6=+4OK(*.,,y*AOJ'))*:JMH))'8<
JJ(,V4
,V4
 _
 _
!q"A:~$++JqM!,<Q,?@$++JqM!,<Q,?@:~$++JqM!,<Q,?@$++JqM!,<Q,?@ & ((<0%)ZZ%>"#'#4#4\:#N %)99
 JJt::FKX+I"33L)TOOOO,&/DOOF#tv.<rp   r   c                    #    U R                  U5      I S h  vN   [        U R                  S-   U R                  U5      -   5      nUR	                  XC5        g  N@7f)N )r0  r   r   orderbook_checksum_messagereject)rl   r   r   r   errors        rn   rK  bitget.handle_check_sum_error  sL     &&v...dggmd.M.Mf.UUVe) 	/s   AAAAc                 n    U R                  USS5      nUR                  U5        UR                  U5        g )Nr   r  )parse_bid_askr   
storeArray)rl   booksidedeltabidAsks       rn   handle_deltabitget.handle_delta  s2    ##E1a0 	eF#rp   c                 d    [        S[        U5      5       H  nU R                  XU   5        M     g )Nr   )r   r   rk  )rl   rh  deltasr   s       rn   rF  bitget.handle_deltas  s)    q#f+&Ahq	2 'rp   c                 F   #    U R                  U/X#U5      I Sh  vN $  N7f)a  
get the list of most recent trades for a particular symbol

https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel

: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
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
N)watch_trades_for_symbols)rl   r   r   r   r|   s        rn   watch_tradesbitget.watch_trades  s$      22F8U6RRRRs   !!c                   #    [        U5      nUS:X  a  [        U R                  S-   5      eU R                  5       I Sh  vN   U R	                  U5      nSnU R                  USSS5      u  pd/ n/ n[        S[        U5      5       H  n	X   n
U R                  U
5      nSnU R                  XU5      u  pSU0nU(       a  SOS	nU(       a  S
OSnU(       a  SOSX'   US   X'   UR                  U5        UR                  SU
-   5        M     U(       a  U R                  USS05      nU R                  XU5      I Sh  vN nU R                  (       a6  U R                  US5      nU R                  US
5      nUR                  UU5      nU R!                  UX#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N N7f)a  
get the list of most recent trades for a particular symbol

https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel

:param str[] symbols: 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
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
r   z> watchTradesForSymbols() requires a non-empty array of symbolsNr5   rq   Frw   r   r   r   r   publicTradetrader   trade:Tr   r4   rP   )r   r   r   r   r   rx   r   r{   r~   r   r  r   r   r   r   r  r  rG  !remove_repeated_trades_from_arraysort_by)rl   r   r   r   r|   symbolsLengthrq   r   r   r   r   r{   rw   r   r   r   tradesfirsttradeSymbolr   filtereds                        rn   rq  bitget.watch_trades_for_symbols  s     GA#DGG.n$noo!!!%%g.33F<SUZ\abq#g,'AZF[[(FH#11&vFHHD ),WN),X(N47=WD #)$<D MM$  F!23 ( [[%7F11-PP??OOFA.E**5(;KOOK7E++FE+tTm-?FF==fEH||Hk:HOA 	", Qs$   =GG C;G;G<BGGc                    #    SnU R                  USSS5      u  p2U(       a  SOSnU R                  XSU5      I Sh  vN $  N7f)a"  
unsubscribe from the trades channel

https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel

:param str symbol: unified symbol of the market to unwatch the trades for
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns any: status of the unwatch request
NunWatchTradesrq   Fru  rv  )rx   r   )rl   r   r|   rq   channelTopics        rn   un_watch_tradesbitget.un_watch_trades  sI      33FOUTYZ(+}**6&QQQQs   :AAAc                 N   U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  US S U5      nUS   nU R                  U R                  U5      n	U	c6  U R                  U R                  SS5      n
[        U
5      n	XR                  U'   U R                  US	/ 5      n[        U5      n[        S
U5       H0  nX-
  S-
  nX   nU R                  X5      nU	R                  U5        M2     SU-   nUR                  U	U5        g )Nr   rw   r   r   r   r   rQ   r=   r   r   r  rw  )r   r   r   r   r{  r   rf   r   	safe_listr   r   parse_ws_trader   r   )rl   r   r   r   rw   r   r   r{   r   r  r   r   lengthr   indexrawTrader  r   s                     rn   handle_tradesbitget.handle_trades  s&   F oogub1))#z: (F 2V
%%c8X>!!(D$
C!f5>%%dllM4HE&F"(KK~~gvr2Tq&!AJNE{H((:FMM&!	 "
 'v{+rp   c                 Z   U R                  USS5      nU R                  US5      nU R                  US5      nS nUb  US:w  a  SOSnOUb  SOSnUc  U R                  US S U5      nU R                  U/ SQ5      nU R	                  US	/ 5      nU R                  US
5      n	S n
U	bM  U R                  U	S5      nU R                  U5      n[        R                  " U R                  U	SS5      5      US.n
U R                  UU R                  U/ SQ5      U R                  USS5      UU R                  U5      US   U R                  US5      U R                  USS5      U R                  US5      U R                  U/ SQ5      U R                  U/ SQ5      U R                  U/ SQ5      U
S.U5      $ )Nr   r   posModecategoryrv   r   r   )uTimecTimer   TexecTime	feeDetailr   feeCointotalFeefeecostcurrency)tradeIdr   execIdorderIdL	orderTypesideS
tradeScope)priceAvgprice	execPriceP)sizer   execQtyv)amountr   	execValue)r   r   orderr   r   r   typer  takerOrMakerr  r  r  r  )r   r   r   safe_integer_nr  r
  safe_currency_coder   
string_abs
safe_tradesafe_string_nr   )rl   rv  r{   r   r  r  defaultTyper   r  r|  r  feeCurrencyIdfeeCurrencyCodes                rn   r  bitget.parse_ws_trade)  s   ~ ##E8X>""5)4##E:6)1V);*&K)0)<*6K>%%fdD+FF''/XY	NN5+r:	y!, ,,UI>M"55mDO**4+=+=eZQV+WX+C $$U,FG''y#>"Y/X&$$UK8&&ufc: ,,ULA''/VW((0VW&&u.TU 
  	rp   c                 <  #    U R                  5       I Sh  vN   SnSnSnSnSn	U R                  USSS5      u  pU R                  U5      nU R                  U5      (       d%  U R	                  U5      nU R                  XYU5      u  pU	(       a  SnUS	-   U-   nS
U0n
U	(       a  SOSnU	(       a  SOSnXU'   U	(       d  SU
S'   OU R                  USS05      nU R                  XgX5      I Sh  vN nU R                  (       a  U$ U R                  XX#S5      $  GN N-7f)a-  
watch all open positions

https://www.bitget.com/api-doc/contract/websocket/private/Positions-Channel
https://www.bitget.com/api-doc/uta/websocket/private/Positions-Channel

:param str[]|None symbols: list of unified market symbols
:param int [since]: the earliest time in ms to fetch positions for
:param int [limit]: the maximum number of positions to retrieve
:param dict params: extra parameters specific to the exchange API endpoint
:param str [params.instType]: one of 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES', default is 'USDT-FUTURES'
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
Nr   	positionsUSDT-FUTURESr6   rq   FUTA
:positionsrw   r   r   positiondefaultr   T)
r   rx   r   is_emptyget_market_from_symbolsr~   r  watch_privater   filter_by_symbols_since_limit)rl   r   r   r   r|   r{   r   subscriptionHashrw   rq   r   r   r   newPositionss                 rn   watch_positionsbitget.watch_positions  s3     !!!&!33F<LeUZ[%%g.}}W%%11':F#11&vFHH-;
 %(Y #*&^&DN[[%7F!//t\\??11,W[\\7 	"0 ]s"   DDCD,D-+DDc                    U R                  US0 5      nU R                  USS5      nU R                  c  0 U l        U R                  US5      nX@R                  ;  d  US:X  a  [        5       U R                  U'   U R                  U   nU R	                  US/ 5      n/ n[        S[        U5      5       Ha  n	Xy   n
U R                  U
SS	5      nU R                  US S S
5      nU R                  X5      nUR                  U5        UR                  U5        Mc     U R                  XS-   5      n[        S[        U5      5       Hl  n	X   nUR                  S5      nUS   nUR                  S5      nU R                  US	US5      nU R                  U5      (       a  MZ  UR                  UU5        Mn     UR                  XS-   5        g )Nr   rw   r   r@  rA  r   r   r   r   r   z:positions::z::r  ,Fr  )r
  r   r  r   r  r   r   r   r   parse_ws_positionr   find_message_hashessplitr   r  r   )rl   r   r   r   rw   r@  cacherawPositionsr  r   rawPositionr   r{   r  r   r   partssymbolsStringr   r  s                       rn   handle_positionsbitget.handle_positions  s   Z nnWeR0##CR8>>!DN!!'84NN**0D'?'ADNN8$x(~~gvr:q#l+,A&/K))+xJH%%hdJGF--kBH)LL" - 00N9RSq#m,-A'*K%%d+E!!HM#))#.G,,\8WeTI==++y+6 . 	|%<=rp   c                    U R                  USS5      nU R                  US5      nU R                  USSS.5      nU R                  USS5      nUS	:X  a  S
OSnU R                  U/ SQ5      nU R                  USS5      n	[        R
                  " U	S5      n
S nUb  US   nU R                  0 SU_SU R                  US5      _SU R                  X2S S5      _SS _SU_SU R                  USS5      _SU R                  USS5      _SU R                  USS5      _SU R                  U
5      _SU R                  US S!5      _SU_S"U R                  US"5      _S#U R                  US$S%5      _S&U_S'U_S(U R                  U5      _S)S _U R                  US*S+5      U R                  US,5      U R                  US-5      S U R                  US.5      U R                  US/5      S0.E5      $ )1Nr   r   
marginModecrossisolated)crossedr  r  holdMode
hedge_modeTF)updatedTimer  r  createdTimeunrealizedPLR
profitRater   contractSizer   r   posIdr   notionalliquidationPriceliqPrice
entryPriceopenPriceAvgavgPriceunrealizedPnlunrealizedPLunrealisedPnlr   	contractstotalr  	markPricer  holdSideposSidehedgedr   r   maintenanceMarginkeepMarginRatemmr	available
marginSizeleverage
marginRate)maintenanceMarginPercentage
collateralinitialMargininitialMarginPercentager  marginRatio)r   r   get_supported_mappingr  r   r   safe_positionsafe_symbolr"  parse_numbersafe_numberr   )rl   r  r{   r   marginModeIdr  hedgedIdr  r   percentageDecimalr   r  s               rn   r  bitget.parse_ws_positionB  s   n %%h(C'',?//"?
 
 %%h	:F"l2''2bc	 ..x,W''(95A
!.1L!! #
H#
$""8W5#
 d&&xzJ#
 	#

 *#
  2 28=OQ[ \#
 $,,X~zR#
 T//./Z#
 $++J7#
 ++HgvF#
 L#
 ))(K@#
 D&&xYG#
 f#
 #
  Y/!#
"  ##
$ ,0+=+=hHXZ_+`**8[A!--hE'+((:>++HlC/#
  	rp   c                 `  #    U R                  5       I Sh  vN   SnSnSnU R                  U5      u  ptU(       a  SOSnSn	Ub#  U R                  U5      nUS   nUS   nUS-   U-   nSn
U R                  USS	S
5      u  pU R	                  US5      nSnU R                  SXT5      u  pSnU R                  SXTS5      u  pUS:X  d  US:X  a  Uc  SnUc  US:w  a  Uc	  US-   U-   nO#US:X  a  US-   nOUS:X  a  US-   nOUS:X  a  US-   nSnUc	  US:X  a  SnOU R                  XZU5      u  pUS:X  a  Ub  U	S-   U-   n	U(       a  U	S-   n	US:X  d  US:X  a  UOSnU(       a  SOSnSnU R                  SU5      u  nnUb  SnUS-   U-   nUS:X  a  SnOSnU
(       a  SnSnU	S-   U-   n	SU0nU
(       a  S OS!nUUU'   U
(       d  UUS"'   OU R                  US	S#05      nU R                  XU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 N=7f)$a!  
watches information on multiple orders made by the user

https://www.bitget.com/api-doc/spot/websocket/private/Order-Channel
https://www.bitget.com/api-doc/spot/websocket/private/Plan-Order-Channel
https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
https://www.bitget.com/api-doc/contract/websocket/private/Plan-Order-Channel
https://www.bitget.com/api-doc/margin/cross/websocket/private/Cross-Orders
https://www.bitget.com/api-doc/margin/isolated/websocket/private/Isolate-Orders
https://www.bitget.com/api-doc/uta/websocket/private/Order-Channel

: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
:param boolean [params.trigger]: *contract only* set to True for watching trigger orders
:param str [params.marginMode]: 'isolated' or 'cross' for watching spot margin orders]
:param str [params.type]: 'spot', 'swap'
:param str [params.subType]: 'linear', 'inverse'
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NtriggerOrderr  zorder:tradesr   r   r  r0   rq   FproductTypelinearr   marginr  r  z:linearzCOIN-FUTURESz:inversezUSDC-FUTURESz:usdcfuturesrv   z:stoporders-algoordersMARGINr  orders-isolatedorders-crossedr  rw   r   r   r   T)r   is_trigger_orderr{   rx   r   handle_market_type_and_paramshandle_sub_type_and_paramsr~   handle_margin_mode_and_paramsr  r  r   r  filter_by_symbol_since_limit)rl   r   r   r   r|   r{   r   	isTriggerr   r  rq   r  r  subTyperw   r   r   r  r   r   r
  s                        rn   watch_ordersbitget.watch_orders  s    . !!!	 11&9	)2n)[[(FH%Fd|H%+f4K33FM5RWX&&v}=99-X99-YabFNdh.V^ Hdfn6>%+g5KN*%	1KN*%
2KN*%6K>dfnH#11&vFH6>v1/#5>/'9"fn0@y#,-(
!??vV
F!H%+j8KZ'+*HG+c1H<
 %(Y&^#DN[[%7F))+vVV??OOF2E00tTTC 	"| Ws"   H.H)GH..H,/;H.,H.c                    U R                  US0 5      nU R                  USS5      nU R                  US5      nU R                  US5      nS nUS:X  a  SnOUS:X  a  SnOSnU R	                  US	/ 5      nU R                  US
0 5      n	U R                  U	SU5      n
U
S:H  nU
S:H  nU
S:H  nU R
                  c=  U R                  U R                  SS5      n[        U5      U l        [        U5      U l	        US:H  =(       d    US:H  nU(       a  U R                  OU R
                  nU(       a  SOSn0 n[        S
[        U5      5       H]  nUU   nU R                  USSU5      nU R                  US S U5      nU R                  UU5      nUR                  U5        US   nSUU'   M_     [        UR!                  5       5      n[        S
[        U5      5       H9  nUU   nUS-   U-   nUS:X  a  US-   nOUS:X  a  US-   nUR#                  UU5        M;     UR#                  UU5        U(       a  UR#                  US5        U(       a  UR#                  US5        U(       a  UR#                  US5        g g )Nr   r   r   rw   r   r   r  r   r   r   r  zusdt-futureszcoin-futureszusdc-futuresordersLimitr=   r	  
ordersAlgor  r  r   Tr  r  z:crossr  z	:isolatedzorder:linearzorder:inversezorder:usdcfutures)r
  r   r   r   r  r
  r   rf   r   triggerOrdersr   r   r   parse_ws_orderr   listkeysr   )rl   r   r   r   r   rw   	argInstIdr   r   r|  r  isLinearSwapisInverseSwapisUSDCFuturesr   r  r  r   marketSymbolsr   r  r   r{   r  r   r  innerMessageHashs                              rn   handle_orderbitget.handle_order  sx   d nnWeR0$$S)W=))#z:$$S(3	
vJ!J#J~~gvr2tQ+))%XF N2!^3!^3;;%%dllM4HE07DK!7!>D-K7l3J	'0##dkk(1nw q#d)$AGE))%8YOH%%hdJGF((7FMM&!H%F$(M&! % M&&()q#d)$A!WF*S069**#3h#> --#3k#A NN6#34 % 	v{+NN6>2NN6?3NN6#67 rp   c           	         SU;  nSU;   nU R                  US5      nUS:X  a  SnUS:X  a  SnU R                  USS5      nU R                  Xb5      nU R                  US	S
5      nUS   nU R                  USS5      n	U R	                  US/ 5      n
U R	                  U
S5      nU R                  US5      nS nUbI  U R                  US5      nU R                  [        R                  " U5      5      U R                  U5      S.nU R                  US5      nUS LnS nU(       d  U R                  US5      nO U(       a  U(       a  U R                  US5      nU R                  U R                  U/ SQ5      5      nU R                  US5      nU R                  US5      nU R                  U R                  USS5      5      nU R                  U R                  USS5      5      nUS:H  nUS:H  nS nS nS nS nU R                  USS5      nU(       a  U(       a:  U R                  USS5      nU R                  US S5      nU R                  US!S5      nO}U R                  US 5      nUb  UnOUnU(       a  U(       a  UnUnOPUnOMU R                  USS5      nO9U R                  US S5      nU R                  US"S5      nU R                  US#S5      n[        R                  " UU5      nU R                  0 S$U_SU_S%U R                  US&5      _S'U R                  US(5      _S)U_S*U R                  U5      _S+U R                  US,S-5      _S.U_S/U R!                  US0S/5      _S1S _SU_SU_SU_S2U_S3U_S4U_S5U_UU R#                  U	5      US S6.EU5      $ )7Nr  loanTyper  r   Tr  r   r   r  r  statusorderStatusr  r   r  r  r  triggerPricer  executePrice)r  	fillPricer  r  r  accBaseVolume
cumExecQtynewSizecumExecValuer{   buybaseSizeqtyr   fillTotalAmountr  fillNotionalUsdr   r   r  clientOrderId	clientOidr   r   lastTradeTimestampr  r  r  timeInForceforcepostOnlyr  r  r   filled)	remainingr(  r  r{  )r   r   r   r!  r   r   r  r   r  r  r  	omit_zerosafe_string_lower_n
string_sub
safe_orderr   safe_string_upper_2parse_ws_order_status)rl   r  r{   isSpotisMarginr  r   r   r   	rawStatusorderFeer  	feeAmount	feeObjectfeeCurrencyr*  isTriggerOrderr  r  r  r  r-  newSizeValueisMarketOrderisBuytotalAmountfilledAmountr  r=  totalFilledpartialFillAmounts                                  rn   r  bitget.parse_ws_order  sC   v  5(%'))%<vFxH%%eXx@!!(3''wF	!&&uhF	??5+r:ooh*$$S%0		 **3	:K))'*<*<Y*GH 33K@I ''~>&d2$$UG4E$$UN;E>>$":":5Bg"hiv.{3t'9'9%R^'_`~~d&8&8	>&Z[)	((N"00
EJ"00lS))%1BNS$($4$4UL$I!$0#4L#.L &3+&2 #'"4"4UIu"MK  --e\<PL,,UFEBK%%e->OD&&{K@	  
E 
f 
 $""5)4 
 T--e[A	 

  
 Y/ 
 !$"5"5eWm"T 
 D 
 433E7MR 
  
 D 
 U 
 L 
 k 
 D 
  x! 
" l# 
$ #00;+ 
, - 	rp   c                 6    SSSSSS.nU R                  X!U5      $ )Nr   closedcanceled)livepartially_filledr<  	cancellednot_trigger)r   )rl   r(  statusess      rn   rC  bitget.parse_ws_order_statusw  s-     &#!
 &99rp   c                 P  #    U R                  5       I Sh  vN   SnSnUb  U R                  U5      nUS   nUS-   U-   nSnU R                  SXT5      u  ptSnSn	U R                  USSS5      u  pUc	  US:X  a  S	nOU R	                  XYU5      u  pU	(       a  S
nSU-   n
SU0nU	(       a  SOSnSX'   U	(       d  SUS'   OU R                  USS05      nU R                  XjX5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  GN N<7f)ag  
watches trades made by the user

https://www.bitget.com/api-doc/contract/websocket/private/Fill-Channel
https://www.bitget.com/api-doc/uta/websocket/private/Fill-Channel

: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 exchange API endpoint
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
NmyTradesr   r  r+   rq   Fr   rv   r  zfill:rw   r   r   fillr  r   T)
r   r{   r  rx   r~   r  r  r   r  r  )rl   r   r   r   r|   r{   r   r  rw   rq   r  r   r   r{  s                 rn   watch_my_tradesbitget.watch_my_trades  sM     !!! [[(FH%F%+f4K99/6Z33FOUTYZ>dfnH#11&vFHH"X-
 %(Y%&DN[[%7F))+VV??OOF2E00tTT? 	"8 Ws"   D&D!CD&'D$(:D&$D&c                    U R                   c-  U R                  U R                  SS5      n[        U5      U l         U R                   nU R	                  US/ 5      n[        U5      nSn[        SU5       HD  nXX   n	U R                  U	5      n
UR                  U
5        U
S   nSU-   nUR                  XL5        MF     UR                  XG5        g )NrQ   r=   r   r^  r   r   z	myTrades:)
r^  r   rf   r   r  r   r   r  r   r   )rl   r   r   r   r  r   r  r   r   rv  r  r   symbolSpecificMessageHashs                rn   handle_my_tradesbitget.handle_my_trades  s    \ == %%dllM4HE&u-DM~~gvr2T q&!AGE((/FMM&!H%F(3f(<%NN6= " 	v+rp   c                    #    SnU R                  USSS5      u  p!SnU R                  SSU5      u  p1SnU R                  SU5      u  pASnSnUS:X  d  US:X  a  SnO!Ub  S	nU(       d  US
:X  a  SnOSnO	U(       d  SnU R                  USSU5      u  pQU(       a  SnSU0nU(       a  SOSnXgU'   U(       d  SUS'   OU R                  USS05      nSUR	                  5       -   n	U R                  XXq5      I Sh  vN $  N7f)aA  
watch balance and get the amount of funds available for trading or funds locked in orders

https://www.bitget.com/api-doc/spot/websocket/private/Account-Channel
https://www.bitget.com/api-doc/contract/websocket/private/Account-Channel
https://www.bitget.com/api-doc/margin/cross/websocket/private/Margin-Cross-Account-Assets
https://www.bitget.com/api-doc/margin/isolated/websocket/private/Margin-isolated-account-assets
https://www.bitget.com/api-doc/uta/websocket/private/Account-Channel

:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.type]: spot or contract if not provided self.options['defaultType'] is used
:param str [params.instType]: one of 'SPOT', 'MARGIN', 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
:param str [params.marginMode]: 'isolated' or 'cross' for watching spot margin balances
:param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr*   rq   Faccountrt   ru   r  r  r  account-isolatedaccount-crossedrv   rw   r  r   r   r  coinTbalance:)rx   r  r  r  rz   r  )
rl   r|   rq   r  r  rw   r   r   r   r   s
             rn   watch_balancebitget.watch_balance.  s.    " 33FNESXY99.$PVW
!??PVW
FN 0%H#H+0G/GH88Q[]efH
 %(Y&^$DL[[%7F 8>>#33''$OOOOs   C5C>7C<8C>c                 J   U R                  US0 5      nU R                  US5      nU R                  US/ 5      n[        S[	        U5      5       GH  nXV   nUS:X  Ga  U R                  US/ 5      n[        S[	        U5      5       H  n	X   n
U R                  U
S5      nU R                  U5      nXR                  ;   a  U R                  U   OU R                  5       nU R                  U
S5      nU R                  U
S5      nUc  Ub  [        R                  " X5      US	'   U R                  U
S
5      US'   U R                  U
S5      US'   U R                  U
S5      US'   XR                  U'   M     GM&  U R                  USS5      nU R                  U5      nXR                  ;   a  U R                  U   OU R                  5       nU R                  US5      nUb,  U R                  US5      n[        R                  " UU5      US	'   SU;   a  SOS
nU R                  UU5      US'   U R                  US5      US'   U R                  US5      US'   XR                  U'   GM     U R                  U R                  5      U l        SU-   nUR                  U R                  U5        g )Nr   rw   r   r   rq   rj  borrowdebtsdebtr  freelockedusedbalancer  
marginCoininterestmaxTransferOutequityfrozenrk  )r
  r   r   r   r   r  r   r  ru  rg  r   
string_addr   safe_balancer   )rl   r   r   r   rw   r   r   
rawBalancecoinsjentry
currencyIdcoderg  ro  rp  rw  	freeQueryr   s                      rn   handle_balancebitget.handle_balancea  s|   r nnWeR0))#z:w3q#d)$AJ5 z62>q#e*-A!HE!%!1!1%!@J22:>D59\\5Idll40PTP\P\P^G!--eX>F ,,UG<E*0A*1*<*<V*K&*&6&6uk&JGFO&*&6&6uh&GGFO'+'7'7y'IGG$)0LL& . "//
FLQ
..z:151E$,,t,DLLN))*h?%#//
JGH&-&8&8&JGFO1AZ1O,Va	"&"2"2:y"I#'#3#3J#I "&"2"2:x"H%,T"; %< ((6 8+t||[1rp   c                   #    S nS nU R                  USSS5      u  pCU(       a  U R                  S   S   S   nOU R                  S   S   S   nU R                  U R                  SS	S5      nU(       aV  U R	                  US
5      nUS:w  a>  US:w  a8  US:w  a2  U(       a  U R                  S   S   S   nOU R                  S   S   S   nSU/S.nU R                  X5      n	U R                  XQX5      I S h  vN $  N7f)NwatchPublicrq   Fr7   r"   r:   r8   sandboxModesandboxrw   SCOIN-FUTURESSUSDT-FUTURESSUSDC-FUTURESr<   	subscribeopr   rx   re   safe_bool_2rf   r   r  watch
rl   r   r   r|   rq   urlr  rw   requestr   s
             rn   r   bitget.watch_public  s    33FM5RWX))E"4(5C))E"4(2C&&t||]IuU''j9HO+(o2MT\`oTo))E*62;?C))E*628<CF
 ++g.ZZ'GGGG   C4C=6C;7C=c                   #    S nS nU R                  USSS5      u  pCU(       a  U R                  S   S   S   nOU R                  S   S   S   nU R                  U R                  SS	S5      nU(       aV  U R	                  US
5      nUS:w  a>  US:w  a8  US:w  a2  U(       a  U R                  S   S   S   nOU R                  S   S   S   nSU/S.nU R                  X5      n	U R                  XQX5      I S h  vN $  N7f)NunWatchPublicrq   Fr7   r"   r:   r8   r  r  rw   r  r  r  r<   unsubscriber  r  r  s
             rn   r5  bitget.un_watch_public  s    33FOUTYZ))E"4(5C))E"4(2C&&t||]IuU''j9HO+(o2MT\`oTo))E*62;?C))E*628<CF
 ++g.ZZ'GGGGr  c                 "  #    S nS nU R                  USSS5      u  pCU(       a  U R                  S   S   S   nOU R                  S   S   S   nU R                  U R                  SS	S5      nU(       ai  U R	                  US
0 5      nU R                  US5      nUS:w  a>  US:w  a8  US:w  a2  U(       a  U R                  S   S   S   nOU R                  S   S   S   nSUS.n	U R                  X5      n
U R                  XQX5      I S h  vN $  N7f)NwatchPublicMultiplerq   Fr7   r"   r:   r8   r  r  r   rw   r  r  r  r<   r  r  )rx   re   r  rf   r
  r   r  watch_multiple)rl   r   	argsArrayr|   rq   r  r  argsArrayFirstrw   r  r   s              rn   r   bitget.watch_public_multiple	  s    33F<QSXZ_`))E"4(5C))E"4(2C&&t||]IuU!^^Iq"=N''
CHO+(o2MT\`oTo))E*62;?C))E*628<C
 ++g.((WTTTTs   DDD	Dc                 J  #    U R                  5         U R                  US5      nU R                  U5      nSnUR                  U5      nU R	                  UR
                  U5      nUc  [        U R                  5       5      nUS-   S-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S5      n	Sn
U
U R                  U R                  UU	S./S.nU R                  X5      nU R!                  X$X5        UI S h  vN $  N7f)	Nr  authenticatedGETz/user/verifybase64login)apiKey
passphraser   signr  )check_required_credentialsr   r   reusableFuturer   subscriptionsr/  secondshmacencodesecrethashlibsha256r  passwordr  r  )rl   r|   r  r   r   ru   r  r   auth	signature	operationr  r   s                rn   authenticatebitget.authenticate%	  s    '')vu-S!%&&{3(<(<kJ DLLN+Iu$~5D		$++d"3T[[5Mw~~_ghII #'++&*mm%. )	
G kk'2GJJs>||s   DD#D!D#c                 8  #    S nS nU R                  USSS5      u  pTU(       a  U R                  S   S   S   nOU R                  S   S   S   nU R                  U R                  SS	S5      nU(       aV  U R	                  US
5      nUS:w  a>  US:w  a8  US:w  a2  U(       a  U R                  S   S   S   nOU R                  S   S   S   nU R                  SU05      I S h  vN   SU/S.n	U R                  X5      n
U R                  XaX5      I S h  vN $  N5 N7f)NwatchPrivaterq   Fr7   r"   r;   r9   r  r  rw   r  r  r  r<   r  r  r  )rx   re   r  rf   r   r  r  r  )rl   r   r  r   r|   rq   r  r  rw   r  r   s              rn   r  bitget.watch_private@	  s+    33FNESXY))E"4(6C))E"4(3C&&t||]IuU''j9HO+(o2MT\`oTo))E*62<@C))E*629=C---F
 ++g.ZZ'LLL 	. Ms$   CD D!0DDDDc                 b    SnU R                  UR                  U5      nUR                  S5        g )Nr  T)r   futuresr   )rl   r   r   r   ru   s        rn   handle_authenticatebitget.handle_authenticateX	  s)     &=trp   c                 :   U R                  US5      n US:X  a  U R                  US5      nU R                  S-   U R                  U5      -   nU R                  U R                  S   S   XE5        U R                  USS5      nU R                  U R                  S   S	   Xe5        [        U5      eg
! [         a`  n[        U[        5      (       a0  SnUR                  Xx5        XR                  ;   a  UR                  U	 OUR                  U5         S nAgS nAff = f)Neventrc  r  r`  r"   rb   msgr   rc   Fr  T)r   r   jsonthrow_exactly_matched_exceptionrh   throw_broadly_matched_exceptionr   	Exception
isinstancer   rb  r  )	rl   r   r   r  r  feedbackr  er   s	            rn   handle_error_messagebitget.handle_error_message`	  s      '2	''877S=499W+==44T__T5J75SUYd&&wr:44T__T5J75SUXc#H-- 		!011-a-"6"66,,[9 a 		s   BB0 0
D:ADDc                 .   U R                  X5      (       a  g U R                  US5      nUS:X  a  U R                  X5        g US:X  a  U R                  X5        g U R                  US5      nUS:X  a  U R                  X5        g US:X  a  U R	                  X5        g US:X  a  U R                  X5        g 0 SU R                  _SU R                  _S	U R                  _S
U R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _SU R                  _nU R                  US0 5      nU R                  USSS5      nU R                  XW5      nUb  U" X5        UR                  S5      S:  a  U R                  X5        UR                  S5      S:  a  U R!                  X5        g g )Nr   pongr  r  r  r  r   rv  ru  r_  r  r
  r  r	  r  r  rg  r  r  rh  ri  r   r   r   r   r   r   r   r*  )r  r   handle_pongr  handle_subscription_statushandle_un_subscription_statusr   r  rd  r$  r  r  r  r   safe_value_2findr]  )	rl   r   r   contentr  methodsr   r   methods	            rn   handle_messagebitget.handle_messagey	  sf   b $$V55""7I6fV-fV-  '2G$$V5K++F<M!..v?
d((
T''
 4--
 D))	

 T&&
 d''
 $++
 4,,
 d//
 t00
 t**
 --
 ..
  3 3
 t22
  T&&!
$ oogub1!!#y'2>06#::h1$f.::g!#""63 $rp   c                     g)NrT    )rl   r   s     rn   rT   bitget.ping	  s    rp   c                 0    U R                  5       Ul        U$ N)millisecondslastPongrl   r   r   s      rn   r  bitget.handle_pong	  s    ++-rp   c                     U$ r  r  r  s      rn   r  !bitget.handle_subscription_status 
  s	     rp   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  US5      nU R                  US S U5      nUS   nSUS   -   n	SU-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S	-   U-   5      nXR                  ;   a  UR                  X5        UR                  S
U	5        g )Nr   rw   r   r   r   r   zunsubscribe:orderbook:r8  z orderbook T)r
  r   r   r   rC  r  r   r   r  rb  r   rl   r   r   r   rw   r  r   r{   r   r   subMessageHashrc  s               rn   !handle_order_book_un_subscription(bitget.handle_order_book_un_subscription	
  s    nnWeR0))#z:"f,v:!!#x0!!&$d;!.1AA%.__$'111$$^4...$$[1 =!86!AB^^+MM%0t[)rp   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  US S U5      nUS   nSUS   -   n	SU-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S	-   U-   5      nXR                  ;   a  UR                  X5        UR                  S
U	5        g )Nr   rw   r   r   r   r   zunsubscribe:trade:rw  z trades T)r
  r   r   r   r{  r  r   r   r  rb  r   r  s               rn   handle_trades_un_subscription$bitget.handle_trades_un_subscription 
  s	    nnWeR0))#z:"f,v:##C8<!!&$d;!*VH-==!F*[[ F#111$$^4...$$[1 :!5!>?^^+MM%0t[)rp   c                    U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  US S U5      nUS   nSUS   -   n	SU-   n
XR                  ;   a  U R                  U	 XR
                  ;   a  UR
                  U
	 XR
                  ;   a  UR
                  U		 [        U R                  S	-   U-   5      nXR                  ;   a  UR                  X5        UR                  S
U	5        g )Nr   rw   r   r   r   r   zunsubscribe:ticker:r   z ticker T)r
  r   r   r   r   r  r   r   r  rb  r   r  s               rn   handle_ticker_un_subscription$bitget.handle_ticker_un_subscription7
  s	    nnWeR0))#z:"f,v:##C8<!!&$d;!+fX.>>"V+\\!V$111$$^4...$$[1 :!5!>?^^+MM%0t[)rp   c                 t   U R                  US0 5      nU R                  US5      nUS:X  a  SOSnU R                  USS5      nU R                  USS5      nU R                  US	5      nS n	Uc  S
n	UR	                  SS5      nOSn	U R                  U R                  S5      n
U R                  X5      nU R                  US S U5      nUS   nS nS nU	(       a  SU-   nSU-   nOSU-   S-   U-   nSU-   S-   U-   nXR                  ;   a"  XR                  U   ;   a  U R                  U   U	 U R                  XU5        g )Nr   rw   r   r   r   r   r   r   r   Fr   r   TrS   zunsubscribe:kline:r   zunsubscribe:candles:r  r   )r
  r   r   r   r  r   rf   r  r   r  clean_unsubscription)rl   r   r   r   rw   r  r   r   r   r  rS   r   r{   r   r   r  s                   rn   handle_ohlcv_un_subscription#bitget.handle_ohlcv_un_subscriptionN
  s\    nnWeR0))#z:"f,v:##C8<$$S)W=##C4Ex4HE__T\\<@
''=	!!&$d;!.7K%.N09<sBVKK')3c9FBN[[ KK//KK'	2!!&+Frp   c                    U R                  US5      nUc  U R                  US0 5      /n[        S[        U5      5       H  nX4   nU R	                  USS5      nUS:X  a  U R                  X5        M3  US:X  d  US:X  a  U R                  X5        MR  US	:X  a  U R                  X5        Mk  UR                  S
5      (       a  U R                  X5        M  UR                  S5      (       d  M  U R                  X5        M     U$ )Nr   r   r   r   r   r*  rv  ru  r   r   r   )
r  r
  r   r   r   r  r  r  
startswithr  )rl   r   r   argsListr   r   r   s          rn   r  $bitget.handle_un_subscription_statuss
  s    ( >>'62wr:;Hq#h-(A+C((iAG'!66vGW$']*B226CH$226C##H--11&B##G,,11&B ) rp   )ru  r^  r
  r  r  r  )M__name__
__module____qualname____firstlineno__r   rk   boolr~   r/  r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r  r  r  r  r  r   r'  r0  r   r&  r]  rK  rk  rF  r   rr  rq  r  r  r  r   r  r  r  r   r   r  r$  r  rC  r`  rd  r   rl  r  r   r5  r   r  r  r  r	   r  r  rT   r  r  r  r  r  r  r  __static_attributes____classcell__)rm   s   @rn   r   r      s   X# Xt 16b " "" 68 B BF B< 9; OC Os O 6:" 'E7 'E 'ER=,F =,~@D 8<B 'FW 'F7 'FR,V ,, ?CQUdhqs *H *H *H3 *H^a *Hx|  ~B  yC *HX BFb *Q3 *Q3 *QUX *QXY,6 Y,v!
D !
F @DB PS P PS\ P  =? Q Q3 Q, _a ES E3 ERU Eeh E, SW_a -$s) -C -fo -^g= g=R*6 *3 *UX *
$3 <@d[] S SS S Sbfglbm S" OSaenp 2d3i 2 2[^ 2uyz  vA 2h 9; RC Rs R$7,F 7,rBH 8<$]ajl *]W *]C *]WZ *]quv~q *]Xg>v g>R]~ 04$UYbd XU XUC XUs XUimnsit XUtB86 B8Hvp: 37TX\eg -UC -Us -URU -Ulpqvlw -U^|,v |,| *, 1P 1Pf|2V |2| <> H. ?A H. LN U0 )+ 6 OQ M0& 6 t 2~4V ~4@6 &  * *.*F *.*F *.#G6 #GJ%F % %rp   r   )%ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   r  ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   r   r   r   r   ccxt.base.preciser   async_supportr   r  rp   rn   <module>r     s]     A  A  v v v v 4  * 0 . ' . * - %B*T&& B*rp   