Jelajahi Sumber

Temporarily disable copy trading functionality for debugging

- Commented out initialization and command handlers related to copy trading in TelegramTradingBot.
- Disabled copy trading monitor initialization and startup in MonitoringCoordinator.
- Added a debug message handler to log all incoming messages for better troubleshooting.
Carles Sentis 5 hari lalu
induk
melakukan
488075e0e1
3 mengubah file dengan 42 tambahan dan 16 penghapusan
  1. 28 9
      src/bot/core.py
  2. 13 6
      src/monitoring/monitoring_coordinator.py
  3. 1 1
      trading_bot.py

+ 28 - 9
src/bot/core.py

@@ -71,7 +71,8 @@ class TelegramTradingBot:
         self.price_cmds = PriceCommands(self.trading_engine, self.notification_manager)
         self.balance_adjustments_cmds = BalanceAdjustmentsCommands(self.trading_engine, self.notification_manager)
         self.commands_cmds = CommandsInfo(self.trading_engine, self.notification_manager)
-        self.copy_trading_cmds = CopyTradingCommands(self.monitoring_coordinator)
+        # TEMPORARY: Disable copy trading commands initialization for debugging
+        # self.copy_trading_cmds = CopyTradingCommands(self.monitoring_coordinator)
 
         # Create a class to hold all info commands
         class InfoCommandsHandler:
@@ -154,9 +155,10 @@ class TelegramTradingBot:
         self.application.add_handler(CommandHandler("commands", self.commands_cmds.commands_command))
         
         # Copy trading commands
-        self.application.add_handler(CommandHandler("copy_status", self.copy_trading_cmds.copy_status_command))
-        self.application.add_handler(CommandHandler("copy_start", self.copy_trading_cmds.copy_start_command))
-        self.application.add_handler(CommandHandler("copy_stop", self.copy_trading_cmds.copy_stop_command))
+        # TEMPORARY: Disable copy trading commands for debugging
+        # self.application.add_handler(CommandHandler("copy_status", self.copy_trading_cmds.copy_status_command))
+        # self.application.add_handler(CommandHandler("copy_start", self.copy_trading_cmds.copy_start_command))
+        # self.application.add_handler(CommandHandler("copy_stop", self.copy_trading_cmds.copy_stop_command))
         self.application.add_handler(CommandHandler("c", self.commands_cmds.commands_command))  # Alias
         
         # Management commands
@@ -174,10 +176,13 @@ class TelegramTradingBot:
         # Callback and message handlers
         self.application.add_handler(CallbackQueryHandler(self.trading_commands.button_callback))
         self.application.add_handler(MessageHandler(
-            filters.Regex(r'^(LONG|SHORT|EXIT|SL|TP|LEVERAGE|BALANCE|POSITIONS|ORDERS|STATS|MARKET|PERFORMANCE|DAILY|WEEKLY|MONTHLY|RISK|ALARM|MONITORING|LOGS|DEBUG|VERSION|COMMANDS|KEYBOARD|COO|COPY_STATUS|COPY_START|COPY_STOP)'),
+            filters.Regex(r'^(LONG|SHORT|EXIT|SL|TP|LEVERAGE|BALANCE|POSITIONS|ORDERS|STATS|MARKET|PERFORMANCE|DAILY|WEEKLY|MONTHLY|RISK|ALARM|MONITORING|LOGS|DEBUG|VERSION|COMMANDS|KEYBOARD|COO)'),
             self.handle_keyboard_command
         ))
         
+        # Debug message handler to catch all messages (should be last)
+        self.application.add_handler(MessageHandler(filters.ALL, self.debug_message_handler))
+        
     async def handle_keyboard_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
         """Handles commands sent via the main keyboard."""
         command_text = update.message.text.upper()
@@ -209,9 +214,10 @@ class TelegramTradingBot:
             "DEBUG": self.management_commands.debug_command,
             "VERSION": self.management_commands.version_command,
             "KEYBOARD": self.management_commands.keyboard_command,
-            "COPY_STATUS": self.copy_trading_cmds.copy_status_command,
-            "COPY_START": self.copy_trading_cmds.copy_start_command,
-            "COPY_STOP": self.copy_trading_cmds.copy_stop_command,
+            # TEMPORARY: Disable copy trading keyboard commands for debugging
+            # "COPY_STATUS": self.copy_trading_cmds.copy_status_command,
+            # "COPY_START": self.copy_trading_cmds.copy_start_command,
+            # "COPY_STOP": self.copy_trading_cmds.copy_stop_command,
         }
 
         command_func = command_map.get(command_text)
@@ -227,12 +233,25 @@ class TelegramTradingBot:
                 f"Unknown command: {command_text}", chat_id=update.effective_chat.id
             )
 
+    async def debug_message_handler(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
+        """Debug handler to log all incoming messages."""
+        try:
+            chat_id = update.effective_chat.id if update.effective_chat else "unknown"
+            message_text = update.message.text if update.message and update.message.text else "no text"
+            logger.info(f"🐛 DEBUG: Received message from chat_id={chat_id}, text='{message_text}'")
+            logger.info(f"🐛 DEBUG: Expected chat_id={Config.TELEGRAM_CHAT_ID}")
+            logger.info(f"🐛 DEBUG: Authorization result={self.is_authorized(chat_id)}")
+        except Exception as e:
+            logger.error(f"Error in debug message handler: {e}")
+
     async def start_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
         """Handle the /start command."""
         logger.info(f"/start command triggered by chat_id: {update.effective_chat.id}")
         logger.debug(f"Full Update object in start_command: {update}")
 
         chat_id = update.effective_chat.id
+        logger.info(f"🔍 Authorization check: chat_id={chat_id}, expected={Config.TELEGRAM_CHAT_ID}")
+        
         if not self.is_authorized(chat_id):
             logger.warning(f"Unauthorized access attempt by chat_id: {chat_id} in /start.")
             try:
@@ -254,7 +273,7 @@ class TelegramTradingBot:
 • Exit: /exit {Config.DEFAULT_TRADING_TOKEN} (closes position)
 • Info: /balance, /positions, /orders
 
-�� <b>Market Data:</b>
+📊 <b>Market Data:</b>
 • /market - Detailed market overview
 • /price - Quick price check
 

+ 13 - 6
src/monitoring/monitoring_coordinator.py

@@ -43,8 +43,11 @@ class MonitoringCoordinator:
         # Initialize copy trading monitor if available
         if COPY_TRADING_AVAILABLE:
             try:
-                self.copy_trading_monitor = CopyTradingMonitor(hl_client, notification_manager)
-                logger.info("✅ Copy trading monitor initialized")
+                # TEMPORARY: Disable copy trading monitor for debugging
+                # self.copy_trading_monitor = CopyTradingMonitor(hl_client, notification_manager)
+                # logger.info("✅ Copy trading monitor initialized")
+                self.copy_trading_monitor = None
+                logger.info("🚫 Copy trading monitor temporarily disabled for debugging")
             except Exception as e:
                 logger.error(f"❌ Failed to initialize copy trading monitor: {e}")
                 self.copy_trading_monitor = None
@@ -79,8 +82,10 @@ class MonitoringCoordinator:
             # Start copy trading monitor if enabled
             if self.copy_trading_monitor and hasattr(self.copy_trading_monitor, 'enabled') and self.copy_trading_monitor.enabled:
                 try:
-                    asyncio.create_task(self.copy_trading_monitor.start_monitoring())
-                    logger.info("🔄 Copy trading monitor started")
+                    # TEMPORARY: Disable copy trading monitor startup for debugging
+                    # asyncio.create_task(self.copy_trading_monitor.start_monitoring())
+                    # logger.info("🔄 Copy trading monitor started")
+                    logger.info("🚫 Copy trading monitor startup skipped for debugging")
                 except Exception as e:
                     logger.error(f"❌ Failed to start copy trading monitor: {e}")
             
@@ -123,8 +128,10 @@ class MonitoringCoordinator:
         # Stop copy trading monitor
         if self.copy_trading_monitor and hasattr(self.copy_trading_monitor, 'stop_monitoring'):
             try:
-                await self.copy_trading_monitor.stop_monitoring()
-                logger.info("🛑 Copy trading monitor stopped")
+                # TEMPORARY: Skip copy trading monitor stop for debugging
+                # await self.copy_trading_monitor.stop_monitoring()
+                # logger.info("🛑 Copy trading monitor stopped")
+                logger.info("🚫 Copy trading monitor stop skipped (was disabled)")
             except Exception as e:
                 logger.error(f"❌ Error stopping copy trading monitor: {e}")
         

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 
 # Bot version
-BOT_VERSION = "3.0.316"
+BOT_VERSION = "3.0.317"
 
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))