
    E#i:                         S SK rS SKJrJrJrJr  S SKJrJ	r	J
r
JrJrJrJrJrJrJrJr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
\R:                  R<                  5      rg)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheBySymbolBySideArrayCacheByTimestamp)AnyBalancesBoolIntOrder	OrderBookPositionStrStringsTickerTickersTrade)Client)List)AuthenticationError)NotSupported)Precisec                     ^  \ rS rSrS\4U 4S jjrS rS rS0 4S\S\	S\
4S	 jjrS
\4S jr0 4S\S\4S jjrS5S jrS
\4S jrS0 4S\S\4S jjrS
\4S jrS0 4S\S\4S jjrS
\4S jrS5S jrSSS0 4S\S\S\	S\	S\\   4
S jjrS
\4S jrSS0 4S\S\	S\	S\\   4S jjrS
\4S jrS5S jr S
\4S jr!0 4S jr"0 4S jr#0 4S  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(S5S# jr)S
\4S$ jr*S
\4S% jr+S
\4S& jr,SSS0 4S\S\	S\	S\\-   4S' jjr.S5S
\S\4S( jjr/S) r0S* r1S5S+ jr20 4S\34S, jjr4S- r5S
\S\64S. jr7S
\4S/ jr8S
\4S0 jr9S
\4S1 jr:S
\4S2 jr;S
\4S3 jr<S4r=U =r>$ )6	modetrade   returnc                    > U R                  [        [        U ]  5       SSSSSSSSSSSSS.SSSS.0SSS	S.0S
.SSSS.SS0 SSS.S.U R                  SS.SSS[
        000S.5      $ )NTF)wswatchBalancewatchMyTrades
watchOHLCVwatchOrderBookwatchOrderswatchTickerwatchTickerswatchBidsAskswatchTradeswatchTradesForSymbolswatchPositionsr   z"wss://ws-evm.orderly.org/ws/streamz5wss://ws-private-evm.orderly.org/v2/ws/private/stream)publicprivatez*wss://testnet-ws-evm.orderly.org/ws/streamz=wss://testnet-ws-private-evm.orderly.org/v2/ws/private/stream)apitest)apiKeysecret	accountId  )fetchPositionsSnapshotawaitPositionsSnapshot)tradesLimitordersLimit	requestIdr(   i'  )ping	keepAliveexactzAuth is needed.)hasurlsrequiredCredentialsoptions	streaming
exceptions)deep_extendsuperr   describer6   r   )self	__class__s    L/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/modetrade.pyrA   modetrade.describe   s    i ? A $!%""&## $!%#)."&  "F#Z "N#b !$  $#.2.2#	 		"
 )+>_6D
 6 6	    c                     U R                  U R                  S0 5      nU R                  X!S5      nU R                  US5      nX@R                  S   U'   U$ )Nr5   r      )	safe_dictr<   safe_integersum)rB   urlr<   previousValuenewValues        rD   
request_idmodetrade.request_idK   sP    ..{B?))':88M1-)1[!#&rF   c                   #    SnU R                   b  U R                   S:w  a  U R                   nU R                  S   S   S   S-   U-   nU R                  U5      nSU0nU R                  Xb5      nU R	                  XAXqU5      I S h  vN $  N7f)N(OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY r+   r   r)   /id)r/   r:   rO   extendwatch)rB   messageHashmessagerU   rL   r5   	subscriberequests           rD   watch_publicmodetrade.watch_publicR   s     7>>%$..B*>Biit$X.4r9OOC(	)
	 ++i1ZZ'	RRRRs   BBB
BNsymbollimitc                    #    U R                  5       I Sh  vN   SnU R                  U5      nUS   S-   U-   nSUS.nU R                  Xs5      nU R                  Xh5      I Sh  vN n	U	R	                  5       $  Na N7f)a  

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/orderbook

watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return.
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
N	orderbookrU   @rZ   eventtopic)load_marketsmarketrV   r\   r_   )
rB   r^   r_   paramsnamerg   re   r[   rY   ra   s
             rD   watch_order_bookmodetrade.watch_order_book_   s      !!!V$ts"T) 
 ++g.++E;;	   	" <s"   A<A8AA<#A:$A<:A<clientc                    U R                  US0 5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nX`R                  ;  a  U R	                  5       U R                  U'   U R                  U   nU R                  US5      n	U R                  X6U	SS5      n
UR                  U
5        UR                  X5        g )Ndatar^   re   tsbidsasks)	rI   safe_stringsafe_market
orderbooks
order_bookrJ   parse_order_bookresetresolve)rB   rl   rY   rn   marketIdrg   r^   re   ra   	timestampsnapshots              rD   handle_order_bookmodetrade.handle_order_bookv   s    , ~~gvr2##D(3!!(+!  '2//)&*oo&7DOOF#OOF+	%%gt4	((y&&Q!y(rF   c                    #    U R                  5       I Sh  vN   SnU R                  U5      nUS   nUS   S-   U-   nSUS.nU R                  Xb5      nU R                  XW5      I Sh  vN $  NV N7f)a  

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/24-hour-ticker

watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Ntickerr^   rU   rb   rZ   rc   )rf   rg   rV   r\   )rB   r^   rh   ri   rg   re   r[   rY   s           rD   watch_tickermodetrade.watch_ticker   s      !!!V$!ts"T) 
 ++g.&&u666 	" 7s"   A1A-AA1(A/)A1/A1c                 x   U R                  0 SU R                  S U5      _SS _SS _SU R                  US5      _SU R                  US5      _SS _SS _SS _S	S _S
S _SU R                  US5      _SU R                  US5      _SS _SS _SS _SS _SS _U R                  US5      U R                  US5      US.EU5      $ )Nr^   rz   datetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechange
percentageaveragevolumeamount)
baseVolumequoteVolumeinfo)safe_tickersafe_symbolrr   )rB   r   rg   s      rD   parse_ws_tickermodetrade.parse_ws_ticker   sT     !
d&&tV4!
!
 !
 D$$VV4	!

 4##FE2!
 4!
 !
 4!
 !
 D!
 D$$VV4!
 T%%fg6!
 D!
 T!
 d!
  $!!
" t#!
$ **68<++FH=)!
* + 	rF   c                 8   U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  U5      nU R                  US5      nXsS'   U R	                  X65      nUS   US'   XR
                  US   '   UR                  X5        U$ )Nrn   re   r^   ro   date)rI   rr   rs   rJ   r   tickersrx   )	rB   rl   rY   rn   re   ry   rg   rz   r   s	            rD   handle_tickermodetrade.handle_ticker   s    " ~~gvr2  '2##D(3!!(+%%gt4	 V%%d3!(+x)/VH%&v%rF   symbolsc                    #    U R                  5       I Sh  vN   U R                  U5      nSnUnSUS.nU R                  XR5      nU R                  XF5      I Sh  vN nU R	                  USU5      $  N[ N7f)a  

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/24-hour-tickers

watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
:param str[] symbols: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   rZ   rc   r^   rf   market_symbolsrV   r\   filter_by_arrayrB   r   rh   ri   re   r[   rY   r   s           rD   watch_tickersmodetrade.watch_tickers   s      !!!%%g. 
 ++g.))%99##GXw?? 	" :"   A6A2AA6A4A64A6c                    U R                  US5      nU R                  US/ 5      nU R                  US5      n/ n[        S[	        U5      5       Hp  nU R                  XG   S5      nU R                  U5      n	U R                  U R                  XG   SU05      U	5      n
XR                  U	S   '   UR                  U
5        Mr     UR                  Xc5        g )Nre   rn   ro   r   r^   r   )rr   	safe_listrJ   rangelenrs   r   rV   r   appendrx   )rB   rl   rY   re   rn   rz   resultiry   rg   r   s              rD   handle_tickersmodetrade.handle_tickers  s    (   '2~~gvr2%%gt4	q#d)$A'':H%%h/F))$++dg	?R*SU[\F-3LL)*MM&! % 	v%rF   c                    #    U R                  5       I Sh  vN   U R                  U5      nSnUnSUS.nU R                  XR5      nU R                  XF5      I Sh  vN nU R	                  USU5      $  N[ N7f)a]  

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/bbos

watches best bid & ask for symbols
:param str[] symbols: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NbbosrZ   rc   r^   r   r   s           rD   watch_bids_asksmodetrade.watch_bids_asks&  s      !!!%%g. 
 ++g.))%99##GXw?? 	" :r   c                 ^   U R                  US5      nU R                  US/ 5      nU R                  US5      n/ n[        S[	        U5      5       HJ  nU R                  U R                  XG   SU05      5      nXR                  US   '   UR                  U5        ML     UR                  Xc5        g )Nre   rn   ro   r   r^   )
rr   r   rJ   r   r   parse_ws_bid_askrV   r   r   rx   )	rB   rl   rY   re   rn   rz   r   r   r   s	            rD   handle_bid_askmodetrade.handle_bid_ask<  s        '2~~gvr2%%gt4	q#d)$A**4;;twy@Q+RSF-3LL)*MM&! % 	v%rF   c                 d   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  UUU R	                  U5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      US.U5      $ )Nr^   ro   r   askSizer   bidSize)r^   rz   r   r   r   r   r   r   )rr   rs   rJ   r   iso8601)rB   r   rg   ry   r^   rz   s         rD   r   modetrade.parse_ws_bid_askV  s    ##FH5!!(3!!&(3%%fd3	"Y/##FE2))&)<##FE2))&)<	!
 	 		rF   1m	timeframesincec                 $  #    U R                  5       I Sh  vN   US:w  aB  US:w  a<  US:w  a6  US:w  a0  US:w  a*  US:w  a$  US:w  a  US	:w  a  [        U R                  S
-   5      eU R                  U5      nU R	                  U R
                  X"5      nSnUS   S-   U-   S-   U-   n	SU	S.n
U R                  X5      nU R                  X5      I Sh  vN nU R                  (       a  UR                  US   U5      nU R                  XUSS5      $  N N@7f)aa  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/k-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   5m15m30m1h1d1w1MzG watchOHLCV timeframe argument must be 1m, 5m, 15m, 30m, 1h, 1d, 1w, 1MklinerU   rb   _rZ   rc   r^   r   T)rf   r   rU   rg   rr   
timeframesrV   r\   
newUpdatesgetLimitfilter_by_since_limit)rB   r^   r   r   r_   rh   rg   intervalri   re   r[   rY   ohlcvs                rD   watch_ohlcvmodetrade.watch_ohlcvf  sH     !!!I$5I<NU^bgUgnw{n  GP  TX  GX  _h  lp  _p  w@  DH  wHtww)rrssV$##DOOYJts"T)C/(: 
 ++g.''77??NN6(#3U;E))%q$GG 	" 8s"   DDB6DD?DDc           	      &   U R                  US0 5      nU R                  US5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nU R                  U5      n	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      U R                  US
5      /n
U R                  U R                  U0 5      U R                  U'   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   U	   nUR                  U
5        UR                  X5        g )Nrn   re   r^   type	startTimer   r   r   r   r   
OHLCVLimitr0   )rI   rr   rs   find_timeframerJ   safe_number
safe_valueohlcvsr<   r   r   rx   )rB   rl   rY   rn   re   ry   rg   r^   r   r   parsedstoredr_   
ohlcvCaches                 rD   handle_ohlcvmodetrade.handle_ohlcv  s|   & ~~gvr2  '2##D(3!!(+!##D&1''1	dK0T6*T6*T5)T7+T8,
 #oodkk62FFV!4i@>%%dllL$GE*51F-3KK	*[[(3
&!z)rF   c                 N  #    U R                  5       I Sh  vN   U R                  U5      nUS   nUS   S-   nSUS.nU R                  Xt5      nU R                  Xh5      I Sh  vN n	U R                  (       a  U	R                  US   U5      nU R                  XX#S5      $  N N?7f)a  
watches information on multiple trades made in a market

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/public/trade

:param str symbol: unified market symbol of the market trades were made in
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trade structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr^   rU   z@traderZ   rc   T)rf   rg   rV   r\   r   r   filter_by_symbol_since_limit)
rB   r^   r   r_   rh   rg   re   r[   rY   tradess
             rD   watch_tradesmodetrade.watch_trades  s      !!!V$!tx' 
 ++g.((88??OOF8$4e<E00tTT 	" 9s"   B%B!AB%#B#$>B%#B%c                    U R                  US5      nU R                  US5      nU R                  US0 5      nU R                  US5      nU R                  U5      nUS   nU R	                  U R                  USU05      U5      n	XR                  ;  a6  U R                  U R                  SS5      n
[        U
5      nXR                  U'   U R                  U   nUR                  U	5        XR                  U'   UR                  X5        g )Nre   ro   rn   r^   rz   r3   r0   )rr   rJ   rI   rs   parse_ws_traderV   r   r<   r   r   rx   )rB   rl   rY   re   rz   rn   ry   rg   r^   trader_   r   r   s                rD   handle_trademodetrade.handle_trade  s       '2%%gt4	~~gvr2##D(3!!(+!##DKK{I6N$OQWX++%%%dllM4HE&F"(KKV$e$Fv%rF   c                    U R                  US5      nU R                  X25      nUS   nU R                  USS5      nU R                  USS5      n[        R                  " XV5      nU R                  US5      nU R                  US5      n	S n
U R                  US5      nUb  U(       a  SOS	n
S nU R                  US
5      nUb$  UU R                  U R                  US5      5      S.nU R                  U R                  US5      U	U R                  U	5      UUUUUU R                  US5      U
U R                  US5      UUS.U5      $ )Nr^   executedPricepriceexecutedQuantitysizesiderz   makertakerfeefeeAssetcostcurrencytradeIdorderIdr   )rU   rz   r   r^   r   r   r   r   ordertakerOrMakerr   r   r   )rr   rs   safe_string_2r   
string_mulsafe_string_lowerrJ   	safe_boolsafe_currency_code
safe_trader   )rB   r   rg   ry   r^   r   r   r   r   rz   r   r   r   feeValues                 rD   r   modetrade.parse_ws_trade  sh   J ##E84!!(3!""5/7C##E+=vF!!%0%%eV4%%e[9	ug.&+7L##E51  33D4D4DUJ4WXC ""5)4"Y/%%eY7(**5&9 
  	rF   c                 &   SnU R                  US5      nU(       a.  U R                  UR                  S5      nUR                  S5        g [        U R	                  U5      5      nUR                  Xc5        X1R                  ;   a  UR                  S	 g g )NauthenticatedsuccessT)r   futuresrx   r   jsonrejectsubscriptions)rB   rl   rY   rX   r  futureerrors          rD   handle_authmodetrade.handle_auth/  sz     &//'95__V^^_EFNN4 '		'(:;EMM%-222((9 3rF   c                   #    U R                  5         U R                  S   S   S   S-   U R                  -   nU R                  U5      nSnSnUR	                  U5      nU R                  UR                  U5      nUc  [        U R                  5       5      nUn	U R                  n
U
R                  S5      S:  a  U
R                  S5      nUS	   n
U R                  U R                  U	5      U R                  U
5      S
5      nU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+   r   r*   rT   r  authzed25519:r   rH   ed25519)orderly_keysignrz   )rd   rh   )check_required_credentialsr:   r/   rl   reusableFuturer   r
  strnoncer.   findspliteddsaencodebase58_to_binaryr-   rV   rW   )rB   rh   rL   rl   rX   rd   r  r  ro   r  r.   parts	signaturer[   rY   s                  rD   authenticatemodetrade.authenticateD  s,    '')iit$Y/#5FS!%&&{3(<(<kJ TZZ\"BD[[F{{:&!+Z0q

4;;t#4d6K6KF6SU^_I#';;%!#G kk'2GJJs>||s   D9E;E <Ec                   #    U R                  U5      I S h  vN   U R                  S   S   S   S-   U R                  -   nU R                  U5      nSU0nU R	                  Xb5      nU R                  XAXqU5      I S h  vN $  Nj N7fNr+   r   r*   rT   rU   )r  r:   r/   rO   rV   rW   )rB   rX   rY   rh   rL   r5   rZ   r[   s           rD   watch_privatemodetrade.watch_private`  s     '''iit$Y/#5FOOC(	)
	 ++i1ZZ'	RRR 	( S"   BBA%B=B>BBc                   #    U R                  U5      I S h  vN   U R                  S   S   S   S-   U R                  -   nU R                  U5      nSU0nU R	                  Xb5      nU R                  XAXqU5      I S h  vN $  Nj N7fr"  )r  r:   r/   rO   rV   watch_multiple)rB   messageHashesrY   rh   rL   r5   rZ   r[   s           rD   watch_private_multiple modetrade.watch_private_multiplej  s     '''iit$Y/#5FOOC(	)
	 ++i1((WU^___ 	( `r%  c                   #    U R                  5       I Sh  vN   U R                  USSS5      nU(       a  SOSnU R                  USS/5      nUnUb  U R                  U5      nUS   nUSU-   -  nS	US
.n	U R	                  X5      n
U R                  Xz5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  N N;7f)a  
watches information on multiple orders made by the user

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/execution-report
https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/algo-execution-report

: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 bool [params.trigger]: True if trigger order
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NstoptriggerFalgoexecutionreportexecutionreportr^   :rZ   rc   T	rf   safe_bool_2omitrg   rV   r#  r   r   r   rB   r^   r   r_   rh   r-  re   rX   rg   r[   rY   orderss               rD   watch_ordersmodetrade.watch_orderst  s      !!!""669eD*1%8I6FI#67[[(FH%F3<'K 
 ++g.))+????OOF2E00tTT# 	" @s"   CCBCC:CCc                   #    U R                  5       I Sh  vN   U R                  USSS5      nU(       a  SOSnU R                  US5      nSnUb  U R                  U5      nUS   nUS	U-   -  nS
US.n	U R	                  X5      n
U R                  Xz5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XX#S5      $  N N;7f)a  
watches information on multiple trades made by the user

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/execution-report
https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/algo-execution-report

: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 bool [params.trigger]: True if trigger order
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr,  r-  Fr.  r/  myTradesr^   r0  rZ   rc   Tr1  r4  s               rD   watch_my_tradesmodetrade.watch_my_trades  s      !!!""669eD*1%8I66* [[(FH%F3<'K 
 ++g.))+????OOF2E00tTT# 	" @s"   CCBCC:CCc           	         U R                  US5      nU R                  US5      nU R                  U5      nUS   nU R                  US5      nU R                  US5      U R                  US5      S.nU R                  US5      nU R                  US5      n	U R                  US5      n
[        R
                  " US	5      (       a  U
b  U
n	U R                  US
5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUn[        R                  " X5      (       a  [        R                  " UU5      nU R                  US5      nU R                  U5      nS nU R                  US5      nU R                  US5      nU R                  0 SU_SU_SU_SU_SU_SU R                  U5      _SU_SU_SS _SS _SU_SU	_SU_SU_SU_SS _SS _UUUUUS.E5      $ )Nr   r^   rz   totalFeer   r   r   avgPrice0quantityr   r   totalExecutedQuantitystatusclientOrderIdtriggerPricer   rU   r   lastTradeTimestamptimeInForcepostOnly	stopPricer   r   r   )filled	remainingrB  r   r   )rr   rg   rJ   r   r   	string_eqr   	string_ge
string_subparse_order_status
safe_orderr   )rB   r   rg   r   ry   r^   rz   r   priceStringr   r>  r   r   r   rI  totalExecQuantityrJ  	rawStatusrB  r   rC  rD  s                         rD   parse_ws_ordermodetrade.parse_ws_order  s   D ""5)4##E84X&!%%e[9	$$UJ7((
;
 &&ug6  0##E:6[#..H4HE!!%4%%eV4%%eV4!!%)@A ,,U4KL	V77**96GHI$$UH5	((3((@''~>  
E 
f 
 ' 
 ]	 

  
 Y/ 
 !) 
 D 
 4 
  
 D 
 U 
  
 L 
 f 
  D! 
" t# 
$ "- 
  	rF   c                    U R                  US5      nU R                  US5      n[        U[        5      (       ah  [	        S[        U5      5       HN  nXE   nU R                  U R                  US5      5      nUb  U R                  X5        U R                  XU5        MP     g U R                  U R                  US5      5      nUb  U R                  X5        U R                  XU5        g )Nre   rn   r   r   )	rr   r   
isinstancelistr   r   	omit_zerohandle_my_tradehandle_order)rB   rl   rY   re   rn   r   r   r   s           rD   handle_order_updatemodetrade.handle_order_update,  s    :   '2w/dD!!1c$i(..)9)9$	)JK&((7!!&7 ) nnT%5%5dI%FGG"$$V2fE2rF   c                    U R                  U5      nU R                  US5      nU R                  US5      nUGb:  U R                  c-  U R                  U R                  SS5      n[        U5      U l        U R                  nU R                  UR                  U0 5      n	U R                  X5      n
U
bq  U R                  U
S5      nUb  XS'   U R                  U
S5      nUb  XS'   U R                  U
S5      US'   U R                  U
S5      US'   U R                  U
S	5      US	'   UR                  U5        UR                  U R                  U5        US
-   U-   nUR                  U R                  U5        g g )Nr^   rU   r4   r0   r   feesr   rz   r   r0  )rS  rr   r5  rJ   r<   r   rI   hashmapr   r   r   rx   )rB   rl   rY   re   r   r^   r   r_   cachedOrdersr5  r   r   r^  messageHashSymbols                 rD   rZ  modetrade.handle_orderZ  sb   $$W-!!&(3""640{{"))$,,tL4U;;;L^^L$8$8&"EFNN63E ooeU3?$'5M~~eV4#%)6N#'>>%#Bx &*&7&7{&K{#%)%5%5eZ%Hz"'NN4;;. %f 4NN4;;(9:) rF   c                 j   SnU R                  US5      nU R                  U5      nUS   nU R                  X%5      nU R                  nUc.  U R	                  U R
                  SS5      n	[        U	5      nXl        UR                  U5        UR                  X5        US-   U-   n
UR                  X5        g )Nr9  r^   r3   r0   r0  )	rr   rs   r   r9  rJ   r<   r   r   rx   )rB   rl   rY   rX   ry   rg   r^   r   r   r_   symbolSpecificMessageHashs              rD   rY  modetrade.handle_my_tradet  s    : !##GX6!!(+!##G4>%%dllM4HE+E2F"Mev+$/#$5$>!v9rF   c                 .  #    U R                  5       I Sh  vN   / nU R                  U5      nU R                  U5      (       d5  [        S[	        U5      5       H  nX   nUR                  SU-   5        M     OUR                  S5        U R                  S   S   S   S-   U R                  -   nU R                  U5      n	U R                  X5        U R                  S	S
S5      n
U R                  S	SS5      nU
(       a@  U(       a9  U R                  c,  U	R                  S
5      I Sh  vN nU R                  XX#S5      $ SSS.nU R                  X]U5      I Sh  vN nU R                  (       a  U$ U R                  U R                  XUS5      $  GNx Nj N:7f)a  

       https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/position-push

       watch all open positions
       :param str[] [symbols]: list of unified market symbols
@param since timestamp in ms of the earliest position to fetch
@param limit the maximum number of positions to fetch
       :param dict params: extra parameters specific to the exchange API endpoint
       :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
       Nr   positions::	positionsr+   r   r*   rT   r(   r1   Tr2   rZ   positionrc   )rf   r   is_emptyr   r   r   r:   r/   rl   set_positions_cachehandle_optionrh  r  filter_by_symbols_since_limitr)  r   )rB   r   r   r_   rh   r(  r   r^   rL   rl   r1   r2   r{   r[   newPositionss                  rD   watch_positionsmodetrade.watch_positions  s     !!!%%g.}}W%%1c'l+ $$]V%;< ,   -iit$Y/#5FS!  1!%!3!34DF^`d!e!%!3!34DF^`d!e!&<AW#]]+CDDH55hW[\\ 
 "88QWXX??11$..'RWY]^^1 	" E Ys4   FFDF&F'1FF6FFFc                     U R                  SSS5      nU(       a@  SnXQR                  ;  a.  UR                  U5        U R                  U R                  X5        g g [        5       U l        g )Nr(   r1   F)rl  r  r  spawnload_positions_snapshotr   rh  )rB   rl   r   r   r1   rX   s         rD   rk  modetrade.set_positions_cache  s]    !%!3!34DF^`e!f!2K>>1k*

477M 2 67DNrF   c                   #    U R                  5       I S h  vN n[        5       U l        U R                  n[        S[	        U5      5       HI  nX5   nU R                  USS5      n[        R                  " US5      (       d  M8  UR                  U5        MK     UR                  U   nUR                  U5        UR                  US5        g  N7f)Nr   	contractsr?  rh  )fetch_positionsr   rh  r   r   rr   r   	string_gtr   r  rx   )	rB   rl   rX   rh  cacher   ri  rv  r  s	            rD   rs  !modetrade.load_positions_snapshot  s     ..00	13q#i.)A |H((;DI  C00X&	 * ,uuk* 1s   CCA(CA	Cc                    U R                  US0 5      nU R                  US/ 5      nU R                  c  [        5       U l        U R                  n/ n[	        S[        U5      5       Hv  nXG   nU R                  US5      n	U R                  U	5      n
U R                  X5      nUR                  U5        UR                  U5        SU
S   -   nUR                  X5        Mx     UR                  US5        g )Nrn   rh  r   r^   rg  )rI   r   rh  r   r   r   rr   rs   parse_ws_positionr   rx   )rB   rl   rY   rn   rawPositionsry  rn  r   rawPositionry   rg   ri  rX   s                rD   handle_positionsmodetrade.handle_positions  s    B ~~gvr2~~dK<>>!57DNq#l+,A&/K''X>H%%h/F--kBH)LL"'&*::KNN81 - 	|[1rF   c                 t   U R                  US5      nU R                  X25      nU R                  US5      nS n[        R                  " US5      (       a  SnOSnU R                  US5      nU R                  US5      nU R	                  US5      nU R                  US	5      n	U R                  US
5      n
[        R
                  " U5      n[        R                  " XG5      nU R                  0 SU_SS _SU R                  US5      _SU_SU R                  U5      _SS _SS _SS _SS _SS _SU R                  U	5      _SU R                  U5      _SS _SU R                  U
5      _SU R                  U5      _SU R                  U5      _SS _U R                  US5      U R                  U5      S S SS US S S S S.E5      $ )Nr^   positionQtyr?  longshortcontractSize	markPricerz   averageOpenPriceunsettledPnlr   rU   r   lastUpdateTimestampinitialMargininitialMarginPercentagemaintenanceMarginmaintenanceMarginPercentage
entryPricenotionalleverageunrealizedPnlrv  marginRatioestLiqPricecross)liquidationPricer  	lastPrice
collateral
marginMode
marginTyper   r   hedgedstopLossPricetakeProfitPrice)rr   rs   r   rx  rJ   
string_absr   safe_positionr   parse_numberr   )rB   ri  rg   contractr   r   r  r  rz   r  unrealisedPnlr  s               rD   r|  modetrade.parse_ws_position  sB   2 ##Hh7!!(3-8T3''DD''?$$X{;	%%h<	%%h0BC
((>B!!$'%%d6!! #
H#
$#
 d&&vx8#
 	#

 Y/#
 "4#
 T#
 &t#
  #
 *4#
 $++J7#
 ))(3#
 #
 T..}=#
 **40#
  D--l;!#
" 4##
$ !% 0 0= I**95!!#9#
  	rF   c                    #    U R                  5       I Sh  vN   SnUnSUS.nU R                  XA5      nU R                  X55      I Sh  vN $  N7 N7f)aO  
watch balance and get the amount of funds available for trading or funds locked in orders

https://orderly.network/docs/build-on-evm/evm-api/websocket-api/private/balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
NbalancerZ   rc   )rf   rV   r#  )rB   rh   re   rX   r[   rY   s         rD   watch_balancemodetrade.watch_balanceW  s^      !!! 
 ++g.''=== 	" >s!   AA2A	A
AAc                    U R                  US0 5      nU R                  US0 5      n[        UR                  5       5      nU R                  US5      nX0R                  S'   X`R                  S'   U R                  U5      U R                  S'   [        S[        U5      5       H  nXW   nXH   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XS
'   XS'   [        R                  " X5      US'   XR                  U
'   M     U R                  U R                  5      U l        UR                  U R                  S5        g )Nrn   balancesro   r   rz   r   r   holdingfrozentotalusedfreer  )rI   rW  keysrJ   r  r   r   r   r   accountrr   r   rM  safe_balancerx   )rB   rl   rY   rn   r  r  ro   r   keyvaluecoder  r  r  s                 rD   handle_balancemodetrade.handle_balancej  sH   8 ~~gvr2>>$
B7HMMO$w-#V$&[!#'<<#3Z q#d)$A'CME**3/D-1\\-Adll4(G$$UI6E##E84D$G"FO%00=GFO!(LL % ((6t||Y/rF   c                    SU;  a  gU R                  US5      nU(       a  gU R                  US5      n Ub@  U R                  S-   U R                  U5      -   nU R	                  U R
                  S   XE5        g! [         a`  n[        U[        5      (       a0  SnUR                  Xg5        XqR                  ;   a  UR                  U	 OUR                  U5         S nAgS nAff = f)Nr  FerrorMsg r8   r  T)r   rr   rU   r  throw_exactly_matched_exceptionr>   	ExceptionrV  r   r	  r
  )rB   rl   rY   r  errorMessagefeedbackr  rX   s           rD   handle_error_messagemodetrade.handle_error_message  s     W$..)4''<	'77S=499W+==44T__W5M|f 	%!455-e1"6"66,,[9e$	s   AA9 9
C#ACC#c                 t   U R                  X5      (       a  g U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.nU R                  US5      nU R                  X45      nUb	  U" X5        g U R                  US5      nUb  U R                  X65      nUb	  U" X5        g UR!                  S5      n[#        U5      nUS:X  a  U R                  US5      n	U R                  X95      nUb	  U" X5        g U	R!                  S5      n
[#        U5      nUS:X  a.  U R                  X0R                  U
S5      5      nUb	  U" X5        g g g g g )	N)r6   pongrZ   ra   r   r   r   r   r  r/  r.  ri  r  r   rd   re   rb      rH   r   r   )r  handle_pinghandle_ponghandle_subscriber|   r   r   r   r   r  r[  r  r  r   rr   r   r  r   )rB   rl   rY   methodsrd   methodre   
splitTopicsplitLengthri   	splitNamesplitNameLengths               rD   handle_messagemodetrade.handle_message  s   $$V55$$$$..//((**&&&&$$#77#'#;#;--**''
    '206#  '2__W4F!v'S)Jj/Ka''
A67%6+ JJsO	"%j/"a'!__W6F6FyRS6TUF)v/ * (   rF   c                 
    SS0$ )Nrd   r6    )rB   rl   s     rD   r6   modetrade.ping        rF   c                 
    SS0$ )Nrd   r  r  rB   rl   rY   s      rD   r  modetrade.handle_ping  r  rF   c                 0    U R                  5       Ul        U$ N)millisecondslastPongr  s      rD   r  modetrade.handle_pong  s     ++-rF   c                     U$ r  r  r  s      rD   r  modetrade.handle_subscribe  s	     rF   )r  r9  r5  rh  r  )?__name__
__module____qualname____firstlineno__r   rA   rO   r\   r  r
   r   rj   r   r|   r   r   r   r   r   r   r   r   r   r   r   r   rW  r   r   r   r   r   r   r  r  r#  r)  r   r   r6  r:  rS  r[  rZ  rY  r   ro  rk  rs  r  r|  r   r  r  r	   r  r  r6   r  r  r  __static_attributes____classcell__)rC   s   @rD   r   r      s   7# 7rS @DB !S ! !S\ !.!) !)F 68 7 7F 7,"HF : 6:" @7 @ @,&V &@ 8<B @W @7 @,&V &4  ?CQUdhqs H H H3 H^a Hx|  ~B  yC H<**6 **X <@d[] U US U Ubfglbm U4&6 &:FP:& :* )+ 8 @B S KM ` 04$UYbd U UC Us Uimnsit UB 37TX\eg UC Us URU Ulpqvlw UBtl,3& ,3\;6 ;4*:f *:X 8<$]ajl $_W $_C $_WZ $_quv~q $_L8& 8 8+02dEN *, > >&/0b6 t 2+0V +0Z!6 !!& !& 	v 	 	rF   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   r   r   r   ccxt.base.typesr   r   r	   r
   r   r   r   r   r   r   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   ccxt.base.preciser   async_supportr   r  rF   rD   <module>r     sK     A  A v v v v 4  0 ) %g"",, grF   