Selaa lähdekoodia

Refactor price data handling in InfoCommands - Updated the retrieval of market data prices to handle None values gracefully, ensuring robust float conversion. This improves the reliability of price calculations and enhances overall data integrity in the bot's operations.

Carles Sentis 4 päivää sitten
vanhempi
sitoutus
cd95517fcf
1 muutettua tiedostoa jossa 16 lisäystä ja 11 poistoa
  1. 16 11
      src/commands/info_commands.py

+ 16 - 11
src/commands/info_commands.py

@@ -292,14 +292,17 @@ class InfoCommands:
         if market_data:
             ticker = market_data.get('ticker', {})
             
-            current_price = float(ticker.get('last', 0))
-            bid_price = float(ticker.get('bid', 0))
-            ask_price = float(ticker.get('ask', 0))
-            volume_24h = float(ticker.get('baseVolume', 0))
-            change_24h = float(ticker.get('change', 0))
-            change_percent = float(ticker.get('percentage', 0))
-            high_24h = float(ticker.get('high', 0))
-            low_24h = float(ticker.get('low', 0))
+            current_price = float(ticker.get('last', 0.0) or 0.0)
+            bid_price = float(ticker.get('bid', 0.0) or 0.0)
+            ask_price = float(ticker.get('ask', 0.0) or 0.0)
+            raw_base_volume = ticker.get('baseVolume')
+            volume_24h = float(raw_base_volume if raw_base_volume is not None else 0.0)
+            raw_change_24h = ticker.get('change')
+            change_24h = float(raw_change_24h if raw_change_24h is not None else 0.0)
+            raw_percentage = ticker.get('percentage')
+            change_percent = float(raw_percentage if raw_percentage is not None else 0.0)
+            high_24h = float(ticker.get('high', 0.0) or 0.0)
+            low_24h = float(ticker.get('low', 0.0) or 0.0)
             
             # Market direction emoji
             trend_emoji = "🟢" if change_24h >= 0 else "🔴"
@@ -344,9 +347,11 @@ class InfoCommands:
         
         if market_data:
             ticker = market_data.get('ticker', {})
-            current_price = float(ticker.get('last', 0))
-            change_24h = float(ticker.get('change', 0))
-            change_percent = float(ticker.get('percentage', 0))
+            current_price = float(ticker.get('last', 0.0) or 0.0)
+            raw_change_24h = ticker.get('change')
+            change_24h = float(raw_change_24h if raw_change_24h is not None else 0.0)
+            raw_percentage = ticker.get('percentage')
+            change_percent = float(raw_percentage if raw_percentage is not None else 0.0)
             
             # Price direction emoji
             trend_emoji = "🟢" if change_24h >= 0 else "🔴"