Procházet zdrojové kódy

Enhance market data retrieval in MarketCommands by constructing full market symbols for accurate data fetching. Added leverage information to the market information response and improved error messaging for symbol validation. This change improves the clarity and completeness of market data responses.

Carles Sentis před 4 dny
rodič
revize
83c97694aa
2 změnil soubory, kde provedl 16 přidání a 3 odebrání
  1. 15 2
      src/commands/info/market.py
  2. 1 1
      trading_bot.py

+ 15 - 2
src/commands/info/market.py

@@ -25,12 +25,19 @@ class MarketCommands(InfoCommandsBase):
             # Get token from command arguments or use default
             token = context.args[0].upper() if context.args else Config.DEFAULT_TRADING_TOKEN
             
+            # Construct the full market symbol
+            symbol = f"{token}/USDC:USDC"
+            
             # Get market data
-            market_data = await self.trading_engine.get_market_data(token)
+            market_data = await self.trading_engine.get_market_data(symbol)
             if not market_data:
-                await self._reply(update, f"❌ Could not get market data for {token}")
+                await self._reply(update, f"❌ Could not get market data for {symbol}. Check if the symbol is correct.")
                 return
             
+            # Get all markets to find leverage info
+            all_markets = self.trading_engine.client.get_markets()
+            market_info = all_markets.get(symbol) if all_markets else None
+            
             # Format the message
             message = f"📊 <b>Market Information for {token}</b>\n\n"
             
@@ -41,6 +48,12 @@ class MarketCommands(InfoCommandsBase):
             message += f"24h Low: {self.formatter.format_price_with_symbol(market_data.get('low', 0))}\n"
             message += f"24h Change: {market_data.get('change', 0):.2f}%\n"
             
+            # Add leverage information if available
+            if market_info:
+                max_leverage = market_info.get('limits', {}).get('leverage', {}).get('max', 'N/A')
+                if max_leverage != 'N/A':
+                    message += f"Leverage: Up to {max_leverage}x\n"
+            
             # Add volume information
             message += f"\n📈 <b>Volume Information:</b>\n"
             message += f"24h Volume: {self.formatter.format_amount(market_data.get('volume', 0))}\n"

+ 1 - 1
trading_bot.py

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