
    E#id                         S SK rS SK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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\RB                  RD                  5      r"g)    N)
ArrayCacheArrayCacheBySymbolByIdArrayCacheByTimestamp)AnyBalancesBoolIntNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTrade)Client)List)ExchangeError)AuthenticationError)
BadRequest)InvalidOrder)Precisec                   2  ^  \ rS rSrS\4U 4S jjr0 4S jrS0 4S\S\S\S	\	4S
 jjr
0 4S\4S jjrS0 4S\S\S\S\S\S\4S jjrS0 4S\S\4S jjrS0 4S\\   S\4S jjrS0 4S\S\\   4S jjrS\4S jrSSS0 4S\S\S\S\S\\   4
S jjr0 4S\S\4S jjrS0 4S	\	S\4S jj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"S0 4S\S\S\#4S" jjr$SSS0 4S\S\S\S\\   4S# jjr%SSS0 4S\S\S\S\\    4S$ jjr&0 4S\'4S% jjr(S9S\4S& jjr)S\4S' jr*S\4S( jr+S9S) jr,S* r-S9S+ jr.S\4S, jr/S9S- jr0S\4S. jr1S\4S/ jr2S\4S0 jr3S1 r4S\4S2 jr5S\4S3 jr6S\4S4 jr7S\S\84S5 jr9S\4S6 jr:S\4S7 jr;S8r<U =r=$ ):poloniex   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.ESSSSS.00SSSSSS0SSSSS S!S"S#S$S%S&S'S(S)S*S+S,.S-.S.U R                  S/.S0.5      $ )1NwsT
watchOHLCVwatchOrderBookwatchTickerwatchTickerswatchTradeswatchTradesForSymbolswatchBalancewatchStatusFwatchOrderswatchMyTradescreateOrderWseditOrderWsfetchOpenOrdersWsfetchOrderWscancelOrderWscancelOrdersWs)cancelAllOrdersWsfetchTradesWsfetchBalanceWsapizwss://ws.poloniex.com/ws/publicz wss://ws.poloniex.com/ws/private)publicprivate  namebook_lv2i  i  candles_minute_1candles_minute_5candles_minute_10candles_minute_15candles_minute_30candles_hour_1candles_hour_2candles_hour_4candles_hour_6candles_hour_12candles_day_1candles_day_3candles_week_1candles_month_1)1m5m10m15m30m1h2h4h6h12h1d3d1w1M)!createMarketBuyOrderRequiresPricetradesLimitordersLimit
OHLCVLimitr"   connectionsLimitrequestsLimit
timeframesi:  )	keepAliveping)hasurlsoptions	streaming)deep_extendsuperr   describer^   )self	__class__s    K/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/pro/poloniex.pyre   poloniex.describe   s   h > @dd !$ t	
  t (  u t     u $U    !" !$#$ &*!&"'). "C#E 6:##"J# %)!$,,...****,))*+8 #		u>C
 > >	    c                 L  #    U R                  5         U R                  U R                  5       5      nU R                  S   S   S   nSnU R	                  U5      nU R                  UR                  U5      nUc  SnSU-   S-   U-   nU R                  U R                  U5      U R                  U R                  5      [        R                  S	5      n	S
S/U R                  UU	SSS.S.n
U R                  X5      nU R                  X4X5      I Sh  vN nXeR                  U'   U$  N7f)z
@ignore
       authenticates the user to access private web socket channels

       https://api-docs.poloniex.com/spot/websocket/authentication

       :returns dict: response from exchange
       r4   r    r6   authenticatedNz/wszGET
z
signTimestamp=base64	subscribeauth
HmacSHA2562)keysignTimestamp	signaturesignatureMethodsignatureVersion)eventchannelparams)check_required_credentialsnumber_to_stringmillisecondsr`   client
safe_valuesubscriptionshmacencodesecrethashlibsha256apiKeyextendwatch)rf   ry   	timestampurlmessageHashr}   future
accessPathrequestStringrt   requestmessages               rh   authenticatepoloniex.authenticateV   s#     	'')))$*;*;*=>	iit$Y/%S!!5!5{C>J#j03EE	QM		$++m"<dkk$++>VX_XfXfhpqI$"8;;%.!*'3(+
G kk'2G::cMMF* 17  -- Ns   DD$D"D$Nr8   r   	isPrivatesymbolsc                 h  #    U(       a  SOSnU R                   S   S   U   nSU/S.n/ n	U R                  U5      (       a  U	R                  S5        O(US-   S	R                  U5      -   nU R	                  U5      n	US
:w  a  XS'   U R                  X5      n
U R                  XrX5      I Sh  vN $  N7f)a  
@ignore
       Connects to a websocket channel
       :param str name: name of the channel
       :param str messageHash: unique identifier for the message
       :param boolean isPrivate: True for the authenticated url, False for the public url
       :param str[] [symbols]: CCXT market symbols
       :param dict [params]: extra parameters specific to the poloniex api
       :returns dict: data from the websocket stream
       r6   r5   r4   r    rn   )rw   rx   all::,balancesr   N)r`   is_emptyappendjoin
market_idsr   r   )rf   r8   r   r   r   ry   publicOrPrivater   rn   	marketIdsr   s              rh   rn   poloniex.subscribe   s      (1)hiit$_5 
	 	==!!U#%,sxx/@@K0I:#,i ++i0ZZ'GGGGs   B)B2+B0,B2c                    #    U R                   S   S   S   n[        U R                  5       5      nUUUS.nU R                  X4XT5      I Sh  vN $  N7f)z
@ignore
       Connects to a websocket channel
       :param str name: name of the channel
       :param dict [params]: extra parameters specific to the poloniex api
       :returns dict: data from the websocket stream
       r4   r    r6   )idrw   ry   N)r`   strnoncer   )rf   r8   ry   r   r   rn   s         rh   trade_requestpoloniex.trade_request   sX      iit$Y/$**,'
	
 ZZ)IIIIs   A
AAAsymboltypesideamountpricec                   #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  U5      nUR                  5       nUR                  5       n	U R	                  US:H  US:H  U5      n
U
(       a  SnUS   UR                  5       UR                  5       S.nUS:X  a  U	S:X  a  SnSnU R                  USS	S5      u  pU R                  US
5      nU R                  US
5      nUb  U R                  X5      nOU(       ag  Uc  [        U R                  S-   5      eU R                  U5      nU R                  U5      n[        R                  " UU5      nU R                  UU5      nOU R                  X5      nXS'   O/U R                  US   U5      US'   Ub  U R                  X5      US'   U R!                  SU R#                  X5      5      I Sh  vN nU R%                  US5      nU$  GN GN N7f)a  

       https://api-docs.poloniex.com/spot/websocket/trade-request#create-order

       create a trade order
       :param str symbol: unified symbol of the market to create an order in
       :param str type: 'market' or 'limit'
       :param str side: 'buy' or 'sell'
       :param float amount: how much of currency you want to trade in units of base currency
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]: extra parameters specific to the poloniex api endpoint
       :param str [params.timeInForce]: GTC(default), IOC, FOK
       :param str [params.clientOrderId]: Maximum 64-character length.*
       :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount

EXCHANGE SPECIFIC PARAMETERS
       :param str [params.amount]: quote units for the order
       :param boolean [params.allowBorrow]: allow order to be placed by borrowing funds(Default: False)
       :param str [params.stpMode]: self-trade prevention, defaults to expire_taker, none: enable self-trade; expire_taker: taker order will be canceled when self-trade happens
       :param str [params.slippageTolerance]: used to control the maximum slippage ratio, the value range is greater than 0 and less than 1
       :returns dict: an `order structure <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
       NMARKETLIMIT_MAKERr   )r   r   r   BUYTcreateOrderrV   costa	   createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend(quote quantity) in the amount argumentr   r   quantityr   r   )load_marketsr   marketupperis_post_onlyhandle_option_and_paramssafe_numberomitcost_to_precisionr   r   r{   r   
string_mulamount_to_precisionprice_to_precisionr   r   	safe_dict)rf   r   r   r   r   r   ry   r   uppercaseTypeuppercaseSide
isPostOnlyr   quoteAmountrV   r   amountStringpriceStringcostRequestordersorders                       rh   create_order_wspoloniex.create_order_ws   s    . !!!!!!V$



&&}'@-S`B`bhi
)MTlJJLJJL

 X%MU,BK04-8<8U8UV\^k  nQ  SW  9X5-##FF3DYYvv.F"44VB2=&tww  2}  (}  ~  ~#'#8#8#@L"&"7"7">K")"4"4\;"OK"&"8"8"MK"44VD +H"&":":6(;KV"TGJ #'#:#:6#I ))-W9UVVvq)M 	"!F Ws2   HG:HG=F2H!H "H=H Hr   c                    #    U R                  US5      nUb(  U R                  US/ 5      nU R                  XT/5      US'   U R                  U/X#5      I Sh  vN nU R	                  US5      nU$  N7f)a  

https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-multiple-orders

cancel multiple orders
:param str id: order id
:param str [symbol]: unified market symbol
:param dict [params]: extra parameters specific to the poloniex api endpoint
:param str [params.clientOrderId]: client order id
:returns dict: an list of `order structures <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
clientOrderIdNclientOrderIdsr   )safe_stringr~   array_concatcancel_orders_wsr   )rf   r   r   ry   r   r   r   r   s           rh   cancel_order_wspoloniex.cancel_order_ws   s{      ((A$!__V_bIN'+'8'8'YF#$,,bT6BBvq) Cs   AA1A/A1idsc                    #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   SU0nU R                  SU R                  XC5      5      I Sh  vN $  NI N3 N7f)a  

https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-multiple-orders

cancel multiple orders
:param str[] ids: order ids
:param str symbol: unified market symbol, default is None
:param dict [params]: extra parameters specific to the poloniex api endpoint
:param str[] [params.clientOrderIds]: client order ids
:returns dict: an list of `order structures <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
NorderIdscancelOrders)r   r   r   r   )rf   r   r   ry   r   s        rh   r   poloniex.cancel_orders_ws  sf      !!!!!!
 ''G8TUUU 	"! Vs1   A&A A&A",A&A$A&"A&$A&c                    #    U R                  5       I Sh  vN   U R                  5       I Sh  vN   U R                  SU5      I Sh  vN $  N6 N  N7f)a  

https://api-docs.poloniex.com/spot/websocket/trade-request#cancel-all-orders

cancel all open orders of a type. Only applicable to Option in Portfolio Margin mode, and MMP privilege is required.
:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the poloniex api endpoint
:returns dict[]: a list of `order structures <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
NcancelAllOrders)r   r   r   )rf   r   ry   s      rh   cancel_all_orders_wspoloniex.cancel_all_orders_ws"  sM      !!!!!!''(96BBB 	"!Bs1   AAAAAA	AAAr}   c                     U R                  US5      nU R                  US/ 5      n/ n[        S[        U5      5       H)  nXF   nU R	                  U5      nUR                  U5        M+     UR                  XS5        g )Nr   datar   )r   r~   rangelenparse_ws_orderr   resolve)	rf   r}   r   r   r   r   ir   parsedOrders	            rh   handle_order_requestpoloniex.handle_order_request0  ss     &&w5w3q#d)$AGE--e4KMM+& % 	v+rj   rH   	timeframesincelimitc                   #    U R                  5       I Sh  vN   U R                  U R                  S0 5      nU R                  XbU5      nUc  [	        U R
                  S-   U-   5      eU R                  XwSU/U5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  N N<7f)aY  
watches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://api-docs.poloniex.com/spot/websocket/market-data#candlesticks

: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\   z' watchOHLCV cannot take a timeframe of Fr   T)
r   r~   ra   r   r   r   rn   
newUpdatesgetLimitfilter_by_since_limit)	rf   r   r   r   r   ry   r\   rx   ohlcvs	            rh   watch_ohlcvpoloniex.watch_ohlcvE  s      !!!__T\\<D
"":)D?TWW'PPS\\]]nnWuvhOO??NN61E))%q$GG 	"
 Ps"   B?B;A)B? B=;B?=B?c                    #    U R                  5       I Sh  vN   U R                  U5      nU R                  U/U5      I Sh  vN nU R                  X15      $  NA 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://api-docs.poloniex.com/spot/websocket/market-data#ticker

: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)r   r   watch_tickersr~   )rf   r   ry   tickerss       rh   watch_tickerpoloniex.watch_ticker\  sU      !!!V$**F8V<<w// 	"<s!   AA+AAAAc                    #    U R                  5       I Sh  vN   SnU R                  U5      nU R                  X3SX5      I Sh  vN nU R                  (       a  U$ U R	                  U R
                  SU5      $  Nb N67f)ax  
watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://api-docs.poloniex.com/spot/websocket/market-data#ticker

:param str[] symbols:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
NtickerFr   )r   market_symbolsrn   r   filter_by_arrayr   )rf   r   ry   r8   
newTickerss        rh   r   poloniex.watch_tickersk  st      !!!%%g.>>$eWMM
??##DLL(GDD 	" Ns!   A=A9-A=A;5A=;A=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://api-docs.poloniex.com/spot/websocket/market-data#trades

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
N)watch_trades_for_symbols)rf   r   r   r   ry   s        rh   watch_tradespoloniex.watch_trades}  s$      22F8U6RRRRs   !!c                 J  #    U R                  5       I Sh  vN   U R                  USSSS5      nSnU R                  S   S   S   nU R                  U5      nSU/US	.nU R	                  X5      n	/ n
Ub5  [        S
[        U5      5       H  nU
R                  US-   X   -   5        M     U R                  XjX5      I Sh  vN nU R                  (       a5  U R                  US
5      nU R                  US5      nUR                  X5      nU R                  XUSS5      $  GN Na7f)a  
get the list of most recent trades for a list of symbols

https://api-docs.poloniex.com/spot/websocket/market-data#trades

: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
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
NFTtradesr4   r    r5   rn   )rw   rx   r   r   r   r   r   )r   r   r`   r   r   r   r   r   watch_multipler   r~   r   r   r   )rf   r   r   r   ry   r8   r   r   rn   r   messageHashesr   r   firsttradeSymbols                  rh   r   !poloniex.watch_trades_for_symbols  s*     !!!%%gtUD$Giit$X.OOG,	  !
	 ++i01c'l+$$TD[7:%=> ,**3wVV??OOFA.E**5(;KOOK7E))&TRR- 	"" Ws#   D#DB(D#?D! AD#!D#c                 &  #    U R                  5       I Sh  vN   U R                  U R                  S5      nU R                  USS5      nU R	                  USSU5      u  pSU R                  XUSU/U5      I Sh  vN nUR                  5       $  Nv N7f)a  
watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://api-docs.poloniex.com/spot/websocket/market-data#book-level-2

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: not used by poloniex watchOrderBook
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
Nr"   r8   r9   methodF)r   r~   ra   r   r   rn   r   )rf   r   r   ry   watchOrderBookOptionsr8   	orderbooks          rh   watch_order_bookpoloniex.watch_order_book  s      !!! $>N O 5vzJ44VXvtT..UVHfMM	   	" Ns"   BBA!B8B9BBc                 T  #    U R                  5       I Sh  vN   SnU R                  5       I Sh  vN   Ub  U R                  U5      nUc  SOU/nU R                  XUSXd5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XrUSS5      $  N Ns N>7f)a  
watches information on multiple orders made by the user

https://api-docs.poloniex.com/spot/websocket/order

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: not used by poloniex watchOrders
:param int [limit]: not used by poloniex watchOrders
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Nr   Tr   r   r   r   rn   r   r   r   )rf   r   r   r   ry   r8   r   r   s           rh   watch_orderspoloniex.watch_orders  s      !!!!!![[(F!>$~~d$HH??OOF2E))&TRR 	"! Is1   B(B"B(B$6B('B&(;B($B(&B(c                 X  #    U R                  5       I Sh  vN   SnSnU R                  5       I Sh  vN   Ub  U R                  U5      nUc  SOU/nU R                  XVSXt5      I Sh  vN nU R                  (       a  UR                  X5      nU R                  XUSS5      $  N Ns N>7f)a  
watches information on multiple trades made by the user using orders stream

https://api-docs.poloniex.com/spot/websocket/order

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: not used by poloniex watchMyTrades
:param int [limit]: not used by poloniex watchMyTrades
:param dict [params]: extra parameters specific to the poloniex strean
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Nr   myTradesTr   r  )	rf   r   r   r   ry   r8   r   r   r   s	            rh   watch_my_tradespoloniex.watch_my_trades  s      !!! !!![[(F!>$~~dwOO??OOF2E))&TRR 	" 	" Ps1   B*B$B*B&6B*)B(*;B*&B*(B*c                    #    U R                  5       I Sh  vN   SnU R                  5       I Sh  vN   U R                  X"SSU5      I Sh  vN $  N: N" N7f)a4  
watch balance and get the amount of funds available for trading or funds locked in orders

https://api-docs.poloniex.com/spot/websocket/balance

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
Nr   T)r   r   rn   )rf   ry   r8   s      rh   watch_balancepoloniex.watch_balance  sS      !!!!!!^^DdFCCC 	"!Cs1   AAAAAAAAAc           	          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	startTimeopenhighlowcloser   )safe_integerr   )rf   r   r   s      rh   parse_ws_ohlcvpoloniex.parse_ws_ohlcv  sn    " e[1UF+UF+UE*UG,UJ/
 	
rj   c                    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5      nU R                  U5      nU R                  U R                  S0 5      nU R                  XH5      n	US-   U-   n
U R                  X75      nU R                  U R                  U0 5      U R                  U'   U R                  U R                  U   U	5      nUb^  Uc9  U R                  U R                  SS5      n[        U5      nXR                  U   U	'   UR                  U5        UR                  X5        U$ )	Nr   r   rx   r   r\   r   rY   r7   )r~   r   safe_symbolsafe_marketra   find_timeframer  ohlcvsr  r   r   r   )rf   r}   r   r   rx   marketIdr   r   r\   r   r   parsedstoredr   s                 rh   handle_ohlcvpoloniex.handle_ohlcv  s?   * w/tQ'""7I6##D(3!!(+!!&)__T\\<D
''<	nv-$$T2"oodkk62FFV!4i@~))$,,dK.u517F#I.MM&!NN6/rj   c                    U R                  US/ 5      n[        S[        U5      5       H  nX4   nU R                  US5      nUc  M  U R	                  U5      nUS   nSn	U	S-   U-   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5        UR                  X5        M     U$ )Nr   r   r   r   r   rW   r7   )r~   r   r   r   parse_ws_trader   r  ra   r   r   r   )rf   r}   r   r   r   itemr#  trader   r   r   tradesArrayrW   s                rh   handle_tradepoloniex.handle_tradeA  s    $ w3q#d)$A7D''h7H#++D1x"TkF2"oodkk6B&"&"3"3DLL-QU"VK",["9K*5KK'""5){8 % rj   c                 ~   U R                  US5      nU R                  X25      nU R                  US5      nU R                  USS5      nU R	                  UU R                  USS5      U R                  US5      UU R                  U5      U R                  US5      U R                  US5      U R                  US	S
5      UU R                  U R                  USS5      5      U R                  U R                  USS5      5      U R                  USS5      S U R                  US5      U R                  US5      S.S.U5      $ )Nr   
createTime	matchRoletakerr   tradeIdorderIdr   	takerSider   
tradePricer   filledQuantityr   r   filledAmounttradeFeefeeCurrencyrater   currencyinfor   r   r   datetimer   r   r   takerOrMakerr   r   r   fee)	r   r   r  safe_string_lower_2
safe_tradesafe_string_2iso8601safe_string_lower	omit_zero)rf   r+  r   r#  r   
takerMakers         rh   r)  poloniex.parse_ws_tradee  sC   V ##E84!!(3%%e\:	--e['J
$$UD)<&&vx8"Y/%%eY7**5&9,,UKH&^^D$6$6ulG$TUnnT%7%7?OQ[%\]&&uhG((
; ,,UMB 
$ % 	rj   c                 8    SSSSSSS.nU R                  X!U5      $ )Nr  closedcanceled)NEWPARTIALLY_FILLEDFILLEDPENDING_CANCELPARTIALLY_CANCELEDCANCELED)r   )rf   statusstatusess      rh   parse_statuspoloniex.parse_status  s0     &$"("
 &99rj   c                    U R                  US5      nU R                  US5      nU R                  UU R                  US5      U R                  XB5      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 R                  US5      U R                  US	5      S S U R                  US
5      U R                  US5      S.S.U5      $ )N	tradeTimer   r3  r4  r   r   r1  r   tradeAmountr9  r:  r;  r>  )r  r   rD  r  rF  rG  )rf   r+  r   r   r#  s        rh   parse_ws_order_tradepoloniex.parse_ws_order_trade  s    : %%e[9	##E84""5)4&&x8"Y/%%eY7**5&9$$UF3 225+F%%eW5&&um<((
; ,,UMB 
$ % 	rj   c                    U R                  US/ 5      nU R                  nUc-  U R                  U R                  S5      n[	        U5      nX@l        / n[        S[        U5      5       GH>  nU R                  X75      nU R                  US5      n	U R                  US5      n
U	c  M>  U R                  U	5      nU R                  US5      nU R                  US5      nU
S:X  d  U
S	:X  a$  U R                  U5      nUR                  U5        GOU R                  UR                  U0 5      nU R                  XU5      nU R                  U5      nU R                  UU5        US
   c  / US
'   US
   R                  U5        US   US'   SnSnUS
   n[        S[        U5      5       H^  nUU   nU R                  US   5      nU R                  US   5      n[         R"                  " UU5      n[         R"                  " UU5      nM`     [         R$                  " US5      (       a)  U R'                  [         R(                  " UU5      5      US'   U R'                  U5      US'   US   b  U R                  US   5      nU R                  US   5      n[         R"                  " UU5      nUUS'   US   b=  U R                  US   5      nU R'                  [         R*                  " UU5      5      US'   US   c  S SUS   S   S.US'   US   S   bT  US   S   bK  U R                  US   S   5      nU R                  US   S   5      n[         R"                  " UU5      US   S'   U R                  US5      nU R-                  U5      nUUS'   UR                  U5        UR                  U	5        GMA     [        S[        U5      5       H4  nXg   n	U R/                  U	5      n U S   nSU-   n!UR1                  UU!5        M6     UR1                  US5        U$ )Nr   rX   r   r   	eventTyper4  r   placerM  r   r   lastTradeTimestamp0r   r   averagefilled	remainingrB  r=  r;  staterT  zorders::r   )r~   r   r  ra   r   r   r   r   r  r   r   hashmapsafe_value_2r)  handle_my_tradesr{   r   
string_add	string_gtparse_number
string_div
string_subrV  r   r   )"rf   r}   r   r   r   r   r   r   r   r#  r^  r   r4  r   r$  previousOrderspreviousOrderr+  	totalCosttotalAmountpreviousOrderTradesjpreviousOrderTrader   r   rZ  previousOrderFilledpreviousOrderAmountstringOrderCoststringTradeCostrawStatere  r   r   s"                                     rh   handle_orderpoloniex.handle_order  s=   H w3>%%dllMBE+E2F K	q#d)$AOOD,E''x8H((<I#))(3**5)< $ 0 0 H'9
+B!007FMM&)%)__V^^VR%PN$($5$5n}$]M //6E))&%8$X.624h/!(+2259:?:LM"67 #I"%K*7*A'"1c*=&>?-@-C*#445G5OP!%!6!67I(7S!T$+$6$6y$$G	&-&8&8f&M @ ((c::373D3DWEWEWXacnEo3pi0,0,=,=i,HM&)$X.:&*&;&;E(O&L.2.C.CMRZD[.\+.5.@.@ATVa.b+2Eh/(2>262G2GV^H_2`/9=9J9J7K]K]^q  tG  LH  :IM+6$U+3$($%(-eZ(@0e,
 &e,V4@uU|TZG[Gg*.*?*?e@TU[@\*]*.*?*?eV@T*U7>7I7I/[j7ke,V4#//w?H --h7E.3M(+MM-0  *o %p q#i.)A |H[[*FH%F$v-KNN6;/ * 	vx(rj   c                 8   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 R                  US5      nS n	[        R                  " US5      (       d$  / n	U R                  U5      n
U	R	                  U
5        U R                  0 SU_SU R                  XR5      _S	U_SU_S
U_SU R                  U5      _SS _SU R                  US5      _SS _SS _SU R                  US5      _SU R                  US5      _SS _SS _SU R                  US5      _SS _SS _UU R                  US5      U R                  U5      S U R                  US5      U R                  US5      S.U	S.E5      $ )Nr4  r   r   tsr8  re  ra  r?  r   r   r@  r`  r   timeInForcepostOnlyr   r   	stopPricetriggerPricer   r   r   rb  remaining_sizer9  r:  r;  )rc  rd  rT  rB  r   )	r   r   	string_eqr[  r   
safe_orderr  rF  rV  )rf   r   r   r   r   r#  r   r8  rT  r   r+  s              rh   r   poloniex.parse_ws_orderS  s%   : eY/((@##E84$$UD1	''~>!!%1  s33F--e4EMM%   
E 
d&&x8 
 " 
 ]	 

  
 Y/ 
 !$ 
 D$$UF3 
 4 
  
 D$$UF3 
 T%%eW5 
  
 D 
 d&&uj9 
  D! 
" t# 
$ #))%1AB''/((
; ,,UMB
 5 
  	rj   c                 <   U R                  US/ 5      n0 n[        S[        U5      5       HF  nX5   nU R                  US5      nUc  M  U R	                  U5      nUS   n	XR
                  U	'   XU	'   MH     U R                  US5      n
[        S[        U
5      5       Hj  nX   nUR                  S5      nUS   nUR                  S5      nU R                  USU5      nU R                  U5      (       a  MY  UR                  X5        Ml     UR                  US5        U$ )	Nr   r   r   zticker::r      r   r   )r~   r   r   r   parse_tickerr   find_message_hashessplitr   r   r   )rf   r}   r   r   r   r   r*  r#  r   r   r   r   partssymbolsStringr   r   s                   rh   handle_tickerpoloniex.handle_ticker  s   . w3
q#d)$A7D''h7H#**40)'-V$%+6" % 00Dq#m,-A'*K%%d+E!!HM#))#.G**:xIG==))w4 . 	z8,rj   c                 n   U R                  US/ 5      nU R                  US5      nUS:H  nUS:H  n[        S[        U5      5       GH  nX7   nU R                  US5      n	U R	                  U	5      n
U
S   nSnUS-   U-   nU R                  UR
                  U0 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(       d	  U(       d  M  U(       a  U R                  0 U5      U R                  U'   U R                  U   nUbi  [        S[        U5      5       HP  nU R                  UU5      nU R                  US5      nU R                  US5      nUS   nUR                  UU5        MR     Ubi  [        S[        U5      5       HP  nU R                  UU5      nU R                  US5      nU R                  US5      nUS   nUR                  UU5        MR     UUS'   UUS'   U R                  U5      US'   UR                  UU5        GM     g )Nr   actionsnapshotupdater   r   r9   r   r   r}  asksbidsr  r   r@  )r~   r   r   r   r   r   r  
order_book
orderbooksr   storerF  r   )rf   r}   r   r   r   r  r  r   r*  r#  r   r   r8   r   subscriptionr   r   r  r  r  rs  bidr   r   bidsSideaskasksSides                              rh   handle_order_bookpoloniex.handle_order_book  s-   ` w32:%!q#d)$A7D''h7H%%h/FH%FD+.K??6+?+?bQL%%lG<E))$5I??40D??40D66.2oob%.HDOOF+ OOF3	#"1c$i0"oodA6 $ 0 0a 8!%!1!1#q!9#,V#4 uf5 1 #"1c$i0"oodA6 $ 0 0a 8!%!1!1#q!9#,V#4 uf5 1 '-	(#)2	+&(,Y(?	*%y+6C %rj   c                     U R                  US/ 5      nSnU R                  U5      U l        UR                  U R                  U5        g )Nr   r   )r~   parse_ws_balancebalancer   )rf   r}   r   r   r   s        rh   handle_balancepoloniex.handle_balance  s?    ( w3 ,,T2t||[1rj   c                    U R                  US0 5      nU R                  US5      nUUU R                  U5      S.n[        S[	        U5      5       Hu  nU R                  X5      nU R                  US5      nU R                  U5      nU R                  5       n	U R                  US5      U	S'   U R                  US5      U	S'   XU'   Mw     U R                  U5      $ )	Nr   r}  )r?  r   r@  r=  	availablefreeholdused)	r~   r  rF  r   r   r   safe_currency_codeaccountsafe_balance)
rf   responsefirstBalancer   resultr   r  
currencyIdcode
newAccounts
             rh   r  poloniex.parse_ws_balance5  s    " xB7%%lD9	"Y/

 q#h-(Aooh2G))':>J**:6DJ!%!1!1';!GJv!%!1!1'6!BJv%4L )   ((rj   c                    SnUS   nU R                   c-  U R                  U R                  SS5      n[        U5      U l         U R                   nUR	                  U5        UR                  Xc5        US-   U-   nUR                  Xg5        g )Nr  r   rW   r7   :)r  r  ra   r   r   r   )rf   r}   parsedTrader   r   r   r   symbolMessageHashs           rh   rh  poloniex.handle_my_tradesW  s|     X&== %%dllM4HE259DMk"v+'#-6v1rj   c                 .    U R                  5       Ul        g N)r|   lastPongrf   r}   s     rh   handle_pongpoloniex.handle_pongd  s    ++-rj   c           	         U R                  X5      (       a  g U R                  US5      nU R                  US5      nUS:X  a  U R                  5       Ul        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
                  _SU R                  _U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.EnU R                  XS5      nUS:X  a  U R                  X5        g Uc  U R                  X5        g U R                  US/ 5      n[        U5      nUS:  a	  U" X5        g g )Nrx   rw   pongr:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   bookr9   r   )r   r   r   r   cancelOrderr   ro   ro   r   r   )handle_error_messager   r|   r  r&  r  r  r-  rz  r  r   handle_authenticater~   r   )	rf   r}   r   r   rw   methodsr  r   
dataLengths	            rh   handle_messagepoloniex.handle_messageg  s3   $$V553  '2F?"//1FO
 1 1
 1 1
  !2!2
  !2!2	

  !2!2
 d//
 d//
 d//
 d//
 t00
 T..
 T..
 d//
 t00
 D**
  ..!
" d((#
$ ''''++4444#88,,1
4 /6>$$V5\%%f6??7FB7DTJA~v' rj   c                    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S:X  d  US:X  a   U R                  US5      nU R                  US	5      n	U R                  S
-   U R	                  U5      -   n
U R                  U R                  S   X5        U R                  U R                  S   X5        [        U
5      eg! [         a`  n[        U[        5      (       a0  SnUR                  X5        XR                  ;   a  UR                  U	 OUR                  X5         S nAgS nAff = f)Nr   rw   r   r   r4  errorra  r   r   exactbroadrl   TF)r   	safe_listr   r   jsonthrow_exactly_matched_exception
exceptionsthrow_broadly_matched_exceptionr   	Exception
isinstancer   rejectr   )rf   r}   r   r   rw   r   r  r4  r  r  feedbacker   s                rh   r  poloniex.handle_error_message  sI   < gt,  '2~~gv.tQ'""5)4W'S.((	:''v677S=499W+==44T__W5Mt^44T__W5Mu_#H--   a!455"1KMM!1"&:&::"00=MM!(s   (BC7 7
E!AEE!c                 4   U R                  US5      nU R                  US5      nSnU(       a  UR                  X%5        U$ [        U R                  S-   U R	                  U5      -   5      nUR                  Xe5        XQR                  ;   a  UR                  U	 U$ )Nr   successrl   r  )r~   r   r   r   r  r  r   )rf   r}   r   r   r  r   r  s          rh   r  poloniex.handle_authenticate  s     w///$	2%NN70 	 (#		'8J(JKEMM%-222((5rj   c                 
    SS0$ )Nrw   r^    r  s     rh   r^   poloniex.ping  s    V
 	
rj   )r  r  r   r  )>__name__
__module____qualname____firstlineno__r   re   r   r   boolr   rn   r   r   r   floatr
   r   r   r   r   r   r   r   r   r   r	   listr   r   r   r   r   r   r   r   r   r  r  r  r   r  r  r&  r-  r)  rV  r[  rz  r   r  r  r  r  rh  r  r  r   r  r  r^   __static_attributes____classcell__)rg   s   @rh   r   r      s   ?# ?B )+ 5n `dln HC Hc Hd HU\ H< 57 J J" pt|~ =C =y =	 =[` =il =  DI =~ <@  S ( DHPR V$s) VS V& 8<B C C4PU; C,6 ,* ?CQUdhqs H H H3 H^a Hx|  ~B  yC H. 68 0 0F 0 6:" E7 E E$ <@d[] S SS S Sbfglbm S OSaenp "Sd3i "S "S[^ "Suyz  vA "SH @DB !S ! !S\ !$ 04$UYbd S SC Ss Simnsit S. 37TX\eg SC Ss SRU Slpqvlw S0 *, D D
D 
2(6 (T"6 "HAF
:1fj6 jXCJ+F +ZU7 U7n2V 22 )D2v 2.& .*(V *(X46 4t 4l& *
6 
 
rj   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   r   r   !ccxt.async_support.base.ws.clientr   typingr   ccxt.base.errorsr   r   r   r   ccxt.base.preciser   async_supportr   r  rj   rh   <module>r     sZ     f f  H  H  H  H 4  * 0 ' ) %N
t!!** N
rj   