Fixed check auto trading
This commit is contained in:
@@ -5,7 +5,6 @@ from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery
|
||||
|
||||
import app.telegram.keyboards.inline as kbi
|
||||
|
||||
from app.bybit.get_functions.get_positions import (
|
||||
get_active_orders,
|
||||
get_active_orders_by_symbol,
|
||||
@@ -22,7 +21,7 @@ router_get_positions_handlers = Router(name="get_positions_handlers")
|
||||
|
||||
@router_get_positions_handlers.callback_query(F.data == "my_deals")
|
||||
async def get_positions_handlers(
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
) -> None:
|
||||
"""
|
||||
Gets the user's active positions.
|
||||
@@ -43,7 +42,7 @@ async def get_positions_handlers(
|
||||
|
||||
@router_get_positions_handlers.callback_query(F.data == "change_position")
|
||||
async def get_positions_handler(
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
) -> None:
|
||||
"""
|
||||
Gets the user's active positions.
|
||||
@@ -70,11 +69,15 @@ async def get_positions_handler(
|
||||
await callback_query.answer(text="Нет активных позиций.")
|
||||
return
|
||||
|
||||
active_symbols_sides = [(pos.get("symbol"), pos.get("side")) for pos in active_positions]
|
||||
active_symbols_sides = [
|
||||
(pos.get("symbol"), pos.get("side")) for pos in active_positions
|
||||
]
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text="Ваши активные позиции:",
|
||||
reply_markup=kbi.create_active_positions_keyboard(symbols=active_symbols_sides),
|
||||
reply_markup=kbi.create_active_positions_keyboard(
|
||||
symbols=active_symbols_sides
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("Error in get_positions_handler: %s", e)
|
||||
@@ -113,7 +116,8 @@ async def get_position_handler(callback_query: CallbackQuery, state: FSMContext)
|
||||
size = position.get("size") or "Нет данных"
|
||||
take_profit = position.get("takeProfit") or "Нет данных"
|
||||
stop_loss = position.get("stopLoss") or "Нет данных"
|
||||
position_idx = position.get("positionIdx")
|
||||
position_idx = position.get("positionIdx") or "Нет данных"
|
||||
liq_price = position.get("liqPrice") or "Нет данных"
|
||||
else:
|
||||
side = "Нет данных"
|
||||
symbol = "Нет данных"
|
||||
@@ -122,6 +126,7 @@ async def get_position_handler(callback_query: CallbackQuery, state: FSMContext)
|
||||
take_profit = "Нет данных"
|
||||
stop_loss = "Нет данных"
|
||||
position_idx = "Нет данных"
|
||||
liq_price = "Нет данных"
|
||||
|
||||
side_rus = (
|
||||
"Покупка"
|
||||
@@ -129,23 +134,42 @@ async def get_position_handler(callback_query: CallbackQuery, state: FSMContext)
|
||||
else "Продажа" if side == "Sell" else "Нет данных"
|
||||
)
|
||||
|
||||
position_idx_rus = ("Односторонний" if position_idx == 0
|
||||
else "Покупка в режиме хеджирования" if position_idx == 1
|
||||
else "Продажа в режиме хеджирования" if position_idx == 2
|
||||
else "Нет данных")
|
||||
position_idx_rus = (
|
||||
"Односторонний"
|
||||
if position_idx == 0
|
||||
else (
|
||||
"Покупка в режиме хеджирования"
|
||||
if position_idx == 1
|
||||
else (
|
||||
"Продажа в режиме хеджирования"
|
||||
if position_idx == 2
|
||||
else "Нет данных"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
text_lines = [
|
||||
f"Торговая пара: {symbol}",
|
||||
f"Режим позиции: {position_idx_rus}",
|
||||
f"Цена входа: {avg_price}",
|
||||
f"Количество: {size}",
|
||||
f"Движение: {side_rus}",
|
||||
]
|
||||
|
||||
if take_profit and take_profit != "Нет данных":
|
||||
text_lines.append(f"Тейк-профит: {take_profit}")
|
||||
if stop_loss and stop_loss != "Нет данных":
|
||||
text_lines.append(f"Стоп-лосс: {stop_loss}")
|
||||
if liq_price and liq_price != "Нет данных":
|
||||
text_lines.append(f"Цена ликвидации: {liq_price}")
|
||||
|
||||
text = "\n".join(text_lines)
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text=f"Торговая пара: {symbol}\n"
|
||||
f"Режим позиции: {position_idx_rus}\n"
|
||||
f"Цена входа: {avg_price}\n"
|
||||
f"Количество: {size}\n"
|
||||
f"Движение: {side_rus}\n"
|
||||
f"Тейк-профит: {take_profit}\n"
|
||||
f"Стоп-лосс: {stop_loss}\n",
|
||||
reply_markup=kbi.make_close_position_keyboard(symbol_pos=symbol,
|
||||
side=side,
|
||||
position_idx=position_idx,
|
||||
qty=size),
|
||||
text=text,
|
||||
reply_markup=kbi.make_close_position_keyboard(
|
||||
symbol_pos=symbol, side=side, position_idx=position_idx, qty=size
|
||||
),
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
@@ -159,7 +183,7 @@ async def get_position_handler(callback_query: CallbackQuery, state: FSMContext)
|
||||
|
||||
@router_get_positions_handlers.callback_query(F.data == "open_orders")
|
||||
async def get_open_orders_handler(
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
callback_query: CallbackQuery, state: FSMContext
|
||||
) -> None:
|
||||
"""
|
||||
Gets the user's open orders.
|
||||
@@ -186,7 +210,9 @@ async def get_open_orders_handler(
|
||||
await callback_query.answer(text="Нет активных ордеров.")
|
||||
return
|
||||
|
||||
active_orders_sides = [(pos.get("symbol"), pos.get("side")) for pos in active_positions]
|
||||
active_orders_sides = [
|
||||
(pos.get("symbol"), pos.get("side")) for pos in active_positions
|
||||
]
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text="Ваши активные ордера:",
|
||||
@@ -222,13 +248,13 @@ async def get_order_handler(callback_query: CallbackQuery, state: FSMContext):
|
||||
|
||||
if orders:
|
||||
side = orders.get("side")
|
||||
symbol = orders.get("symbol") or "Нет данных"
|
||||
price = orders.get("price") or "Нет данных"
|
||||
qty = orders.get("qty") or "Нет данных"
|
||||
order_type = orders.get("orderType") or ""
|
||||
trigger_price = orders.get("triggerPrice") or "Нет данных"
|
||||
take_profit = orders.get("takeProfit") or "Нет данных"
|
||||
stop_loss = orders.get("stopLoss") or "Нет данных"
|
||||
symbol = orders.get("symbol")
|
||||
price = orders.get("price")
|
||||
qty = orders.get("qty")
|
||||
order_type = orders.get("orderType")
|
||||
trigger_price = orders.get("triggerPrice")
|
||||
take_profit = orders.get("takeProfit")
|
||||
stop_loss = orders.get("stopLoss")
|
||||
order_id = orders.get("orderId")
|
||||
else:
|
||||
side = "Нет данных"
|
||||
@@ -253,16 +279,31 @@ async def get_order_handler(callback_query: CallbackQuery, state: FSMContext):
|
||||
else "Лимитный" if order_type == "Limit" else "Нет данных"
|
||||
)
|
||||
|
||||
text_lines = [
|
||||
f"Торговая пара: {symbol}",
|
||||
f"Количество: {qty}",
|
||||
f"Движение: {side_rus}",
|
||||
f"Тип ордера: {order_type_rus}",
|
||||
]
|
||||
if price:
|
||||
text_lines.append(f"Цена: {price}")
|
||||
|
||||
if trigger_price and trigger_price != "Нет данных":
|
||||
text_lines.append(f"Триггер цена: {trigger_price}")
|
||||
|
||||
if take_profit and take_profit != "Нет данных":
|
||||
text_lines.append(f"Тейк-профит: {take_profit}")
|
||||
|
||||
if stop_loss and stop_loss != "Нет данных":
|
||||
text_lines.append(f"Стоп-лосс: {stop_loss}")
|
||||
|
||||
text = "\n".join(text_lines)
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text=f"Торговая пара: {symbol}\n"
|
||||
f"Цена: {price}\n"
|
||||
f"Количество: {qty}\n"
|
||||
f"Движение: {side_rus}\n"
|
||||
f"Тип ордера: {order_type_rus}\n"
|
||||
f"Триггер цена: {trigger_price}\n"
|
||||
f"Тейк-профит: {take_profit}\n"
|
||||
f"Стоп-лосс: {stop_loss}\n",
|
||||
reply_markup=kbi.make_close_orders_keyboard(symbol_order=symbol, order_id=order_id),
|
||||
text=text,
|
||||
reply_markup=kbi.make_close_orders_keyboard(
|
||||
symbol_order=symbol, order_id=order_id
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("Error in get_order_handler: %s", e)
|
||||
|
Reference in New Issue
Block a user