22 lines
		
	
	
		
			603 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			603 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import logging.config
 | 
						|
 | 
						|
from pybit.unified_trading import HTTP
 | 
						|
 | 
						|
from app.bybit.logger_bybit.logger_bybit import LOGGING_CONFIG
 | 
						|
from database import request as rq
 | 
						|
 | 
						|
logging.config.dictConfig(LOGGING_CONFIG)
 | 
						|
logger = logging.getLogger("bybit")
 | 
						|
 | 
						|
 | 
						|
async def get_bybit_client(tg_id: int) -> HTTP | None:
 | 
						|
    """
 | 
						|
    Get bybit client
 | 
						|
    """
 | 
						|
    try:
 | 
						|
        api_key, api_secret = await rq.get_user_api(tg_id=tg_id)
 | 
						|
        return HTTP(demo=True, api_key=api_key, api_secret=api_secret)
 | 
						|
    except Exception as e:
 | 
						|
        logger.error("Error getting bybit client for user %s: %s", tg_id, e)
 | 
						|
        return None
 |