
    ei?                         d dl Zd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ  G d dej        j                  ZdS )    N)ArrayCacheBySymbolById)AnyBalancesIntOrder	OrderBookStr)Client)Listc            
            e Zd Zdef fdZi fdefdZdefdZd Z	dddi fde
d	ed
edee         fdZdefdZddZdi fded
edefdZdefdZd Zd ZdefdZd ZdefdZi fdZi fdZ xZS )bitruereturnc                     |                      t          t          |                                           dddddddddd	dddddd	id
ddddiddiddidiiidddidd          S )NTF)	wswatchBalancewatchTickerwatchTickerswatchTradeswatchMyTradeswatchOrderswatchOrderBook
watchOHLCVapizhttps://open.bitrue.comzwss://ws.bitrue.com/market/wszwss://wsapi.bitrue.com)publicprivate)openr   r   v1r   zposeidon/api/v1/listenKey   z%poseidon/api/v1/listenKey/{listenKey})postputdelete@w gunzip)listenKeyRefreshRater   )hasurlsr   options)deep_extendsuperr   describe)self	__class__s    M/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/pro/bitrue.pyr*   zbitrue.describe   s    fd 3 3 < < > > $$ %$!&#"&#
 
 5"A#;   ! ;Q% !H$ !H'
$ 
$$ )0d M,A
 ,A
 , , ,	    c                    K   |                                   d{V }d}dddid}|                     ||          }|                     ||||           d{V S )an  
        watch balance and get the amount of funds available for trading or funds locked in orders

        https://github.com/Bitrue-exchange/Spot-official-api-docs#balance-update

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nbalancesubchanneluser_balance_updateeventparams)authenticater(   watch)r+   r6   urlmessageHashmessagerequests         r-   watch_balancezbitrue.watch_balance>   s       %%''''''''0
 
 ""7F33ZZ[';GGGGGGGGGr.   clientc                     |                      |dg           }|                     |           d}|                    | j        |           d S )NBr0   )
safe_valueparse_ws_balancesresolver0   )r+   r>   r;   balancesr:   s        r-   handle_balancezbitrue.handle_balanceR   sO    \ ??7C44x(((t|[11111r.   c                 *   || j         d<   t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          }|                     |d          }|                     |dd          }	|                     |dd          }
|	dk    }|
dk    }|s|r|r||d<   |r||d	<   || j         |<   |                     | j                   | _         d S )
Ninfor   aFLTtfreeused)r0   rangelensafe_stringsafe_currency_codeaccountsafe_integersafe_balance)r+   rD   ir0   
currencyIdcoderS   rM   rN   balanceUpdateTimelockBalanceUpdateTime
updateFree
updateUseds                r-   rB   zbitrue.parse_ws_balances   s4   "  (Vq#h--(( 	- 	-AqkG))'377J**:66DllnnG##GS11D##GS11D $ 1 1'3 B B$($5$5gsA$F$F!*a/J.!3J -Z - +&*GFO +&*GFO%,T"((66r.   Nsymbolsincelimitc                   K   |                                   d{V  ||                     |          }|d         }|                                  d{V }d}dddid}|                     ||          }	|                     |||	|           d{V }
| j        r|
                    ||          }|                     |
|||d          S )	a  
        watches information on user orders

        https://github.com/Bitrue-exchange/Spot-official-api-docs#order-update

        :param str symbol:
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: the maximum amount of orders to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order structure <https://docs.ccxt.com/?id=order-structure>` indexed by market symbols
        Nr]   ordersr1   r2   user_order_updater4   T)load_marketsmarketr7   r(   r8   
newUpdatesgetLimitfilter_by_symbol_since_limit)r+   r]   r^   r_   r6   rd   r9   r:   r;   r<   ra   s              r-   watch_orderszbitrue.watch_orders   s      !!!!!!!!![[((FH%F%%''''''''.
 
 ""7F33zz#{G[IIIIIIII? 	3OOFE22E00tTTTr.   c                    |                      |          }| j        0|                     | j        dd          }t	          |          | _        | j        }|                    |           d}|                    | j        |           d S )NordersLimiti  ra   )parse_ws_orderra   rT   r'   r   appendrC   )r+   r>   r;   parsedr_   ra   r:   s          r-   handle_orderzbitrue.handle_order   s    0 $$W--;%%dlM4HHE077DKft{K00000r.   c           
         |                      |d          }|                     |d          }|                     |d          }|                      |d          }|dk    rdnd}|                     |d          }|                     |d	          }	|                     i d
|d|                     |d          d|                     |d          d|d|                     |          d|                      |d          d|                     ||          d|                     |          dd dd d|d|                     |d          dd d|                     |d          d|                     |d          dd d |                     |d!          d |                     |          |                     |	          | 	                    |d"          d#d$|          S )%NEsoSr   buysellXNrG   idrV   clientOrderIdc	timestampdatetimelastTradeTimestamprK   r]   typetimeInForcepostOnlysidepriceptriggerPriceamountqcostYaveragefilledzn)currencyr   )	remainingstatusfee)
rT   safe_string_upperrQ   
safe_orderiso8601safe_symbolparse_ws_order_typeparse_ws_order_statusrR   safe_number)
r+   orderrd   r{   marketIdtypeIdsideIdr   statusIdfeeCurrencyIds
             r-   rk   zbitrue.parse_ws_order   sj   0 %%eS11	))%55!!%--""5#..  1uu6##E3//((44  
E 
$""5#.. 
 T--eS99 
 	 

 Y// 
 !$"3"3E3"?"? 
 d&&x88 
 D,,V44 
 4 
  
 D 
 T%%eS11 
 D 
 d&&uc22 
 D$$UC00 
  t! 
" d&&uc22# 
$ 00:: 33MBB((44 ) 
  
  
0 1  	r.   c                 l  K   |                                   d {V  |                     |          }|d         }d|z   }|d                                         }d|z   dz   }| j        d         d         d         }d	||d
d}	|                     |	|          }
|                     |||
|           d {V S )Nr]   
orderbook:rx   market__simple_depth_step0r   r   r   r1   )cb_idr2   r4   )rc   rd   lowerr&   r(   r8   )r+   r]   r_   r6   rd   r:   marketIdLowercaser2   r9   r;   r<   s              r-   watch_order_bookzbitrue.watch_order_book$  s      !!!!!!!!!V$$!"V+"4L..00//2GGit$X.*" 
 
 ""7F33ZZ[';GGGGGGGGGr.   c                    |                      |d          }|                    d          }|                     |d          }|                     |          }|d         }|                     |d          }|                     |di           }	|| j        vr|                                 | j        |<   | j        |         }
|                     |	||dd          }|
	                    |           d	|z   }|
                    |
|           d S )
Nr2   _r   r]   tstickbuysasksr   )rQ   splitr   safe_marketrT   rA   
orderbooks
order_bookparse_order_bookresetrC   )r+   r>   r;   r2   partsr   rd   r]   r{   r   	orderbooksnapshotr:   s                r-   handle_order_bookzbitrue.handle_order_book6  s   B ""7I66c""))%33!!(++!%%gt44	w33$/))&*oo&7&7DOF#OF+	((vy&&QQ!!!"V+y+.....r.   c                 <    dddd}|                      |||          S )Nr_   rd   )123rQ   )r+   r   typess      r-   r   zbitrue.parse_ws_order_typef  s1    
 

 vv666r.   c                 B    ddddddd}|                      |||          S )Nr   closedcanceled)0r   r   r   47r   )r+   r   statusess      r-   r   zbitrue.parse_ws_order_statusn  s:    
 
 &&999r.   c                 >    |                      | j        ||           d S N)spawnpong)r+   r>   r;   s      r-   handle_pingzbitrue.handle_pingy  s     

49fg.....r.   c                 t   K   |                      |d          }d|i}|                    |           d {V  d S )Npingr   )rT   send)r+   r>   r;   timer   s        r-   r   zbitrue.pong|  sU         &11D
 kk$r.   c                    d|v r|                      ||           d S d|v r|                     ||           d S |                     |d          }| j        | j        d}|                     ||          }| |||           d S d S )Nr2   r   e)BALANCEORDER)r   r   rQ   rE   rn   rA   )r+   r>   r;   r5   handlershandlers         r-   handle_messagezbitrue.handle_message  s    ""6733333wVW-----$$Wc22E.* H ooh66G"((((( #"r.   c                   K   |                      | j        d          }||                     |           d {V }|                      |di           }|                     |d          }|| j        d<   | j        d         d         d         dz   |z   | j        d<   |                     | j        dd	          }|                     || j                   | j        d         S )
N	listenKeydatar   r   r   z/stream?listenKey=listenKeyUrlr$   r"   )rA   r'   'openV1PrivatePostPoseidonApiV1ListenKeyrQ   r&   rT   delaykeep_alive_listen_key)r+   r6   r   responser   keyrefreshTimeouts          r-   r7   zbitrue.authenticate  s      OODL+>>	!II&QQQQQQQQH ??8VR88D""455C(+DL%+/9U+;D+A)+LOc+cfi+iDL(!..t|=SU\]]NJJ~t'ABBB|N++r.   c                 p  K   |                      | j        d          }d|i}	 |                     |                     ||                     d {V  n,# t          $ r}d | j        d<   d | j        d<   Y d }~d S d }~ww xY w|                     | j        dd          }|                     || j                   d S )Nr   r   r$   r"   )rQ   r'   /openV1PrivatePutPoseidonApiV1ListenKeyListenKeyextend	ExceptionrT   r   r   )r+   r6   r   r<   errorr   s         r-   r   zbitrue.keep_alive_listen_key  s      $$T\;??	
	FFt{{SZ\bGcGcdddddddddd  	 	 	(,DL%+/DL(FFFFF	 **4<9OQXYY

>4#=>>>>>s   /A 
A<A77A<r   )__name__
__module____qualname__r   r*   r   r=   r
   rE   rB   r	   r   r   r   rh   rn   rk   strr   r   r   r   r   r   r   r   r7   r   __classcell__)r,   s   @r-   r   r      s       -# - - - - - -^ *, H H H H H H(12V 12 12 12 12f#7 #7 #7J 04$UYbd U U UC Us Uimnsit U U U U<16 1 1 1 1B9 9 9 9v @DB H HS H HS\ H H H H$./ ./ ./ ./ ./`7 7 7	: 	: 	:/& / / / /
  
  
 )V ) ) ) ) )+ , , , ,* 24 ? ? ? ? ? ? ? ?r.   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   ccxt.base.typesr   r   r   r   r   r	   !ccxt.async_support.base.ws.clientr
   typingr   async_supportr    r.   r-   <module>r      s        C C C C C C E E E E E E E E E E E E E E E E 4 4 4 4 4 4      r? r? r? r? r?T& r? r? r? r? r?r.   