
    ":hf)                         d dl Zd dlmZ d dl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y)    N)
ArrayCache)AnyInt	OrderBookTrade)Client)Listc            
            e Zd Zdef fdZdi fdededefdZde	fdZ
d	 Zd
 Zd Zddi fdedededee   fdZddi fdee   dededee   fdZde	fdZddZd Zde	fdZ xZS )	tradeogrereturnc                     | j                  t        t        |          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dddddiii i d      S )NwsTwatchTradeswatchTradesForSymbolswatchOrderBookwatchOrderBookForSymbolsF
watchOHLCVwatchOHLCVForSymbolswatchOrderswatchMyTradeswatchTickerwatchTickerswatchBidsAskswatchBalancecreateOrderWseditOrderWscancelOrderWscancelOrdersWsapizwss://tradeogre.com:8443)hasurlsoptions	streaming)deep_extendsuperr   describe)self	__class__s    L/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/pro/tradeogre.pyr&   ztradeogre.describe   s   i ? Adt ( !$	
 +E e ' u   u       u   !" !%#( 4
7D
  	    Nsymbollimitc                 "  K   | j                          d{    | j                  |      }| j                  d   d   }d|d   z   }dd|d   d	}| j                  ||| j	                  ||      |       d{   }|j                         S 7 t7 w)
a6  
        watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://tradeogre.com/help/api

        :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(not used by the exchange)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        Nr   r   
orderbook:r+   	subscribebookidaet)load_marketsmarketr!   watchextendr,   )	r'   r+   r,   paramsr7   urlmessageHashrequest	orderbooks	            r)   watch_order_bookztradeogre.watch_order_book/   s      !!!V$iit$'&*::

 **S+t{{7F7SU`aa	   	" bs"   BBAB6B7BBclientc                 <   | j                  |d      }| j                  |      }|| j                  vr| j                  i       | j                  |<   | j                  |   }| j	                  |d      }| j	                  |d      }d|z   }|it        |j                        }	| j                  ddd      }
|	|
k(  r | j                  | j                  |||d i        |j                  j                  |       y ||k\  ry | j                  ||       |j                  ||       y )Nr5   noncesr.   r   snapshotDelay   )safe_stringsafe_symbol
orderbooks
order_booksafe_integerlencachehandle_optionspawnload_order_bookappendhandle_deltaresolve)r'   r@   messagemarketIdr+   storedOrderBookrB   
deltaNoncer<   cacheLengthrD   s              r)   handle_order_bookztradeogre.handle_order_bookF   s    ##GS1!!(+$//)&*oob&9DOOF#//&1!!/7;&&w4
"V+=o334K ../?RSTMm+

4//fdTVW!!((1j /734r*   c                     | j                  |d      |d<   | j                  |di       }| j                  |di       }| j                  |di       }|d   }|d   }| j                  ||       | j                  ||       y )NrC   rB   dbidsasks)rJ   	safe_dicthandle_bid_asks)r'   r>   deltadatar[   r\   
storedBids
storedAskss           r)   rQ   ztradeogre.handle_deltai   s     "..uc:	'~~eS"-~~dFB/~~dFB/v&
v&
Z.Z.r*   c                     t        |j                               }t        dt        |            D ]J  }| j	                  ||      }| j                  ||      }| j                  |      |g}|j                  |       L y )Nr   )listkeysrangerK   rF   safe_numberparse_number
storeArray)r'   bookSidebidAsksre   ipriceamountbidAsks           r)   r^   ztradeogre.handle_bid_asksv   ss    GLLN#q#d)$ 	(A$$T1-E%%gu5F''.7F'		(r*   c                     |d   }| j                  |d      }| j                  |d      }||k  ryt        dt        |            D ]%  }||   }| j                  |d      }||k(  s |dz   c S  t        |      S )Nr   rC   rB      )rJ   rf   rK   )	r'   r>   deltasfirstElementfirstElementNoncerB   rl   r_   rV   s	            r)   get_cache_indexztradeogre.get_cache_index   s    ay --lC@!!)W5$$q#f+& 	A1IE**5#6JU"1u		
 6{r*   sincec                    K   | j                          d{    | j                  |      }|d   }| j                  |g|||       d{   S 7 77 w)a  
        watches information on multiple trades made in a market

        https://tradeogre.com/help/api

        :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+   )r6   r7   watch_trades_for_symbols)r'   r+   rw   r,   r:   r7   s         r)   watch_tradesztradeogre.watch_trades   sZ      !!!V$!22F8UE6RRR 	" Ss!   AA2A	A
AAsymbolsc                 `  K   | j                          d{    | j                  |dd      }g }d}|t        |      }|dkD  r6t        dt        |            D ]  }||   }d|z   }	|j	                  |	        nd}	|j	                  |	       dddd	}
| j
                  d
   d   }| j                  ||| j                  |
|      dg       d{   }| j                  r6| j                  |d      }| j                  |d      }|j                  ||      }| j                  |||dd      S 7 7 ^w)a%  

        https://tradeogre.com/help/api

        get the list of most recent trades for a list of symbols
        :param str[] symbols: unified symbol of the market to fetch trades for(empty array means all markets)
        :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>`
        NTr   trades:tradesr/   trade*r2   r   r   r+   	timestamp)r6   market_symbolsrK   rf   rP   r!   watch_multipler9   
newUpdatesr]   rF   getLimitfilter_by_since_limit)r'   r{   rw   r,   r:   messageHashessymbolsLengthrl   r+   r<   r=   r;   r~   firsttradeSymbols                  r)   ry   z"tradeogre.watch_trades_for_symbols   sK     !!!%%gtT:LM11c'l+ 2 '&0$$[12
 #K  -

 iit$**3t{{7TZ?[^f]ghh??NN61-E**5(;KOOK7E))&%TRR3 	"( is#   D.D)B6D.D,AD.,D.c                    | j                  |d      }| j                  |      }| j                  |di       }|d   }|| j                  vr7| j	                  | j
                  dd      }t        |      }|| j                  |<   | j                  |   }	| j                  ||      }
|	j                  |
       d|z   }|j                  |	|       |j                  |	d       y )Nr5   rZ   r+   tradesLimit  r}   r~   )
rF   safe_marketr]   r~   rJ   r"   r   parse_ws_traderP   rR   )r'   r@   rS   rT   r7   r`   r+   r,   storedrL   r   r<   s               r)   handle_tradeztradeogre.handle_trade   s     ##GS1!!(+~~gsB/!$++%%%dllM4HE&F"(DKKF###D&1U&(uk*uh'r*   c                 .   | j                  |dd      }| j                  |d      }| j                  |d || j                  |      | j                  |d      d d | j	                  |      d | j                  |d      | j                  |d      d d d dd|      S )	NrZ   r   r5   r+   pq)currencycost)infor1   r   datetimer+   ordertypesidetakerOrMakerrm   rn   r   fee)safe_integer_productrF   
safe_tradeiso8601parse_ws_trade_side)r'   r   r7   r   sideEnums        r)   r   ztradeogre.parse_ws_trade   s     --eS$?	##E3/"Y/&&vx8,,X6 %%eS1&&uc2  
" # 	r*   c                 2    ddd}| j                  |||      S )Nbuysell)01)rF   )r'   r   sidess      r)   r   ztradeogre.parse_ws_trade_side  s&    
 tT22r*   c                     | j                   | j                  d}| j                  |d      }| j                  ||      }|
 |||       y y )N)r0   r   r4   )rX   r   rF   
safe_value)r'   r@   rS   methodseventmethods         r)   handle_messageztradeogre.handle_message  sT    **&&
   #.%067# r*   )N)__name__
__module____qualname__r   r&   strr   r   r?   r   rX   rQ   r^   rv   r	   r   rz   ry   r   r   r   r   __classcell__)r(   s   @r)   r   r      s    # @ @DB !S ! !S\ !.!5 !5F/( <@d[] S SS S Sbfglbm S" OSaenp %Sd3i %S %S[^ %Suyz  vA %SN(6 (8<3$V $r*   r   )ccxt.async_supportccxt ccxt.async_support.base.ws.cacher   ccxt.base.typesr   r   r   r   !ccxt.async_support.base.ws.clientr   typingr	   async_supportr    r*   r)   <module>r      s3     7 6 6 4 C$"",, C$r*   