The logic of setting take profit and stop loss has been changed, added data for the end user
This commit is contained in:
		@@ -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():
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user