forked from kodorvan/stcs
Added verification for open orders. Adjusted responses for the user
This commit is contained in:
@@ -7,7 +7,7 @@ from aiogram.types import CallbackQuery
|
||||
|
||||
import app.telegram.keyboards.inline as kbi
|
||||
import database.request as rq
|
||||
from app.bybit.get_functions.get_positions import get_active_positions_by_symbol
|
||||
from app.bybit.get_functions.get_positions import get_active_positions_by_symbol, get_active_orders_by_symbol
|
||||
from app.bybit.open_positions import start_trading_cycle
|
||||
from app.helper_functions import safe_float
|
||||
from app.telegram.tasks.tasks import (
|
||||
@@ -33,6 +33,7 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non
|
||||
"""
|
||||
try:
|
||||
await state.clear()
|
||||
tg_id = callback_query.from_user.id
|
||||
symbol = await rq.get_user_symbol(tg_id=callback_query.from_user.id)
|
||||
deals = await get_active_positions_by_symbol(
|
||||
tg_id=callback_query.from_user.id, symbol=symbol
|
||||
@@ -50,6 +51,15 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non
|
||||
)
|
||||
return
|
||||
|
||||
orders = await get_active_orders_by_symbol(
|
||||
tg_id=callback_query.from_user.id, symbol=symbol)
|
||||
|
||||
if orders is not None:
|
||||
await callback_query.answer(
|
||||
text="У вас есть активные ордера",
|
||||
)
|
||||
return
|
||||
|
||||
conditional_data = await rq.get_user_conditional_settings(
|
||||
tg_id=callback_query.from_user.id
|
||||
)
|
||||
@@ -73,6 +83,12 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non
|
||||
symbol=symbol,
|
||||
auto_trading=True,
|
||||
)
|
||||
await rq.set_total_fee_user_auto_trading(
|
||||
tg_id=tg_id, symbol=symbol, total_fee=0
|
||||
)
|
||||
await rq.set_fee_user_auto_trading(
|
||||
tg_id=tg_id, symbol=symbol, fee=0
|
||||
)
|
||||
res = await start_trading_cycle(
|
||||
tg_id=callback_query.from_user.id,
|
||||
)
|
||||
@@ -84,11 +100,11 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non
|
||||
"estimated will trigger liq": "Лимитный ордер может вызвать мгновенную ликвидацию. Проверьте параметры ордера.",
|
||||
"ab not enough for new order": "Недостаточно средств для создания нового ордера",
|
||||
"InvalidRequestError": "Произошла ошибка при запуске торговли.",
|
||||
"Order does not meet minimum order value": "Сумма ордера не достаточна для запуска торговли",
|
||||
"position idx not match position mode": "Ошибка режима позиции для данного инструмента",
|
||||
"Qty invalid": "Некорректное значение ордера для данного инструмента",
|
||||
"The number of contracts exceeds maximum limit allowed": "️️Количество контрактов превышает допустимое максимальное количество контрактов",
|
||||
"The number of contracts exceeds minimum limit allowed": "️️Количество контрактов превышает допустимое минимальное количество контрактов",
|
||||
"Order does not meet minimum order value": "Сумма ставки меньше допустимого для запуска торговли.",
|
||||
"position idx not match position mode": "Измените режим позиции, чтобы запустить торговлю",
|
||||
"Qty invalid": "Некорректное значение ставки для данного инструмента",
|
||||
"The number of contracts exceeds maximum limit allowed": "️️Превышен максимальный лимит ставки",
|
||||
"The number of contracts exceeds minimum limit allowed": "️️Лимит ставки меньше минимально допустимого",
|
||||
}
|
||||
|
||||
if res == "OK":
|
||||
@@ -112,7 +128,7 @@ async def start_trading(callback_query: CallbackQuery, state: FSMContext) -> Non
|
||||
except Exception as e:
|
||||
await callback_query.answer(text="Произошла ошибка при запуске торговли")
|
||||
logger.error(
|
||||
"Error processing command long for user %s: %s",
|
||||
"Error processing command start_trading for user %s: %s",
|
||||
callback_query.from_user.id,
|
||||
e,
|
||||
)
|
||||
|
Reference in New Issue
Block a user