forked from kodorvan/stcs
The stop trading button has been added, and the switch mode has been fixed
This commit is contained in:
@@ -7,25 +7,25 @@ logging.config.dictConfig(LOGGING_CONFIG)
|
||||
logger = logging.getLogger("close_positions")
|
||||
|
||||
|
||||
async def close_position(
|
||||
tg_id: int, symbol: str, side: str, position_idx: int, qty: float
|
||||
async def close_position_by_symbol(
|
||||
tg_id: int, symbol: str
|
||||
) -> bool:
|
||||
"""
|
||||
Closes all positions
|
||||
:param tg_id: Telegram user ID
|
||||
:param symbol: symbol
|
||||
:param side: side
|
||||
:param position_idx: position index
|
||||
:param qty: quantity
|
||||
:return: bool
|
||||
"""
|
||||
try:
|
||||
client = await get_bybit_client(tg_id)
|
||||
|
||||
if side == "Buy":
|
||||
r_side = "Sell"
|
||||
else:
|
||||
r_side = "Buy"
|
||||
response = client.get_positions(
|
||||
category="linear", symbol=symbol
|
||||
)
|
||||
positions = response.get("result", {}).get("list", [])
|
||||
r_side = "Sell" if positions[0].get("side") == "Buy" else "Buy"
|
||||
qty = positions[0].get("size")
|
||||
position_idx = positions[0].get("positionIdx")
|
||||
|
||||
response = client.place_order(
|
||||
category="linear",
|
||||
@@ -37,16 +37,16 @@ async def close_position(
|
||||
positionIdx=position_idx,
|
||||
)
|
||||
if response["retCode"] == 0:
|
||||
logger.info("All positions closed for %s for user %s", symbol, tg_id)
|
||||
logger.info("Positions closed for %s for user %s", symbol, tg_id)
|
||||
return True
|
||||
else:
|
||||
logger.error(
|
||||
"Error closing all positions for %s for user %s", symbol, tg_id
|
||||
"Error closing position for %s for user %s", symbol, tg_id
|
||||
)
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
"Error closing all positions for %s for user %s: %s", symbol, tg_id, e
|
||||
"Error closing positions for %s for user %s: %s", symbol, tg_id, e
|
||||
)
|
||||
return False
|
||||
|
||||
|
Reference in New Issue
Block a user