|
@@ -17,9 +17,13 @@ class MarketCommands(InfoCommandsBase):
|
|
|
|
|
|
async def market_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
|
|
"""Handle the /market command to show market information."""
|
|
|
+
|
|
|
+ # Send a loading message first
|
|
|
+ sent_message = await self._reply(update, "⏳ Fetching market data...")
|
|
|
+
|
|
|
try:
|
|
|
if not self._is_authorized(update):
|
|
|
- await self._reply(update, "❌ Unauthorized access.")
|
|
|
+ await context.bot.edit_message_text(chat_id=sent_message.chat.id, message_id=sent_message.message_id, text="❌ Unauthorized access.")
|
|
|
return
|
|
|
|
|
|
# Get token from command arguments or use default
|
|
@@ -31,7 +35,7 @@ class MarketCommands(InfoCommandsBase):
|
|
|
# Get market data
|
|
|
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 {symbol}. Check if the symbol is correct.")
|
|
|
+ await context.bot.edit_message_text(chat_id=sent_message.chat.id, message_id=sent_message.message_id, text=f"❌ Could not get market data for {symbol}. Check if the symbol is correct.")
|
|
|
return
|
|
|
|
|
|
# Get all markets to find leverage info
|
|
@@ -49,6 +53,20 @@ class MarketCommands(InfoCommandsBase):
|
|
|
last_price = ticker.get('last', 0)
|
|
|
prev_close = ticker.get('previousClose', 0)
|
|
|
change_24h = ((last_price - prev_close) / prev_close * 100) if prev_close else 0
|
|
|
+
|
|
|
+ # Calculate price position within the daily range
|
|
|
+ high_price = ticker.get('high', 0) or 0
|
|
|
+ low_price = ticker.get('low', 0) or 0
|
|
|
+
|
|
|
+ percent_from_low_str = ""
|
|
|
+ percent_from_high_str = ""
|
|
|
+ if high_price > low_price and low_price > 0 and last_price > 0:
|
|
|
+ total_range = high_price - low_price
|
|
|
+ dist_from_low = last_price - low_price
|
|
|
+ percent_from_low = (dist_from_low / total_range) * 100
|
|
|
+ percent_from_high = 100 - percent_from_low
|
|
|
+ percent_from_low_str = f" ({percent_from_low:.0f}% above)"
|
|
|
+ percent_from_high_str = f" ({percent_from_high:.0f}% below)"
|
|
|
|
|
|
# Format the message
|
|
|
message = f"📊 <b>Market Information for {token}</b>\n\n"
|
|
@@ -56,8 +74,8 @@ class MarketCommands(InfoCommandsBase):
|
|
|
# Add price information
|
|
|
message += "💰 <b>Price Information:</b>\n"
|
|
|
message += f"Last Price: {self.formatter.format_price_with_symbol(last_price)}\n"
|
|
|
- message += f"24h High: {self.formatter.format_price_with_symbol(ticker.get('high', 0) or 0)}\n"
|
|
|
- message += f"24h Low: {self.formatter.format_price_with_symbol(ticker.get('low', 0) or 0)}\n"
|
|
|
+ message += f"24h High: {self.formatter.format_price_with_symbol(high_price)}{percent_from_high_str}\n"
|
|
|
+ message += f"24h Low: {self.formatter.format_price_with_symbol(low_price)}{percent_from_low_str}\n"
|
|
|
message += f"24h Change: {change_24h:.2f}%\n"
|
|
|
|
|
|
# Add leverage information if available
|
|
@@ -81,8 +99,8 @@ class MarketCommands(InfoCommandsBase):
|
|
|
message += f"Ask: {self.formatter.format_price_with_symbol(ask)}\n"
|
|
|
message += f"Spread: {self.formatter.format_price_with_symbol(spread)}\n"
|
|
|
|
|
|
- await self._reply(update, message.strip())
|
|
|
+ await context.bot.edit_message_text(chat_id=sent_message.chat.id, message_id=sent_message.message_id, text=message.strip(), parse_mode='HTML')
|
|
|
|
|
|
except Exception as e:
|
|
|
logger.error(f"Error in market command: {e}")
|
|
|
- await self._reply(update, "❌ Error getting market information. Please try again later.")
|
|
|
+ await context.bot.edit_message_text(chat_id=sent_message.chat.id, message_id=sent_message.message_id, text="❌ Error getting market information. Please try again later.")
|