forked from kodorvan/stcs
Fixed
This commit is contained in:
@@ -43,6 +43,12 @@ async def set_switch_position_mode(tg_id: int, symbol: str, mode: int) -> str |
|
||||
tg_id,
|
||||
)
|
||||
return "You have an existing position, so position mode cannot be switched"
|
||||
if str(e).startswith("Open orders exist, so you cannot change position mode"):
|
||||
logger.debug(
|
||||
"Open orders exist, so you cannot change position mode for user: %s",
|
||||
tg_id,
|
||||
)
|
||||
return "Open orders exist, so you cannot change position mode"
|
||||
else:
|
||||
logger.error("Error connecting to Bybit for user %s: %s", tg_id, e)
|
||||
return False
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import logging.config
|
||||
|
||||
from app.bybit import get_bybit_client
|
||||
from app.bybit.get_functions.get_positions import get_active_positions_by_symbol
|
||||
from app.bybit.logger_bybit.logger_bybit import LOGGING_CONFIG
|
||||
|
||||
logging.config.dictConfig(LOGGING_CONFIG)
|
||||
@@ -13,6 +12,7 @@ async def set_tp_sl_for_position(
|
||||
symbol: str,
|
||||
take_profit_price: float,
|
||||
stop_loss_price: float,
|
||||
position_idx: int,
|
||||
) -> bool:
|
||||
"""
|
||||
Set take profit and stop loss for a symbol.
|
||||
@@ -20,14 +20,11 @@ async def set_tp_sl_for_position(
|
||||
:param symbol: Symbol to set take profit and stop loss for
|
||||
:param take_profit_price: Take profit price
|
||||
:param stop_loss_price: Stop loss price
|
||||
:param position_idx: Position index
|
||||
:return: bool
|
||||
"""
|
||||
try:
|
||||
client = await get_bybit_client(tg_id)
|
||||
user_positions = await get_active_positions_by_symbol(
|
||||
tg_id=tg_id, symbol=symbol
|
||||
)
|
||||
position_idx = user_positions.get("positionIdx")
|
||||
resp = client.set_trading_stop(
|
||||
category="linear",
|
||||
symbol=symbol,
|
||||
|
Reference in New Issue
Block a user