2
0
forked from kodorvan/stcs

The logic of the trading cycle has been changed, fixed errors when setting TP and SL

This commit is contained in:
algizn97
2025-11-09 13:10:13 +05:00
parent 39bbe8d997
commit 7c85c03d10
4 changed files with 178 additions and 158 deletions

View File

@@ -13,7 +13,7 @@ async def set_tp_sl_for_position(
take_profit_price: float,
stop_loss_price: float,
position_idx: int,
) -> bool:
) -> bool | str:
"""
Set take profit and stop loss for a symbol.
:param tg_id: Telegram user ID
@@ -21,7 +21,7 @@ async def set_tp_sl_for_position(
:param take_profit_price: Take profit price
:param stop_loss_price: Stop loss price
:param position_idx: Position index
:return: bool
:return: bool or str
"""
try:
client = await get_bybit_client(tg_id)
@@ -40,8 +40,18 @@ async def set_tp_sl_for_position(
logger.info("TP/SL for %s has been set", symbol)
return True
else:
logger.error("Error setting TP/SL for %s: %s", symbol, resp.get("retMsg"))
return False
error_msg = resp.get("retMsg")
if "not modified" in error_msg.lower():
logger.info("TP/SL for %s not modified: %s", symbol, error_msg)
return "not modified"
else:
logger.error("Error setting TP/SL for %s: %s", symbol, error_msg)
return False
except Exception as e:
logger.error("Error setting TP/SL for %s: %s", symbol, e)
return False
error_msg = str(e)
if "not modified" in error_msg.lower():
logger.info("TP/SL for %s not modified: %s", symbol, error_msg)
return "not modified"
else:
logger.error("Error set TP/SL for %s: %s", symbol, e)
return False