1
0
forked from kodorvan/stcs
This commit is contained in:
algizn97
2025-08-30 16:29:56 +05:00
parent 3462078a47
commit 2ee8c9916f
16 changed files with 523 additions and 459 deletions

View File

@@ -9,6 +9,7 @@ logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger("bybit_ws")
event_loop = None # Сюда нужно будет установить event loop из основного приложения
active_ws_tasks = {}
def get_or_create_event_loop() -> asyncio.AbstractEventLoop:
"""
@@ -31,11 +32,14 @@ async def run_ws_for_user(tg_id, message) -> None:
"""
Запускает WebSocket Bybit для пользователя с указанным tg_id.
"""
api_key = await rq.get_bybit_api_key(tg_id)
api_secret = await rq.get_bybit_secret_key(tg_id)
await start_execution_ws(api_key, api_secret, message)
if tg_id not in active_ws_tasks or active_ws_tasks[tg_id].done():
api_key = await rq.get_bybit_api_key(tg_id)
api_secret = await rq.get_bybit_secret_key(tg_id)
# Запускаем WebSocket как асинхронную задачу
active_ws_tasks[tg_id] = asyncio.create_task(
start_execution_ws(api_key, api_secret, message)
)
logger.info(f"WebSocket для пользователя {tg_id} запущен.")
def on_order_callback(message, msg):