forked from kodorvan/stcs
29 lines
911 B
Python
29 lines
911 B
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("set_margin_mode")
|
|
|
|
|
|
async def set_margin_mode(tg_id: int, margin_mode: str) -> bool:
|
|
"""
|
|
Set margin mode
|
|
:param tg_id: int - User ID
|
|
:param margin_mode: str - Margin mode
|
|
:return: bool
|
|
"""
|
|
try:
|
|
client = await get_bybit_client(tg_id=tg_id)
|
|
response = client.set_margin_mode(setMarginMode=margin_mode)
|
|
if response["retCode"] == 0:
|
|
logger.info("Margin mode set to %s for user: %s", margin_mode, tg_id)
|
|
return True
|
|
else:
|
|
logger.error("Error setting margin mode: %s", tg_id)
|
|
return False
|
|
except Exception as e:
|
|
logger.error("Error connecting to Bybit for user %s: %s", tg_id, e)
|
|
return False
|