Browse Source

Refactor risk command and trading stats for improved data handling

- Updated the `risk_command` in `RiskCommands` to safely handle both old and new data structures for open positions, enhancing robustness.
- Modified the `get_token_performance` method in `TradingStats` to remove the limit parameter, allowing for a comprehensive performance report.
- Improved overall code clarity and maintainability.
Carles Sentis 2 days ago
parent
commit
23ba1fc8ea
3 changed files with 4 additions and 3 deletions
  1. 2 1
      src/commands/info/risk.py
  2. 1 1
      src/stats/trading_stats.py
  3. 1 1
      trading_bot.py

+ 2 - 1
src/commands/info/risk.py

@@ -56,8 +56,9 @@ class RiskCommands(InfoCommandsBase):
 
         lines = ["<b>Open Positions:</b>"]
         for p in positions:
+            position_info = p.get('position', p) # Handle both old and new structures for safety
             pnl_emoji = "🟢" if float(p.get('unrealizedPnl', 0.0)) >= 0 else "🔴"
-            lines.append(f"• {p['position']['coin']}: {p['position']['szi']} {p['position']['side']} @ ${p['position']['entryPx']} {pnl_emoji}")
+            lines.append(f"• {position_info['coin']}: {position_info['szi']} {position_info['side']} @ ${position_info['entryPx']} {pnl_emoji}")
         return "\n".join(lines) + "\n"
 
     async def _format_portfolio_summary(self, balance_data, positions):

+ 1 - 1
src/stats/trading_stats.py

@@ -782,7 +782,7 @@ class TradingStats:
         """Get comprehensive summary report."""
         try:
             perf_stats = self.get_performance_stats()
-            token_performance = self.get_token_performance(limit=10)
+            token_performance = self.get_token_performance()
             daily_stats = self.get_daily_stats(limit=7)
             risk_metrics = self.get_risk_metrics()
             balance_adjustments = self.get_balance_adjustments_summary()

+ 1 - 1
trading_bot.py

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