Forráskód Böngészése

Update requirements and refactor command handling in TelegramTradingBot.

- Added `psutil` to requirements for enhanced system monitoring capabilities.
- Removed the `InfoCommands` class and integrated its functionality into dedicated command classes for price and balance adjustments, improving modularity and clarity.
- Updated command handlers in `TelegramTradingBot` to utilize the new command classes, streamlining command management and enhancing maintainability.
Carles Sentis 1 hete
szülő
commit
da854948d4
4 módosított fájl, 14 hozzáadás és 28 törlés
  1. 2 1
      requirements.txt
  2. 10 7
      src/bot/core.py
  3. 1 19
      src/commands/trading_commands.py
  4. 1 1
      trading_bot.py

+ 2 - 1
requirements.txt

@@ -2,4 +2,5 @@ hyperliquid==0.4.66
 python-telegram-bot[webhooks]==20.7
 python-dotenv==1.1.0
 pandas==2.2.3
-numpy==2.2.6 
+numpy==2.2.6
+psutil==7.0.0 

+ 10 - 7
src/bot/core.py

@@ -15,7 +15,6 @@ from src.trading.trading_engine import TradingEngine
 from src.monitoring.market_monitor import MarketMonitor
 from src.notifications.notification_manager import NotificationManager
 from src.commands.trading_commands import TradingCommands
-from src.commands.info_commands import InfoCommands
 from src.commands.management_commands import ManagementCommands
 from src.commands.info.balance import BalanceCommands
 from src.commands.info.positions import PositionsCommands
@@ -28,6 +27,9 @@ from src.commands.info.daily import DailyCommands
 from src.commands.info.weekly import WeeklyCommands
 from src.commands.info.monthly import MonthlyCommands
 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 CommandsCommands
 
 logger = logging.getLogger(__name__)
 
@@ -49,11 +51,9 @@ class TelegramTradingBot:
         self.trading_engine.set_market_monitor(self.market_monitor)
         
         # Initialize command handlers
-        self.info_commands = InfoCommands(self.trading_engine, self.notification_manager)
         self.management_commands = ManagementCommands(self.trading_engine, self.market_monitor)
         # Pass info and management command handlers to TradingCommands
         self.trading_commands = TradingCommands(self.trading_engine, self.notification_manager, 
-                                              info_commands_handler=self.info_commands, 
                                               management_commands_handler=self.management_commands)
         
     def is_authorized(self, chat_id: str) -> bool:
@@ -103,6 +103,9 @@ class TelegramTradingBot:
         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 = CommandsCommands(self.trading_engine, self.notification_manager)
 
         # Info commands
         self.application.add_handler(CommandHandler("balance", self.balance_cmds.balance_command))
@@ -111,15 +114,15 @@ class TelegramTradingBot:
         self.application.add_handler(CommandHandler("stats", self.stats_cmds.stats_command))
         self.application.add_handler(CommandHandler("trades", self.trades_cmds.trades_command))
         self.application.add_handler(CommandHandler("market", self.market_cmds.market_command))
-        self.application.add_handler(CommandHandler("price", self.info_commands.price_command))
+        self.application.add_handler(CommandHandler("price", self.price_cmds.price_command))
         self.application.add_handler(CommandHandler("performance", self.performance_cmds.performance_command))
         self.application.add_handler(CommandHandler("daily", self.daily_cmds.daily_command))
         self.application.add_handler(CommandHandler("weekly", self.weekly_cmds.weekly_command))
         self.application.add_handler(CommandHandler("monthly", self.monthly_cmds.monthly_command))
         self.application.add_handler(CommandHandler("risk", self.risk_cmds.risk_command))
-        self.application.add_handler(CommandHandler("balance_adjustments", self.info_commands.balance_adjustments_command))
-        self.application.add_handler(CommandHandler("commands", self.info_commands.commands_command))
-        self.application.add_handler(CommandHandler("c", self.info_commands.commands_command))  # Alias
+        self.application.add_handler(CommandHandler("balance_adjustments", self.balance_adjustments_cmds.balance_adjustments_command))
+        self.application.add_handler(CommandHandler("commands", self.commands_cmds.commands_command))
+        self.application.add_handler(CommandHandler("c", self.commands_cmds.commands_command))  # Alias
         
         # Management commands
         self.application.add_handler(CommandHandler("monitoring", self.management_commands.monitoring_command))

+ 1 - 19
src/commands/trading_commands.py

@@ -27,11 +27,10 @@ def _normalize_token_case(token: str) -> str:
 class TradingCommands:
     """Handles all trading-related Telegram commands."""
     
-    def __init__(self, trading_engine, notification_manager, info_commands_handler=None, management_commands_handler=None):
+    def __init__(self, trading_engine, notification_manager, management_commands_handler=None):
         """Initialize with trading engine, notification manager, and other command handlers."""
         self.trading_engine = trading_engine
         self.notification_manager = notification_manager
-        self.info_commands_handler = info_commands_handler
         self.management_commands_handler = management_commands_handler
     
     def _is_authorized(self, chat_id: str) -> bool:
@@ -630,23 +629,6 @@ This action cannot be undone.
         # Define a map for informational and management command callbacks
         # These commands expect `update` and `context` as if called by a CommandHandler
         command_action_map = {}
-        if self.info_commands_handler:
-            command_action_map.update({
-                "balance": self.info_commands_handler.balance_command,
-                "positions": self.info_commands_handler.positions_command,
-                "orders": self.info_commands_handler.orders_command,
-                "stats": self.info_commands_handler.stats_command,
-                "price": self.info_commands_handler.price_command,
-                "market": self.info_commands_handler.market_command,
-                "performance": self.info_commands_handler.performance_command,
-                "daily": self.info_commands_handler.daily_command,
-                "weekly": self.info_commands_handler.weekly_command,
-                "monthly": self.info_commands_handler.monthly_command,
-                "trades": self.info_commands_handler.trades_command,
-                "risk": self.info_commands_handler.risk_command,
-                # Note: 'help' is handled separately below as its main handler is in TelegramTradingBot core
-            })
-        
         if self.management_commands_handler:
             command_action_map.update({
                 "alarm": self.management_commands_handler.alarm_command,

+ 1 - 1
trading_bot.py

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