Browse Source

Update trades command to ensure trade ID is always a string and improve error logging by safely accessing trade symbol. This enhances data integrity and provides clearer error messages when processing trades.

Carles Sentis 3 days ago
parent
commit
ef2145c25c
2 changed files with 6 additions and 3 deletions
  1. 5 2
      src/commands/info/trades.py
  2. 1 1
      trading_bot.py

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

@@ -87,11 +87,14 @@ class TradesCommands(InfoCommandsBase):
                             logger.warning(f"Could not parse trade_time: {trade_time}")
 
                     # Add trade ID
-                    trade_id = trade.get('id', 'unknown')
+                    trade_id = str(trade.get('id', 'unknown'))
                     trades_text += f"   🆔 Trade ID: {trade_id[:8]}\n\n"
 
                 except Exception as e:
-                    logger.error(f"Error processing trade {trade.get('symbol', 'unknown')}: {e}")
+                    # The trade object here might be an int if the db issue wasn't fully fixed,
+                    # so we safely access symbol only if it's a dict.
+                    symbol_for_error = trade.get('symbol', 'unknown') if isinstance(trade, dict) else "unknown"
+                    logger.error(f"Error processing trade {symbol_for_error}: {e}")
                     continue
 
             await self._reply(update, trades_text.strip())

+ 1 - 1
trading_bot.py

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