Quellcode durchsuchen

Refactor TelegramTradingBot to integrate new info command handlers for enhanced trading data access. This update includes the addition of various command classes for balance, positions, orders, stats, trades, market, performance, daily, weekly, monthly, risk, and price, improving the overall command structure and user experience. The TradingCommands class has also been updated to accommodate the new info commands handler.

Carles Sentis vor 1 Woche
Ursprung
Commit
e6bbc69807
3 geänderte Dateien mit 45 neuen und 21 gelöschten Zeilen
  1. 41 18
      src/bot/core.py
  2. 3 2
      src/commands/trading_commands.py
  3. 1 1
      trading_bot.py

+ 41 - 18
src/bot/core.py

@@ -52,9 +52,48 @@ class TelegramTradingBot:
         
         # Initialize command handlers
         self.management_commands = ManagementCommands(self.trading_engine, self.market_monitor)
+        
+        # Instantiate new info command classes
+        self.balance_cmds = BalanceCommands(self.trading_engine, self.notification_manager)
+        self.positions_cmds = PositionsCommands(self.trading_engine, self.notification_manager)
+        self.orders_cmds = OrdersCommands(self.trading_engine, self.notification_manager)
+        self.stats_cmds = StatsCommands(self.trading_engine, self.notification_manager)
+        self.trades_cmds = TradesCommands(self.trading_engine, self.notification_manager)
+        self.market_cmds = MarketCommands(self.trading_engine, self.notification_manager)
+        self.performance_cmds = PerformanceCommands(self.trading_engine, self.notification_manager)
+        self.daily_cmds = DailyCommands(self.trading_engine, self.notification_manager)
+        self.weekly_cmds = WeeklyCommands(self.trading_engine, self.notification_manager)
+        self.monthly_cmds = MonthlyCommands(self.trading_engine, self.notification_manager)
+        self.risk_cmds = RiskCommands(self.trading_engine, self.notification_manager)
+        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)
+
+        # Create a class to hold all info commands
+        class InfoCommandsHandler:
+            def __init__(self):
+                self.balance_command = self.balance_cmds.balance_command
+                self.positions_command = self.positions_cmds.positions_command
+                self.orders_command = self.orders_cmds.orders_command
+                self.stats_command = self.stats_cmds.stats_command
+                self.price_command = self.price_cmds.price_command
+                self.market_command = self.market_cmds.market_command
+                self.performance_command = self.performance_cmds.performance_command
+                self.daily_command = self.daily_cmds.daily_command
+                self.weekly_command = self.weekly_cmds.weekly_command
+                self.monthly_command = self.monthly_cmds.monthly_command
+                self.trades_command = self.trades_cmds.trades_command
+                self.risk_command = self.risk_cmds.risk_command
+
+        self.info_commands = InfoCommandsHandler()
+        
         # Pass info and management command handlers to TradingCommands
-        self.trading_commands = TradingCommands(self.trading_engine, self.notification_manager, 
-                                              management_commands_handler=self.management_commands)
+        self.trading_commands = TradingCommands(
+            self.trading_engine, 
+            self.notification_manager,
+            management_commands_handler=self.management_commands,
+            info_commands_handler=self.info_commands
+        )
         
     def is_authorized(self, chat_id: str) -> bool:
         """Check if the chat ID is authorized to use the bot."""
@@ -91,22 +130,6 @@ class TelegramTradingBot:
         self.application.add_handler(CommandHandler("tp", self.trading_commands.tp_command))
         self.application.add_handler(CommandHandler("coo", self.trading_commands.coo_command))
         
-        # Instantiate new info command classes
-        self.balance_cmds = BalanceCommands(self.trading_engine, self.notification_manager)
-        self.positions_cmds = PositionsCommands(self.trading_engine, self.notification_manager)
-        self.orders_cmds = OrdersCommands(self.trading_engine, self.notification_manager)
-        self.stats_cmds = StatsCommands(self.trading_engine, self.notification_manager)
-        self.trades_cmds = TradesCommands(self.trading_engine, self.notification_manager)
-        self.market_cmds = MarketCommands(self.trading_engine, self.notification_manager)
-        self.performance_cmds = PerformanceCommands(self.trading_engine, self.notification_manager)
-        self.daily_cmds = DailyCommands(self.trading_engine, self.notification_manager)
-        self.weekly_cmds = WeeklyCommands(self.trading_engine, self.notification_manager)
-        self.monthly_cmds = MonthlyCommands(self.trading_engine, self.notification_manager)
-        self.risk_cmds = RiskCommands(self.trading_engine, self.notification_manager)
-        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)
-
         # Info commands
         self.application.add_handler(CommandHandler("balance", self.balance_cmds.balance_command))
         self.application.add_handler(CommandHandler("positions", self.positions_cmds.positions_command))

+ 3 - 2
src/commands/trading_commands.py

@@ -27,11 +27,12 @@ def _normalize_token_case(token: str) -> str:
 class TradingCommands:
     """Handles all trading-related Telegram commands."""
     
-    def __init__(self, trading_engine, notification_manager, management_commands_handler=None):
-        """Initialize with trading engine, notification manager, and other command handlers."""
+    def __init__(self, trading_engine, notification_manager, management_commands_handler=None, info_commands_handler=None):
+        """Initialize trading commands with required dependencies."""
         self.trading_engine = trading_engine
         self.notification_manager = notification_manager
         self.management_commands_handler = management_commands_handler
+        self.info_commands_handler = info_commands_handler
     
     def _is_authorized(self, chat_id: str) -> bool:
         """Check if the chat ID is authorized."""

+ 1 - 1
trading_bot.py

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