forked from kodorvan/stcs
Fixed take profit calculation. Added a position check for the current pair when trying to change the margin.
This commit is contained in:
@@ -7,6 +7,7 @@ from aiogram.types import CallbackQuery, Message
|
||||
import app.telegram.keyboards.inline as kbi
|
||||
import database.request as rq
|
||||
from app.bybit.get_functions.get_instruments_info import get_instruments_info
|
||||
from app.bybit.get_functions.get_positions import get_active_positions_by_symbol, get_active_orders_by_symbol
|
||||
from app.bybit.set_functions.set_leverage import set_leverage
|
||||
from app.bybit.set_functions.set_margin_mode import set_margin_mode
|
||||
from app.helper_functions import is_int, is_number, safe_float
|
||||
@@ -211,6 +212,31 @@ async def settings_for_margin_type(
|
||||
"""
|
||||
try:
|
||||
await state.clear()
|
||||
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
|
||||
)
|
||||
position = next((d for d in deals if d.get("symbol") == symbol), None)
|
||||
|
||||
if position:
|
||||
size = position.get("size", 0)
|
||||
else:
|
||||
size = 0
|
||||
|
||||
if safe_float(size) > 0:
|
||||
await callback_query.answer(
|
||||
text="У вас есть активная позиция по текущей паре",
|
||||
)
|
||||
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
|
||||
await callback_query.message.edit_text(
|
||||
text="Выберите тип маржи:\n\n"
|
||||
"Примечание: Если у вас есть открытые позиции, то маржа примениться ко всем позициям",
|
||||
|
Reference in New Issue
Block a user