The logic of setting take profit and stop loss has been changed, added data for the end user

This commit is contained in:
algizn97
2025-10-29 20:58:04 +05:00
parent a8119d2811
commit e043a2429f
3 changed files with 127 additions and 132 deletions

View File

@@ -25,6 +25,7 @@ class WebSocketBot:
self.user_keys = {}
self.loop = None
self.message_handler = TelegramMessageHandler(telegram_bot)
self.last_execution_seq = {}
async def run_user_check_loop(self):
"""Run a loop to check for users and connect them to the WebSocket."""
@@ -83,12 +84,6 @@ class WebSocketBot:
self.user_sockets[tg_id] = self.ws_private
# Connect to the WebSocket private channel
# Handle position updates
self.ws_private.position_stream(
lambda msg: self.loop.call_soon_threadsafe(
asyncio.create_task, self.handle_position_update(msg)
)
)
# Handle order updates
self.ws_private.order_stream(
lambda msg: self.loop.call_soon_threadsafe(
@@ -106,17 +101,23 @@ class WebSocketBot:
logger.error("Error connecting user %s: %s", tg_id, e)
return False
async def handle_position_update(self, message):
"""Handle position updates."""
await self.message_handler.format_position_update(message)
async def handle_order_update(self, message, tg_id):
"""Handle order updates."""
await self.message_handler.format_order_update(message, tg_id)
async def handle_execution_update(self, message, tg_id):
"""Handle execution updates."""
await self.message_handler.format_execution_update(message, tg_id)
data_items = message.get('data', [])
if not data_items:
return
for exec_data in data_items:
seq = exec_data.get('seq')
if tg_id not in self.last_execution_seq:
self.last_execution_seq[tg_id] = -1
if seq <= self.last_execution_seq[tg_id]:
continue
self.last_execution_seq[tg_id] = seq
await self.message_handler.format_execution_update(message, tg_id)
@staticmethod
async def get_users_from_db():