浏览代码

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 4 天之前
父节点
当前提交
a9cde77ea0
共有 2 个文件被更改,包括 7 次插入7 次删除
  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>"]
             price_text_parts = [f"💰 <b>{token} Price Information</b>"]
 
 
             # Current price
             # 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)}")
             price_text_parts.append(f"\n📊 <b>Current Price:</b> {await formatter.format_price_with_symbol(current_price, token)}")
 
 
             # 24h change
             # 24h change
-            change_24h = float(ticker.get('percentage', 0))
+            change_24h = float(ticker.get('percentage') or 0)
             change_emoji = "🟢" if change_24h >= 0 else "🔴"
             change_emoji = "🟢" if change_24h >= 0 else "🔴"
             price_text_parts.append(f"📈 <b>24h Change:</b> {change_emoji} {change_24h:+.2f}%")
             price_text_parts.append(f"📈 <b>24h Change:</b> {change_emoji} {change_24h:+.2f}%")
 
 
             # 24h high/low
             # 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)}")
             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
-            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)
             final_message = "\n".join(price_text_parts)
             await context.bot.edit_message_text(
             await context.bot.edit_message_text(

+ 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.235"
+BOT_VERSION = "2.4.236"
 
 
 # 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"))