浏览代码

Update risk and trades commands to improve trading statistics display and add defensive checks for trade data. Refactor risk command to utilize performance statistics for enhanced accuracy, and implement type checking in trades command to ensure data integrity.

Carles Sentis 3 天之前
父节点
当前提交
3eb18bf1c6
共有 3 个文件被更改,包括 11 次插入5 次删除
  1. 5 4
      src/commands/info/risk.py
  2. 5 0
      src/commands/info/trades.py
  3. 1 1
      trading_bot.py

+ 5 - 4
src/commands/info/risk.py

@@ -112,11 +112,12 @@ class RiskCommands(InfoCommandsBase):
             
             
             # Add trading statistics
             # Add trading statistics
             if stats:
             if stats:
+                performance_stats = stats.get_performance_stats()
                 message += f"\n📊 <b>Trading Statistics:</b>\n"
                 message += f"\n📊 <b>Trading Statistics:</b>\n"
-                message += f"Win Rate: {stats.get('win_rate', 0):.2f}%\n"
-                message += f"Profit Factor: {stats.get('profit_factor', 0):.2f}\n"
-                message += f"Average Win: {await self.formatter.format_price_with_symbol(stats.get('avg_win', 0))}\n"
-                message += f"Average Loss: {await self.formatter.format_price_with_symbol(stats.get('avg_loss', 0))}\n"
+                message += f"Win Rate: {performance_stats.get('win_rate', 0):.2f}%\n"
+                message += f"Profit Factor: {performance_stats.get('profit_factor', 0):.2f}\n"
+                message += f"Average Win: {await self.formatter.format_price_with_symbol(performance_stats.get('average_win', 0))}\n"
+                message += f"Average Loss: {await self.formatter.format_price_with_symbol(performance_stats.get('average_loss', 0))}\n"
             
             
             await update.message.reply_text(message, parse_mode='HTML')
             await update.message.reply_text(message, parse_mode='HTML')
             
             

+ 5 - 0
src/commands/info/trades.py

@@ -33,6 +33,11 @@ class TradesCommands(InfoCommandsBase):
 
 
             for trade in recent_trades:
             for trade in recent_trades:
                 try:
                 try:
+                    # Defensive check to ensure 'trade' is a dictionary
+                    if not isinstance(trade, dict):
+                        logger.warning(f"Skipping non-dict item in recent_trades: {trade}")
+                        continue
+
                     symbol = trade.get('symbol', 'unknown')
                     symbol = trade.get('symbol', 'unknown')
                     base_asset = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
                     base_asset = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
                     side = trade.get('side', 'unknown').upper()
                     side = trade.get('side', 'unknown').upper()

+ 1 - 1
trading_bot.py

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