Sfoglia il codice sorgente

Re-enable copy trading commands and enhance COPY command handling

- Restored initialization of CopyTradingCommands in TelegramTradingBot, allowing access to copy trading functionalities.
- Updated command handlers to include the COPY command, enabling direct execution and improved user interaction.
- Enhanced regex filter to recognize "COPY" in keyboard inputs and added a dedicated handler for copy status commands.
- Updated management commands to include COPY in the keyboard options for better accessibility.
Carles Sentis 5 giorni fa
parent
commit
e3321a5260
3 ha cambiato i file con 32 aggiunte e 14 eliminazioni
  1. 30 12
      src/bot/core.py
  2. 1 1
      src/commands/management_commands.py
  3. 1 1
      trading_bot.py

+ 30 - 12
src/bot/core.py

@@ -31,8 +31,7 @@ from src.commands.info.risk import RiskCommands
 from src.commands.info.price import PriceCommands
 from src.commands.info.balance_adjustments import BalanceAdjustmentsCommands
 from src.commands.info.commands import CommandsInfo
-# DISABLE AGAIN: Copy trading still causing blocking issues
-# from src.commands.copy_trading_commands import CopyTradingCommands
+from src.commands.copy_trading_commands import CopyTradingCommands
 
 logger = logging.getLogger(__name__)
 
@@ -72,8 +71,7 @@ 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)
-        # DISABLE AGAIN: Copy trading still causing blocking issues
-        # self.copy_trading_cmds = CopyTradingCommands(self.monitoring_coordinator)
+        self.copy_trading_cmds = CopyTradingCommands(self.monitoring_coordinator)
 
         # Create a class to hold all info commands
         class InfoCommandsHandler:
@@ -156,6 +154,9 @@ class TelegramTradingBot:
         self.application.add_handler(CommandHandler("commands", self.commands_cmds.commands_command))
         self.application.add_handler(CommandHandler("c", self.commands_cmds.commands_command))  # Alias
         
+        # Copy trading commands (Step 1: Commands only, monitor still disabled)
+        self.application.add_handler(CommandHandler("copy", self.copy_trading_cmds.copy_command))
+        
         # Management commands
         self.application.add_handler(CommandHandler("monitoring", self.management_commands.monitoring_command))
         self.application.add_handler(CommandHandler("alarm", self.management_commands.alarm_command))
@@ -171,7 +172,7 @@ 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)'),
+            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)'),
             self.handle_keyboard_command
         ))
         
@@ -206,23 +207,40 @@ class TelegramTradingBot:
             "DEBUG": self.management_commands.debug_command,
             "VERSION": self.management_commands.version_command,
             "KEYBOARD": self.management_commands.keyboard_command,
+            "COPY": self._handle_copy_status_keyboard,
         }
 
         command_func = command_map.get(command_text)
         if command_func:
-            # We need to simulate a command call, so we'll prepend "/"
-            # to the message text to make it look like a real command.
-            original_text = update.message.text
-            update.message.text = f"/{original_text.lower()}"
-            await command_func(update, context)
-            # Restore original text
-            update.message.text = original_text
+            # For COPY command, handle specially
+            if command_text == "COPY":
+                await command_func(update, context)
+            else:
+                # We need to simulate a command call, so we'll prepend "/"
+                # to the message text to make it look like a real command.
+                original_text = update.message.text
+                update.message.text = f"/{original_text.lower()}"
+                await command_func(update, context)
+                # Restore original text
+                update.message.text = original_text
         else:
             logger.warning(f"Unknown keyboard command: {command_text}")
             await self.notification_manager.send_generic_notification(
                 f"Unknown command: {command_text}", chat_id=update.effective_chat.id
             )
 
+    async def _handle_copy_status_keyboard(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
+        """Handle COPY keyboard command by showing copy trading status."""
+        # Create a mock context with status args to avoid modifying original
+        from types import SimpleNamespace
+        
+        # Create a simple object that mimics the context for copy commands
+        mock_context = SimpleNamespace()
+        mock_context.args = ["status"]
+        mock_context.bot = context.bot
+        
+        await self.copy_trading_cmds.copy_command(update, mock_context)
+
     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}")

+ 1 - 1
src/commands/management_commands.py

@@ -523,7 +523,7 @@ Will trigger when {token} price moves {alarm['direction']} {target_price_str}
             [KeyboardButton("DAILY"), KeyboardButton("WEEKLY"), KeyboardButton("MONTHLY")],
             [KeyboardButton("RISK"), KeyboardButton("ALARM"), KeyboardButton("MONITORING")],
             [KeyboardButton("LOGS"), KeyboardButton("DEBUG"), KeyboardButton("VERSION")],
-            [KeyboardButton("COMMANDS"), KeyboardButton("KEYBOARD"), KeyboardButton("COO")]
+            [KeyboardButton("COMMANDS"), KeyboardButton("KEYBOARD"), KeyboardButton("COO"), KeyboardButton("COPY")]
         ]
 
         # Try to use custom keyboard from config if enabled

+ 1 - 1
trading_bot.py

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