The stop trading button has been added, and the switch mode has been fixed

This commit is contained in:
algizn97
2025-10-23 11:28:44 +05:00
parent ddfa3a7360
commit 3df88d07ab
7 changed files with 35 additions and 83 deletions

View File

@@ -5,6 +5,7 @@ from aiogram import F, Router
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery
from app.bybit.close_positions import close_position_by_symbol
import app.telegram.keyboards.inline as kbi
import database.request as rq
from app.telegram.tasks.tasks import add_stop_task, cancel_stop_task
@@ -27,6 +28,7 @@ async def stop_all_trading(callback_query: CallbackQuery, state: FSMContext):
tg_id=callback_query.from_user.id
)
timer_end = conditional_data.timer_end
symbol = await rq.get_user_symbol(tg_id=callback_query.from_user.id)
async def delay_start():
if timer_end > 0:
@@ -37,30 +39,21 @@ async def stop_all_trading(callback_query: CallbackQuery, state: FSMContext):
await rq.set_stop_timer(tg_id=callback_query.from_user.id, timer_end=0)
await asyncio.sleep(timer_end * 60)
user_auto_trading_list = await rq.get_all_user_auto_trading(
tg_id=callback_query.from_user.id
user_auto_trading = await rq.get_user_auto_trading(
tg_id=callback_query.from_user.id, symbol=symbol
)
if any(item.auto_trading for item in user_auto_trading_list):
for active_auto_trading in user_auto_trading_list:
if active_auto_trading.auto_trading:
symbol = active_auto_trading.symbol
req = await rq.set_auto_trading(
tg_id=callback_query.from_user.id,
symbol=symbol,
auto_trading=False,
)
if not req:
await callback_query.message.edit_text(
text="Произошла ошибка при остановке торговли",
reply_markup=kbi.profile_bybit,
)
return
await callback_query.message.edit_text(
text="Торговля остановлена", reply_markup=kbi.profile_bybit
if user_auto_trading and user_auto_trading.auto_trading:
await rq.set_auto_trading(
tg_id=callback_query.from_user.id,
symbol=symbol,
auto_trading=False,
)
await close_position_by_symbol(
tg_id=callback_query.from_user.id, symbol=symbol)
await callback_query.message.edit_text(text="Торговля остановлена", reply_markup=kbi.profile_bybit)
else:
await callback_query.message.edit_text(text="Нет активной торговли")
await callback_query.message.edit_text(text="Нет активной торговли", reply_markup=kbi.profile_bybit)
task = asyncio.create_task(delay_start())
await add_stop_task(user_id=callback_query.from_user.id, task=task)