2
0
forked from kodorvan/stcs

Added a function to select the type of cost compensation.

This commit is contained in:
algizn97
2025-10-26 14:02:42 +05:00
parent 3ef8eae997
commit faae2475c1
2 changed files with 89 additions and 4 deletions

View File

@@ -341,3 +341,83 @@ async def set_commission_fee(callback_query: CallbackQuery, state: FSMContext) -
) )
finally: finally:
await state.clear() await state.clear()
@router_risk_management.callback_query(F.data == "compensation_commission")
async def compensation_commission(callback_query: CallbackQuery, state: FSMContext) -> None:
"""
Handles the 'compensation_commission' callback query.
Clears the current FSM state, edits the message text to display the compensation commission options,
and shows an inline keyboard for selection.
Args:
callback_query (CallbackQuery): Incoming callback query from Telegram inline keyboard.
state (FSMContext): Finite State Machine context for the current user session.
Logs:
Success or error messages with user identification.
"""
try:
await state.clear()
msg = await callback_query.message.edit_text(
text="Выберите за счет чего будет происходить компенсация комиссии: ",
reply_markup=kbi.commission_place,
)
await state.update_data(prompt_message_id=msg.message_id)
logger.debug(
"Command compensation_commission processed successfully for user: %s",
callback_query.from_user.id,
)
except Exception as e:
await callback_query.answer(
text="Произошла ошибка. Пожалуйста, попробуйте позже."
)
logger.error(
"Error processing command compensation_commission for user %s: %s",
callback_query.from_user.id,
e,
)
@router_risk_management.callback_query(
lambda c: c.data in ["Commission_for_qty", "Commission_for_tp"]
)
async def set_compensation_commission(callback_query: CallbackQuery, state: FSMContext) -> None:
"""
Handles user input for setting the compensation commission.
Updates FSM context with the selected option and persists the choice in database.
Sends an acknowledgement to user and clears FSM state afterward.
Args:
callback_query (CallbackQuery): Incoming callback query from Telegram inline keyboard.
state (FSMContext): Finite State Machine context for the current user session.
Logs:
Success or error messages with user identification.
"""
try:
req = await rq.set_commission_place(
tg_id=callback_query.from_user.id, commission_place=callback_query.data
)
if not req:
await callback_query.answer(
text="Произошла ошибка при установке компенсации комиссии. Пожалуйста, попробуйте позже."
)
return
if callback_query.data == "Commission_for_qty":
await callback_query.answer(text="Комиссия компенсируется по ставке.")
else:
await callback_query.answer(text="Комиссия компенсируется по тейк-профиту.")
except Exception as e:
logger.error(
"Error processing command compensation_commission for user %s: %s",
callback_query.from_user.id,
e,
)
finally:
await state.clear()

View File

@@ -130,12 +130,17 @@ async def risk_management(callback_query: CallbackQuery, state: FSMContext) -> N
commission_fee_rus = ( commission_fee_rus = (
"Да" if commission_fee == "Yes_commission_fee" else "Нет" "Да" if commission_fee == "Yes_commission_fee" else "Нет"
) )
commission_place = risk_management_data.commission_place
commission_place_rus = (
"Ставке" if commission_place == "Commission_for_qty" else "Тейк-профиту"
)
await callback_query.message.edit_text( await callback_query.message.edit_text(
text=f"Риск-менеджмент:\n\n" text=f"Риск-менеджмент:\n\n"
f"- Процент изменения цены для фиксации прибыли: {take_profit_percent:.2f}%\n" f"- Процент изменения цены для фиксации прибыли: {take_profit_percent:.2f}%\n"
f"- Процент изменения цены для фиксации убытка: {stop_loss_percent:.2f}%\n\n" f"- Процент изменения цены для фиксации убытка: {stop_loss_percent:.2f}%\n\n"
f"- Комиссия биржи для расчета прибыли: {commission_fee_rus}\n\n", f"- Комиссия биржи для расчета прибыли: {commission_fee_rus}\n\n"
f"- Компенсация комиссии по: {commission_place_rus}",
reply_markup=kbi.risk_management, reply_markup=kbi.risk_management,
) )
logger.debug( logger.debug(