forked from kodorvan/stcs
Fixed
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import time
|
||||
import json
|
||||
import time
|
||||
|
||||
import logging.config
|
||||
from pybit import exceptions
|
||||
from pybit.unified_trading import HTTP
|
||||
@@ -28,7 +29,7 @@ def safe_float(val) -> float:
|
||||
return 0.0
|
||||
|
||||
|
||||
def format_trade_details_position(data):
|
||||
def format_trade_details_position(data, commission_fee):
|
||||
"""
|
||||
Форматирует информацию о сделке в виде строки.
|
||||
"""
|
||||
@@ -40,9 +41,15 @@ def format_trade_details_position(data):
|
||||
qty = float(msg.get('execQty', 0))
|
||||
order_type = msg.get('orderType', 'N/A')
|
||||
side = msg.get('side', '')
|
||||
commission_fee = float(msg.get('execFee', 0))
|
||||
commission = float(msg.get('execFee', 0))
|
||||
pnl = float(msg.get('execPnl', 0))
|
||||
|
||||
if commission_fee == "Да":
|
||||
if pnl >= 0:
|
||||
pnl -= commission
|
||||
else:
|
||||
pnl -= commission
|
||||
|
||||
movement = ''
|
||||
if side.lower() == 'buy':
|
||||
movement = 'Покупка'
|
||||
@@ -60,7 +67,7 @@ def format_trade_details_position(data):
|
||||
f"Закрыто позиций: {closed_size}\n"
|
||||
f"Тип ордера: {order_type}\n"
|
||||
f"Движение: {movement}\n"
|
||||
f"Комиссия за сделку: {commission_fee:.6f}\n"
|
||||
f"Комиссия за сделку: {commission:.6f}\n"
|
||||
f"Реализованная прибыль: {pnl:.6f} USDT"
|
||||
)
|
||||
else:
|
||||
@@ -71,7 +78,7 @@ def format_trade_details_position(data):
|
||||
f"Количество: {qty}\n"
|
||||
f"Тип ордера: {order_type}\n"
|
||||
f"Движение: {movement}\n"
|
||||
f"Комиссия за сделку: {commission_fee:.6f}"
|
||||
f"Комиссия за сделку: {commission:.6f}"
|
||||
)
|
||||
|
||||
|
||||
@@ -91,13 +98,15 @@ async def handle_execution_message(message, msg: dict) -> None:
|
||||
Обработчик сообщений об исполнении сделки.
|
||||
Логирует событие и проверяет условия для мартингейла и TP.
|
||||
"""
|
||||
logger.info(f"Исполнена сделка:\n{json.dumps(msg, indent=4, ensure_ascii=False)}")
|
||||
|
||||
pnl = parse_pnl_from_msg(msg)
|
||||
tg_id = message.from_user.id
|
||||
|
||||
data_main_stgs = await rq.get_user_main_settings(tg_id)
|
||||
data_main_risk_stgs = await rq.get_user_risk_management_settings(tg_id)
|
||||
take_profit_percent = safe_float(data_main_stgs.get('take_profit_percent', 2))
|
||||
|
||||
commission_fee = data_main_risk_stgs.get('commission_fee', "ДА")
|
||||
symbol = await rq.get_symbol(tg_id)
|
||||
api_key = await rq.get_bybit_api_key(tg_id)
|
||||
api_secret = await rq.get_bybit_secret_key(tg_id)
|
||||
@@ -106,7 +115,7 @@ async def handle_execution_message(message, msg: dict) -> None:
|
||||
positions_list = positions_resp.get('result', {}).get('list', [])
|
||||
position = positions_list[0] if positions_list else None
|
||||
|
||||
trade_info = format_trade_details_position(msg)
|
||||
trade_info = format_trade_details_position(msg, commission_fee=commission_fee)
|
||||
await message.answer(f"{trade_info}", reply_markup=inline_markup.back_to_main)
|
||||
|
||||
liquidation_threshold = -100
|
||||
|
@@ -3,4 +3,4 @@
|
||||
base_buttons_markup = ReplyKeyboardMarkup(keyboard=[
|
||||
[KeyboardButton(text="👤 Профиль")],
|
||||
# [KeyboardButton(text="Настройки")]
|
||||
], resize_keyboard=True, one_time_keyboard=True)
|
||||
], resize_keyboard=True, one_time_keyboard=False)
|
Reference in New Issue
Block a user