Procházet zdrojové kódy

Refactor price command to handle missing ticker data more gracefully by using default values. This change improves the robustness of price information retrieval and ensures consistent formatting in the output.

Carles Sentis před 4 dny
rodič
revize
a9cde77ea0
2 změnil soubory, kde provedl 7 přidání a 7 odebrání
  1. 6 6
      src/commands/info/price.py
  2. 1 1
      trading_bot.py

+ 6 - 6
src/commands/info/price.py

@@ -44,22 +44,22 @@ class PriceCommands(InfoCommandsBase):
             price_text_parts = [f"💰 <b>{token} Price Information</b>"]
 
             # Current price
-            current_price = float(ticker.get('last', 0))
+            current_price = float(ticker.get('last') or 0)
             price_text_parts.append(f"\n📊 <b>Current Price:</b> {await formatter.format_price_with_symbol(current_price, token)}")
 
             # 24h change
-            change_24h = float(ticker.get('percentage', 0))
+            change_24h = float(ticker.get('percentage') or 0)
             change_emoji = "🟢" if change_24h >= 0 else "🔴"
             price_text_parts.append(f"📈 <b>24h Change:</b> {change_emoji} {change_24h:+.2f}%")
 
             # 24h high/low
-            high_24h = float(ticker.get('high', 0))
-            low_24h = float(ticker.get('low', 0))
+            high_24h = float(ticker.get('high') or 0)
+            low_24h = float(ticker.get('low') or 0)
             price_text_parts.append(f"📊 <b>24h Range:</b> {await formatter.format_price_with_symbol(low_24h, token)} - {await formatter.format_price_with_symbol(high_24h, token)}")
 
             # Volume
-            volume_24h = float(ticker.get('quoteVolume', 0))
-            price_text_parts.append(f"💎 <b>24h Volume:</b> {await formatter.format_price_with_symbol(volume_24h)}")
+            volume_24h = float(ticker.get('quoteVolume') or 0)
+            price_text_parts.append(f"💎 <b>24h Volume:</b> {await formatter.format_price_with_symbol(volume_24h, token)}")
 
             final_message = "\n".join(price_text_parts)
             await context.bot.edit_message_text(

+ 1 - 1
trading_bot.py

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