The entire database has been changed to PostgresSQL. The entire code has been updated.

This commit is contained in:
algizn97
2025-10-01 15:23:21 +05:00
parent e5a3de4ed8
commit 97662081ce
49 changed files with 7916 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
import logging.config
from aiogram import F, Router
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery
from app.bybit.close_positions import cancel_all_orders, cancel_order, close_position
from logger_helper.logger_helper import LOGGING_CONFIG
logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger("close_orders")
router_close_orders = Router(name="close_orders")
@router_close_orders.callback_query(
lambda c: c.data and c.data.startswith("close_position_")
)
async def close_position_handler(
callback_query: CallbackQuery, state: FSMContext
) -> None:
"""
Close a position.
:param callback_query: Incoming callback query from Telegram inline keyboard.
:param state: Finite State Machine context for the current user session.
:return: None
"""
try:
symbol = callback_query.data.split("_", 2)[2]
res = await close_position(tg_id=callback_query.from_user.id, symbol=symbol)
if not res:
await callback_query.answer(text="Произошла ошибка при закрытии позиции.")
return
await callback_query.answer(text="Позиция успешно закрыта.")
logger.debug(
"Command close_position processed successfully for user: %s",
callback_query.from_user.id,
)
except Exception as e:
await callback_query.answer(text="Произошла ошибка при закрытии позиции.")
logger.error(
"Error processing command close_position for user %s: %s",
callback_query.from_user.id,
e,
)
finally:
await state.clear()
@router_close_orders.callback_query(
lambda c: c.data and c.data.startswith("close_order_")
)
async def cancel_order_handler(
callback_query: CallbackQuery, state: FSMContext
) -> None:
"""
Cancel an order.
:param callback_query: Incoming callback query from Telegram inline keyboard.
:param state: Finite State Machine context for the current user session.
:return: None
"""
try:
symbol = callback_query.data.split("_", 2)[2]
res = await cancel_order(tg_id=callback_query.from_user.id, symbol=symbol)
if not res:
await callback_query.answer(text="Произошла ошибка при закрытии ордера.")
return
await callback_query.answer(text="Ордер успешно закрыт.")
logger.debug(
"Command close_order processed successfully for user: %s",
callback_query.from_user.id,
)
except Exception as e:
await callback_query.answer(text="Произошла ошибка при закрытии ордера.")
logger.error(
"Error processing command close_order for user %s: %s",
callback_query.from_user.id,
e,
)
finally:
await state.clear()
@router_close_orders.callback_query(F.data == "cancel_all_orders")
async def cancel_all_orders_handler(
callback_query: CallbackQuery, state: FSMContext
) -> None:
"""
Close all open positions and orders.
:param callback_query: Incoming callback query from Telegram inline keyboard.
:param state: Finite State Machine context for the current user session.
:return: None
"""
try:
res = await cancel_all_orders(tg_id=callback_query.from_user.id)
if not res:
await callback_query.answer(
text="Произошла ошибка при закрытии всех ордеров."
)
return
await callback_query.answer(text="Все ордера успешно закрыты.")
logger.debug(
"Command close_all_orders processed successfully for user: %s",
callback_query.from_user.id,
)
except Exception as e:
await callback_query.answer(text="Произошла ошибка при закрытии всех ордеров.")
logger.error(
"Error processing command close_all_orders for user %s: %s",
callback_query.from_user.id,
e,
)
finally:
await state.clear()