Ver código fonte

Add footer to orders and price commands for improved user guidance and information. Include last updated timestamp in price command for better context on data freshness.

Carles Sentis 4 dias atrás
pai
commit
539869a29e

+ 3 - 0
src/commands/info/orders.py

@@ -67,6 +67,9 @@ class OrdersCommands(InfoCommandsBase):
                     logger.error(f"Error processing order {order.get('symbol', 'unknown')}: {e}")
                     continue
 
+            # Add footer
+            orders_text += "💡 Use /long, /short, /sl, or /tp to create orders"
+
             await self._reply(update, orders_text.strip())
 
         except Exception as e:

+ 7 - 2
src/commands/info/price.py

@@ -4,6 +4,7 @@ from telegram.ext import ContextTypes
 from .base import InfoCommandsBase
 from src.utils.token_display_formatter import get_formatter
 from src.config.config import Config
+from datetime import datetime
 
 logger = logging.getLogger(__name__)
 
@@ -47,8 +48,9 @@ class PriceCommands(InfoCommandsBase):
             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)}")
 
-            # 24h change
-            change_24h = float(ticker.get('percentage') or 0)
+            # 24h change - calculated manually for reliability
+            prev_close = float(ticker.get('previousClose') or 0)
+            change_24h = ((current_price - prev_close) / prev_close * 100) if prev_close else 0
             change_emoji = "🟢" if change_24h >= 0 else "🔴"
             price_text_parts.append(f"📈 <b>24h Change:</b> {change_emoji} {change_24h:+.2f}%")
 
@@ -60,6 +62,9 @@ class PriceCommands(InfoCommandsBase):
             # Volume
             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)}")
+            
+            # Add footer with fetch time
+            price_text_parts.append(f"\n<i>Last updated: {datetime.now().strftime('%H:%M:%S')}</i>")
 
             final_message = "\n".join(price_text_parts)
             await context.bot.edit_message_text(

+ 7 - 6
src/commands/info/risk.py

@@ -36,10 +36,10 @@ class RiskCommands(InfoCommandsBase):
                 try:
                     # Get position details
                     symbol = position.get('symbol', '')
-                    size = float(position.get('size', 0))
-                    entry_price = float(position.get('entryPrice', 0))
-                    mark_price = float(position.get('markPrice', 0))
-                    liquidation_price = float(position.get('liquidationPrice', 0))
+                    size = float(position.get('size', 0) or 0)
+                    entry_price = float(position.get('entryPrice', 0) or 0)
+                    mark_price = float(position.get('markPrice', 0) or 0)
+                    liquidation_price = float(position.get('liquidationPrice', 0) or 0)
                     
                     if size == 0 or entry_price == 0:
                         continue
@@ -57,7 +57,7 @@ class RiskCommands(InfoCommandsBase):
                     stop_loss_orders = [o for o in orders if o.get('symbol') == symbol and o.get('type') == 'stop']
                     stop_loss_risk = 0
                     if stop_loss_orders:
-                        stop_price = float(stop_loss_orders[0].get('price', 0))
+                        stop_price = float(stop_loss_orders[0].get('price', 0) or 0)
                         if stop_price > 0:
                             stop_loss_risk = abs((stop_price - mark_price) / mark_price * 100)
                     
@@ -77,7 +77,8 @@ class RiskCommands(InfoCommandsBase):
                     continue
             
             # Get portfolio value
-            portfolio_value = float(self.trading_engine.get_portfolio_value())
+            balance_data = self.trading_engine.get_balance()
+            portfolio_value = float(balance_data.get('total', {}).get('USDC', 0) or 0) if balance_data else 0.0
             
             # Calculate portfolio risk metrics
             portfolio_risk = (total_unrealized_pnl / portfolio_value * 100) if portfolio_value > 0 else 0

+ 1 - 1
trading_bot.py

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