|
@@ -3,6 +3,7 @@ from telegram import Update
|
|
from telegram.ext import ContextTypes
|
|
from telegram.ext import ContextTypes
|
|
from .base import InfoCommandsBase
|
|
from .base import InfoCommandsBase
|
|
from src.utils.token_display_formatter import get_formatter
|
|
from src.utils.token_display_formatter import get_formatter
|
|
|
|
+from src.config.config import Config
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@@ -14,18 +15,26 @@ class PriceCommands(InfoCommandsBase):
|
|
if not self._is_authorized(update):
|
|
if not self._is_authorized(update):
|
|
return
|
|
return
|
|
|
|
|
|
- try:
|
|
|
|
- # Check if a specific token was requested
|
|
|
|
- args = context.args
|
|
|
|
- if not args:
|
|
|
|
- await self._reply(update, "❌ Please specify a token. Example: /price BTC")
|
|
|
|
- return
|
|
|
|
|
|
+ # Determine token first to use in the loading message
|
|
|
|
+ token = context.args[0].upper() if context.args else Config.DEFAULT_TRADING_TOKEN
|
|
|
|
|
|
- token = args[0].upper()
|
|
|
|
- market_data = self.trading_engine.get_market_data(token)
|
|
|
|
|
|
+ # Send a loading message first
|
|
|
|
+ sent_message = await self._reply(update, f"⏳ Fetching price for {token}...")
|
|
|
|
+ if not sent_message:
|
|
|
|
+ logger.error("Failed to send initial message in price_command.")
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ # Construct the full market symbol
|
|
|
|
+ symbol = f"{token}/USDC:USDC"
|
|
|
|
+ market_data = await self.trading_engine.get_market_data(symbol)
|
|
|
|
|
|
if not market_data or not market_data.get('ticker'):
|
|
if not market_data or not market_data.get('ticker'):
|
|
- await self._reply(update, f"❌ Could not fetch price data for {token}")
|
|
|
|
|
|
+ await context.bot.edit_message_text(
|
|
|
|
+ chat_id=sent_message.chat.id,
|
|
|
|
+ message_id=sent_message.message_id,
|
|
|
|
+ text=f"❌ Could not fetch price data for {symbol}"
|
|
|
|
+ )
|
|
return
|
|
return
|
|
|
|
|
|
ticker = market_data['ticker']
|
|
ticker = market_data['ticker']
|
|
@@ -52,9 +61,20 @@ class PriceCommands(InfoCommandsBase):
|
|
volume_24h = float(ticker.get('quoteVolume', 0))
|
|
volume_24h = float(ticker.get('quoteVolume', 0))
|
|
price_text_parts.append(f"💎 <b>24h Volume:</b> {await formatter.format_price_with_symbol(volume_24h)}")
|
|
price_text_parts.append(f"💎 <b>24h Volume:</b> {await formatter.format_price_with_symbol(volume_24h)}")
|
|
|
|
|
|
- await self._reply(update, "\n".join(price_text_parts))
|
|
|
|
|
|
+ final_message = "\n".join(price_text_parts)
|
|
|
|
+ await context.bot.edit_message_text(
|
|
|
|
+ chat_id=sent_message.chat.id,
|
|
|
|
+ message_id=sent_message.message_id,
|
|
|
|
+ text=final_message,
|
|
|
|
+ parse_mode='HTML'
|
|
|
|
+ )
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
error_message = f"❌ Error processing price command: {str(e)}"
|
|
error_message = f"❌ Error processing price command: {str(e)}"
|
|
- await self._reply(update, error_message)
|
|
|
|
- logger.error(f"Error in price command: {e}")
|
|
|
|
|
|
+ logger.error(f"Error in price command: {e}", exc_info=True)
|
|
|
|
+ if sent_message:
|
|
|
|
+ await context.bot.edit_message_text(
|
|
|
|
+ chat_id=sent_message.chat.id,
|
|
|
|
+ message_id=sent_message.message_id,
|
|
|
|
+ text=error_message
|
|
|
|
+ )
|