소스 검색

Refactor balance and trading stats retrieval in info commands for consistency.

- Updated `balance.py` and `stats.py` to use `get_basic_stats()` instead of `get_balance_info()` and `get_trading_stats()`, respectively, ensuring uniformity in data retrieval methods.
- Enhanced `daily.py` and `performance.py` to utilize `get()` for safer access to dictionary keys, improving robustness against missing data and enhancing overall code clarity.
Carles Sentis 1 주 전
부모
커밋
eae76895a6
5개의 변경된 파일16개의 추가작업 그리고 13개의 파일을 삭제
  1. 1 1
      src/commands/info/balance.py
  2. 9 7
      src/commands/info/daily.py
  3. 4 3
      src/commands/info/performance.py
  4. 1 1
      src/commands/info/stats.py
  5. 1 1
      trading_bot.py

+ 1 - 1
src/commands/info/balance.py

@@ -22,7 +22,7 @@ class BalanceCommands(InfoCommandsBase):
                 return
 
             # Get balance info
-            balance_info = stats.get_balance_info()
+            balance_info = stats.get_basic_stats()
             if not balance_info:
                 await self._reply(update, "❌ Balance information not available.")
                 return

+ 9 - 7
src/commands/info/daily.py

@@ -36,18 +36,20 @@ class DailyCommands(InfoCommandsBase):
 
             period_lines = []
             for day_stats_item in daily_stats_list:
-                if day_stats_item['has_trades']:
-                    pnl_emoji = "🟢" if day_stats_item['pnl'] >= 0 else "🔴"
-                    pnl_str = formatter.format_price_with_symbol(day_stats_item['pnl'])
+                if day_stats_item.get('has_trades'):
+                    pnl_emoji = "🟢" if day_stats_item.get('pnl', 0) >= 0 else "🔴"
+                    pnl_str = formatter.format_price_with_symbol(day_stats_item.get('pnl', 0))
                     roe = day_stats_item.get('roe', 0.0)  # Get ROE from stats
                     roe_str = f"ROE: {roe:+.1f}%" if roe != 0 else ""
-                    period_lines.append(f"📅 <b>{day_stats_item['day_formatted']}</b>: {pnl_emoji} {pnl_str} ({day_stats_item['pnl_pct']:+.1f}%) {roe_str} | Trades: {day_stats_item['trades']}")
-                    total_pnl_all_days += day_stats_item['pnl']
-                    total_trades_all_days += day_stats_item['trades']
+                    day_str = day_stats_item.get('day', 'Unknown')
+                    period_lines.append(f"📅 <b>{day_str}</b>: {pnl_emoji} {pnl_str} ({day_stats_item.get('pnl_pct', 0):+.1f}%) {roe_str} | Trades: {day_stats_item.get('trades', 0)}")
+                    total_pnl_all_days += day_stats_item.get('pnl', 0)
+                    total_trades_all_days += day_stats_item.get('trades', 0)
                     total_roe_all_days += roe
                     trading_days_count += 1
                 else:
-                    period_lines.append(f"📅 <b>{day_stats_item['day_formatted']}</b>: 📭 No trading activity")
+                    day_str = day_stats_item.get('day', 'Unknown')
+                    period_lines.append(f"📅 <b>{day_str}</b>: 📭 No trading activity")
 
             if period_lines:
                 daily_text_parts.append("\n".join(period_lines))

+ 4 - 3
src/commands/info/performance.py

@@ -48,15 +48,16 @@ class PerformanceCommands(InfoCommandsBase):
 
             # Sort tokens by P&L
             sorted_tokens = sorted(
-                token_performance.items(),
-                key=lambda x: x[1].get('total_pnl', 0),
+                token_performance,
+                key=lambda x: x.get('total_pnl', 0),
                 reverse=True
             )
 
             formatter = get_formatter()
             performance_text = ["📊 <b>Token Performance Ranking</b>"]
 
-            for token, data in sorted_tokens:
+            for data in sorted_tokens:
+                token = data.get('token', 'Unknown')
                 total_pnl = data.get('total_pnl', 0)
                 total_trades = data.get('total_trades', 0)
                 win_rate = data.get('win_rate', 0)

+ 1 - 1
src/commands/info/stats.py

@@ -23,7 +23,7 @@ class StatsCommands(InfoCommandsBase):
                 return
 
             # Get trading stats
-            trading_stats = stats.get_trading_stats()
+            trading_stats = stats.get_basic_stats()
             if not trading_stats:
                 await self._reply(update, "❌ Trading statistics not available.")
                 return

+ 1 - 1
trading_bot.py

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