Fixed
This commit is contained in:
@@ -5,7 +5,7 @@ from aiogram.fsm.context import FSMContext
|
||||
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_orders,
|
||||
get_active_orders_by_symbol,
|
||||
@@ -22,7 +22,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 +43,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.
|
||||
@@ -64,9 +64,17 @@ async def get_positions_handler(
|
||||
await callback_query.answer(text="Нет активных позиций.")
|
||||
return
|
||||
|
||||
active_positions = [pos for pos in res if float(pos.get("size", 0)) > 0]
|
||||
|
||||
if not active_positions:
|
||||
await callback_query.answer(text="Нет активных позиций.")
|
||||
return
|
||||
|
||||
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(res),
|
||||
reply_markup=kbi.create_active_positions_keyboard(symbols=active_symbols_sides),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("Error in get_positions_handler: %s", e)
|
||||
@@ -82,7 +90,10 @@ async def get_positions_handler(
|
||||
)
|
||||
async def get_position_handler(callback_query: CallbackQuery, state: FSMContext):
|
||||
try:
|
||||
symbol = callback_query.data.split("_", 2)[2]
|
||||
data = callback_query.data
|
||||
parts = data.split("_")
|
||||
symbol = parts[2]
|
||||
get_side = parts[3]
|
||||
res = await get_active_positions_by_symbol(
|
||||
tg_id=callback_query.from_user.id, symbol=symbol
|
||||
)
|
||||
@@ -93,26 +104,48 @@ async def get_position_handler(callback_query: CallbackQuery, state: FSMContext)
|
||||
)
|
||||
return
|
||||
|
||||
symbol = res.get("symbol") or "Нет данных"
|
||||
avg_price = res.get("avgPrice") or "Нет данных"
|
||||
size = res.get("size") or "Нет данных"
|
||||
side = res.get("side") or ""
|
||||
position = next((pos for pos in res if pos.get("side") == get_side), None)
|
||||
|
||||
if position:
|
||||
side = position.get("side")
|
||||
symbol = position.get("symbol") or "Нет данных"
|
||||
avg_price = position.get("avgPrice") or "Нет данных"
|
||||
size = position.get("size") or "Нет данных"
|
||||
take_profit = position.get("takeProfit") or "Нет данных"
|
||||
stop_loss = position.get("stopLoss") or "Нет данных"
|
||||
position_idx = position.get("positionIdx")
|
||||
else:
|
||||
side = "Нет данных"
|
||||
symbol = "Нет данных"
|
||||
avg_price = "Нет данных"
|
||||
size = "Нет данных"
|
||||
take_profit = "Нет данных"
|
||||
stop_loss = "Нет данных"
|
||||
position_idx = "Нет данных"
|
||||
|
||||
side_rus = (
|
||||
"Покупка"
|
||||
if side == "Buy"
|
||||
else "Продажа" if side == "Sell" else "Нет данных"
|
||||
)
|
||||
take_profit = res.get("takeProfit") or "Нет данных"
|
||||
stop_loss = res.get("stopLoss") or "Нет данных"
|
||||
|
||||
position_idx_rus = ("Односторонний" if position_idx == 0
|
||||
else "Покупка в режиме хеджирования" if position_idx == 1
|
||||
else "Продажа в режиме хеджирования" if position_idx == 2
|
||||
else "Нет данных")
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text=f"Торговая пара: {symbol}\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),
|
||||
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),
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
@@ -126,7 +159,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.
|
||||
@@ -147,9 +180,17 @@ async def get_open_orders_handler(
|
||||
await callback_query.answer(text="Нет активных ордеров.")
|
||||
return
|
||||
|
||||
active_positions = [pos for pos in res if pos.get("orderStatus", 0) == "New"]
|
||||
|
||||
if not active_positions:
|
||||
await callback_query.answer(text="Нет активных ордеров.")
|
||||
return
|
||||
|
||||
active_orders_sides = [(pos.get("symbol"), pos.get("side")) for pos in active_positions]
|
||||
|
||||
await callback_query.message.edit_text(
|
||||
text="Ваши активные ордера:",
|
||||
reply_markup=kbi.create_active_orders_keyboard(res),
|
||||
reply_markup=kbi.create_active_orders_keyboard(orders=active_orders_sides),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("Error in get_open_orders_handler: %s", e)
|
||||
@@ -163,7 +204,10 @@ async def get_open_orders_handler(
|
||||
@router_get_positions_handlers.callback_query(lambda c: c.data.startswith("get_order_"))
|
||||
async def get_order_handler(callback_query: CallbackQuery, state: FSMContext):
|
||||
try:
|
||||
symbol = callback_query.data.split("_", 2)[2]
|
||||
data = callback_query.data
|
||||
parts = data.split("_")
|
||||
symbol = parts[2]
|
||||
get_side = parts[3]
|
||||
res = await get_active_orders_by_symbol(
|
||||
tg_id=callback_query.from_user.id, symbol=symbol
|
||||
)
|
||||
@@ -174,37 +218,52 @@ async def get_order_handler(callback_query: CallbackQuery, state: FSMContext):
|
||||
)
|
||||
return
|
||||
|
||||
symbol = res.get("symbol") or "Нет данных"
|
||||
price = res.get("price") or "Нет данных"
|
||||
qty = res.get("qty") or "Нет данных"
|
||||
side = res.get("side") or ""
|
||||
orders = next((pos for pos in res if pos.get("side") == get_side), None)
|
||||
|
||||
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 "Нет данных"
|
||||
order_id = orders.get("orderId")
|
||||
else:
|
||||
side = "Нет данных"
|
||||
symbol = "Нет данных"
|
||||
price = "Нет данных"
|
||||
qty = "Нет данных"
|
||||
order_type = "Нет данных"
|
||||
trigger_price = "Нет данных"
|
||||
take_profit = "Нет данных"
|
||||
stop_loss = "Нет данных"
|
||||
order_id = "Нет данных"
|
||||
|
||||
side_rus = (
|
||||
"Покупка"
|
||||
if side == "Buy"
|
||||
else "Продажа" if side == "Sell" else "Нет данных"
|
||||
)
|
||||
order_type = res.get("orderType") or ""
|
||||
|
||||
order_type_rus = (
|
||||
"Рыночный"
|
||||
if order_type == "Market"
|
||||
else "Лимитный" if order_type == "Limit" else "Нет данных"
|
||||
)
|
||||
trigger_price = res.get("triggerPrice") or "Нет данных"
|
||||
take_profit = res.get("takeProfit") or "Нет данных"
|
||||
stop_loss = res.get("stopLoss") or "Нет данных"
|
||||
|
||||
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),
|
||||
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),
|
||||
)
|
||||
await rq.set_user_symbol(tg_id=callback_query.from_user.id, symbol=symbol)
|
||||
except Exception as e:
|
||||
logger.error("Error in get_order_handler: %s", e)
|
||||
await callback_query.answer(
|
||||
|
Reference in New Issue
Block a user