forked from kodorvan/stcs
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import logging.config
 | 
						|
 | 
						|
from app.bybit import get_bybit_client
 | 
						|
from app.bybit.logger_bybit.logger_bybit import LOGGING_CONFIG
 | 
						|
 | 
						|
logging.config.dictConfig(LOGGING_CONFIG)
 | 
						|
logger = logging.getLogger("get_tickers")
 | 
						|
 | 
						|
 | 
						|
async def get_tickers(tg_id: int, symbol: str) -> dict | None:
 | 
						|
    """
 | 
						|
    Get tickers
 | 
						|
    :param tg_id: int Telegram ID
 | 
						|
    :param symbol: str Symbol
 | 
						|
    :return: dict
 | 
						|
    """
 | 
						|
    try:
 | 
						|
        client = await get_bybit_client(tg_id=tg_id)
 | 
						|
        response = client.get_tickers(category="linear", symbol=symbol)
 | 
						|
        if response["retCode"] == 0:
 | 
						|
            tickers = response["result"]["list"]
 | 
						|
            # USDT quoteCoin
 | 
						|
            usdt_tickers = [t for t in tickers if t.get("symbol", "").endswith("USDT")]
 | 
						|
            if usdt_tickers:
 | 
						|
                logger.info("USDT tickers for user: %s", tg_id)
 | 
						|
                return usdt_tickers[0]
 | 
						|
            else:
 | 
						|
                logger.warning("No USDT tickers found for user: %s", tg_id)
 | 
						|
                return None
 | 
						|
        else:
 | 
						|
            logger.error("Error getting price: %s", tg_id)
 | 
						|
            return None
 | 
						|
    except Exception as e:
 | 
						|
        logger.error("Error connecting to Bybit for user %s: %s", tg_id, e)
 | 
						|
        return None
 |