Fixed
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import asyncio
|
||||
import logging.config
|
||||
import time
|
||||
|
||||
import app.services.Bybit.functions.balance as balance_g
|
||||
import app.services.Bybit.functions.price_symbol as price_symbol
|
||||
import app.telegram.database.requests as rq
|
||||
@@ -47,11 +46,10 @@ def format_trade_details_position(data, commission_fee):
|
||||
Форматирует информацию о сделке в виде строки.
|
||||
"""
|
||||
msg = data.get("data", [{}])[0]
|
||||
|
||||
closed_size = safe_float(msg.get("closedSize", 0))
|
||||
symbol = msg.get("symbol", "N/A")
|
||||
entry_price = safe_float(msg.get("execPrice", 0))
|
||||
qty = safe_float(msg.get("execQty", 0))
|
||||
qty = safe_float(msg.get("orderQty", 0))
|
||||
order_type = msg.get("orderType", "N/A")
|
||||
side = msg.get("side", "")
|
||||
commission = safe_float(msg.get("execFee", 0))
|
||||
@@ -69,7 +67,7 @@ def format_trade_details_position(data, commission_fee):
|
||||
movement = side
|
||||
|
||||
if closed_size > 0:
|
||||
return (
|
||||
text = (
|
||||
f"Сделка закрыта:\n"
|
||||
f"Торговая пара: {symbol}\n"
|
||||
f"Цена исполнения: {entry_price:.6f}\n"
|
||||
@@ -80,8 +78,9 @@ def format_trade_details_position(data, commission_fee):
|
||||
f"Комиссия за сделку: {commission:.6f}\n"
|
||||
f"Реализованная прибыль: {pnl:.6f} USDT"
|
||||
)
|
||||
return text
|
||||
if order_type == "Market":
|
||||
return (
|
||||
text = (
|
||||
f"Сделка открыта:\n"
|
||||
f"Торговая пара: {symbol}\n"
|
||||
f"Цена исполнения: {entry_price:.6f}\n"
|
||||
@@ -90,6 +89,7 @@ def format_trade_details_position(data, commission_fee):
|
||||
f"Движение: {movement}\n"
|
||||
f"Комиссия за сделку: {commission:.6f}"
|
||||
)
|
||||
return text
|
||||
return None
|
||||
|
||||
|
||||
@@ -102,8 +102,6 @@ def format_order_details_position(data):
|
||||
qty = safe_float(msg.get("qty", 0))
|
||||
cum_exec_qty = safe_float(msg.get("cumExecQty", 0))
|
||||
cum_exec_fee = safe_float(msg.get("cumExecFee", 0))
|
||||
take_profit = safe_float(msg.get("takeProfit", 0))
|
||||
stop_loss = safe_float(msg.get("stopLoss", 0))
|
||||
order_status = msg.get("orderStatus", "N/A")
|
||||
symbol = msg.get("symbol", "N/A")
|
||||
order_type = msg.get("orderType", "N/A")
|
||||
@@ -126,8 +124,6 @@ def format_order_details_position(data):
|
||||
f"Исполнено позиций: {cum_exec_qty}\n"
|
||||
f"Тип ордера: {order_type}\n"
|
||||
f"Движение: {movement}\n"
|
||||
f"Тейк-профит: {take_profit:.6f}\n"
|
||||
f"Стоп-лосс: {stop_loss:.6f}\n"
|
||||
f"Комиссия за сделку: {cum_exec_fee:.6f}\n"
|
||||
)
|
||||
return text
|
||||
@@ -140,8 +136,6 @@ def format_order_details_position(data):
|
||||
f"Количество: {qty}\n"
|
||||
f"Тип ордера: {order_type}\n"
|
||||
f"Движение: {movement}\n"
|
||||
f"Тейк-профит: {take_profit:.6f}\n"
|
||||
f"Стоп-лосс: {stop_loss:.6f}\n"
|
||||
)
|
||||
return text
|
||||
|
||||
@@ -153,8 +147,6 @@ def format_order_details_position(data):
|
||||
f"Количество: {qty}\n"
|
||||
f"Тип ордера: {order_type}\n"
|
||||
f"Движение: {movement}\n"
|
||||
f"Тейк-профит: {take_profit:.6f}\n"
|
||||
f"Стоп-лосс: {stop_loss:.6f}\n"
|
||||
)
|
||||
return text
|
||||
return None
|
||||
@@ -206,7 +198,6 @@ async def handle_execution_message(message, msg):
|
||||
Обработчик сообщений об исполнении сделки.
|
||||
Логирует событие и проверяет условия для мартингейла и TP.
|
||||
"""
|
||||
|
||||
tg_id = message.from_user.id
|
||||
data = msg.get("data", [{}])[0]
|
||||
data_main_risk_stgs = await rq.get_user_risk_management_settings(tg_id)
|
||||
@@ -270,7 +261,7 @@ async def handle_execution_message(message, msg):
|
||||
)
|
||||
|
||||
elif pnl > 0:
|
||||
await rq.update_martingale_step(tg_id, 0)
|
||||
await rq.update_martingale_step(tg_id, 1)
|
||||
num = data_main_stgs.get("base_quantity")
|
||||
await rq.update_starting_quantity(tg_id=tg_id, num=num)
|
||||
await message.answer(
|
||||
@@ -405,7 +396,7 @@ async def open_position(
|
||||
logger.info(f"Set leverage to {leverage_to_set} for {symbol}")
|
||||
except exceptions.InvalidRequestError as e:
|
||||
if "110043" in str(e):
|
||||
logger.info(f"Leverage already set to {leverage} for {symbol}")
|
||||
logger.info(f"Leverage already set to {leverage_to_set} for {symbol}")
|
||||
else:
|
||||
raise e
|
||||
|
||||
@@ -482,7 +473,7 @@ async def open_position(
|
||||
logger.info("Режим TP/SL уже установлен - пропускаем")
|
||||
else:
|
||||
raise
|
||||
resp = client.set_trading_stop(
|
||||
client.set_trading_stop(
|
||||
category="linear",
|
||||
symbol=symbol,
|
||||
takeProfit=str(round(take_profit_price, 5)),
|
||||
|
Reference in New Issue
Block a user