Переглянути джерело

Refactor InfoCommands to streamline message formatting and enhance user interaction

- Removed inline keyboard for quick actions in balance reporting to simplify the response.
- Updated message formatting for daily, weekly, and monthly performance reports to improve readability by eliminating unnecessary escape characters.
- Added a new button for "Risk" in the command interface to enhance user access to risk-related features.
Carles Sentis 3 днів тому
батько
коміт
9871f27afe
1 змінених файлів з 44 додано та 51 видалено
  1. 44 51
      src/commands/info_commands.py

+ 44 - 51
src/commands/info_commands.py

@@ -125,15 +125,7 @@ class InfoCommands:
                 
                 final_message = "\n".join(balance_text_parts)
                 
-                # Quick Actions Keyboard (same as before)
-                quick_actions = [
-                    [InlineKeyboardButton("Positions (/p)", callback_data="/positions"), InlineKeyboardButton("Orders (/o)", callback_data="/orders")],
-                    [InlineKeyboardButton("Trades (/tr)", callback_data="/trades"), InlineKeyboardButton("Stats (/st)", callback_data="/stats")],
-                    [InlineKeyboardButton("Performance (/pf)", callback_data="/performance"), InlineKeyboardButton("Commands (/c)", callback_data="/commands")]
-                ]
-                quick_action_markup = InlineKeyboardMarkup(quick_actions)
-
-                await reply_method(text=final_message.strip(), parse_mode='HTML', reply_markup=quick_action_markup)
+                await reply_method(text=final_message.strip(), parse_mode='HTML')
             else:
                 await reply_method(text="❌ Could not fetch balance information", parse_mode='HTML')
         except Exception as e:
@@ -912,15 +904,15 @@ class InfoCommands:
             
             if not daily_stats:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "📅 <b>Daily Performance</b>\\n\\n"
-                    "📭 No daily performance data available yet.\\n\\n"
-                    "💡 Daily stats are calculated from completed trades.\\n"
+                    "📅 <b>Daily Performance</b>\n\n"
+                    "📭 No daily performance data available yet.\n\n"
+                    "💡 Daily stats are calculated from completed trades.\n"
                     "Start trading to see daily performance!",
                     parse_mode='HTML'
                 )
                 return
             
-            daily_text = "📅 <b>Daily Performance (Last 10 Days)</b>\\n\\n"
+            daily_text = "📅 <b>Daily Performance (Last 10 Days)</b>\n\n"
             
             total_pnl_all_days = 0 # Renamed to avoid conflict
             total_trades_all_days = 0 # Renamed
@@ -930,16 +922,16 @@ class InfoCommands:
                 if day_stats_item['has_trades']:
                     pnl_emoji = "🟢" if day_stats_item['pnl'] >= 0 else "🔴"
                     pnl_str = formatter.format_price_with_symbol(day_stats_item['pnl'])
-                    daily_text += f"📊 <b>{day_stats_item['date_formatted']}</b>\\n"
-                    daily_text += f"   {pnl_emoji} P&L: {pnl_str} ({day_stats_item['pnl_pct']:+.1f}%)\\n"
-                    daily_text += f"   🔄 Trades: {day_stats_item['trades']}\\n\\n"
+                    daily_text += f"📊 <b>{day_stats_item['date_formatted']}</b>\n"
+                    daily_text += f"   {pnl_emoji} P&L: {pnl_str} ({day_stats_item['pnl_pct']:+.1f}%)\n"
+                    daily_text += f"   🔄 Trades: {day_stats_item['trades']}\n\n"
                     
                     total_pnl_all_days += day_stats_item['pnl']
                     total_trades_all_days += day_stats_item['trades']
                     trading_days_count += 1
                 else:
-                    daily_text += f"📊 <b>{day_stats_item['date_formatted']}</b>\\n"
-                    daily_text += f"   📭 No trading activity\\n\\n"
+                    daily_text += f"📊 <b>{day_stats_item['date_formatted']}</b>\n"
+                    daily_text += f"   📭 No trading activity\n\n"
             
             if trading_days_count > 0:
                 avg_daily_pnl = total_pnl_all_days / trading_days_count
@@ -947,11 +939,11 @@ class InfoCommands:
                 total_pnl_all_days_str = formatter.format_price_with_symbol(total_pnl_all_days)
                 avg_daily_pnl_str = formatter.format_price_with_symbol(avg_daily_pnl)
                 
-                daily_text += f"📈 <b>Period Summary:</b>\\n"
-                daily_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_days_str}\\n"
-                daily_text += f"   📊 Trading Days: {trading_days_count}/10\\n"
-                daily_text += f"   📅 Avg Daily P&L: {avg_daily_pnl_str}\\n"
-                daily_text += f"   🔄 Total Trades: {total_trades_all_days}\\n"
+                daily_text += f"📈 <b>Period Summary:</b>\n"
+                daily_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_days_str}\n"
+                daily_text += f"   📊 Trading Days: {trading_days_count}/10\n"
+                daily_text += f"   📅 Avg Daily P&L: {avg_daily_pnl_str}\n"
+                daily_text += f"   🔄 Total Trades: {total_trades_all_days}\n"
             
             await context.bot.send_message(chat_id=chat_id, text=daily_text.strip(), parse_mode='HTML')
                 
@@ -977,15 +969,15 @@ class InfoCommands:
             
             if not weekly_stats_list:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "📊 <b>Weekly Performance</b>\\n\\n"
-                    "📭 No weekly performance data available yet.\\n\\n"
-                    "💡 Weekly stats are calculated from completed trades.\\n"
+                    "📊 <b>Weekly Performance</b>\n\n"
+                    "📭 No weekly performance data available yet.\n\n"
+                    "💡 Weekly stats are calculated from completed trades.\n"
                     "Start trading to see weekly performance!",
                     parse_mode='HTML'
                 )
                 return
             
-            weekly_text = "📊 <b>Weekly Performance (Last 10 Weeks)</b>\\n\\n"
+            weekly_text = "📊 <b>Weekly Performance (Last 10 Weeks)</b>\n\n"
             
             total_pnl_all_weeks = 0 # Renamed
             total_trades_all_weeks = 0 # Renamed
@@ -995,16 +987,16 @@ class InfoCommands:
                 if week_stats_item['has_trades']:
                     pnl_emoji = "🟢" if week_stats_item['pnl'] >= 0 else "🔴"
                     pnl_str = formatter.format_price_with_symbol(week_stats_item['pnl'])
-                    weekly_text += f"📈 <b>{week_stats_item['week_formatted']}</b>\\n"
-                    weekly_text += f"   {pnl_emoji} P&L: {pnl_str} ({week_stats_item['pnl_pct']:+.1f}%)\\n"
-                    weekly_text += f"   🔄 Trades: {week_stats_item['trades']}\\n\\n"
+                    weekly_text += f"📈 <b>{week_stats_item['week_formatted']}</b>\n"
+                    weekly_text += f"   {pnl_emoji} P&L: {pnl_str} ({week_stats_item['pnl_pct']:+.1f}%)\n"
+                    weekly_text += f"   🔄 Trades: {week_stats_item['trades']}\n\n"
                     
                     total_pnl_all_weeks += week_stats_item['pnl']
                     total_trades_all_weeks += week_stats_item['trades']
                     trading_weeks_count += 1
                 else:
-                    weekly_text += f"📈 <b>{week_stats_item['week_formatted']}</b>\\n"
-                    weekly_text += f"   📭 No trading activity\\n\\n"
+                    weekly_text += f"📈 <b>{week_stats_item['week_formatted']}</b>\n"
+                    weekly_text += f"   📭 No trading activity\n\n"
             
             if trading_weeks_count > 0:
                 avg_weekly_pnl = total_pnl_all_weeks / trading_weeks_count
@@ -1012,11 +1004,11 @@ class InfoCommands:
                 total_pnl_all_weeks_str = formatter.format_price_with_symbol(total_pnl_all_weeks)
                 avg_weekly_pnl_str = formatter.format_price_with_symbol(avg_weekly_pnl)
 
-                weekly_text += f"📅 <b>Period Summary:</b>\\n"
-                weekly_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_weeks_str}\\n"
-                weekly_text += f"   📊 Trading Weeks: {trading_weeks_count}/10\\n"
-                weekly_text += f"   📅 Avg Weekly P&L: {avg_weekly_pnl_str}\\n"
-                weekly_text += f"   🔄 Total Trades: {total_trades_all_weeks}\\n"
+                weekly_text += f"📅 <b>Period Summary:</b>\n"
+                weekly_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_weeks_str}\n"
+                weekly_text += f"   📊 Trading Weeks: {trading_weeks_count}/10\n"
+                weekly_text += f"   📅 Avg Weekly P&L: {avg_weekly_pnl_str}\n"
+                weekly_text += f"   🔄 Total Trades: {total_trades_all_weeks}\n"
             
             await context.bot.send_message(chat_id=chat_id, text=weekly_text.strip(), parse_mode='HTML')
                 
@@ -1042,15 +1034,15 @@ class InfoCommands:
             
             if not monthly_stats_list:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "🗓️ <b>Monthly Performance</b>\\n\\n"
-                    "📭 No monthly performance data available yet.\\n\\n"
-                    "💡 Monthly stats are calculated from completed trades.\\n"
+                    "🗓️ <b>Monthly Performance</b>\n\n"
+                    "📭 No monthly performance data available yet.\n\n"
+                    "💡 Monthly stats are calculated from completed trades.\n"
                     "Start trading to see monthly performance!",
                     parse_mode='HTML'
                 )
                 return
             
-            monthly_text = "🗓️ <b>Monthly Performance (Last 12 Months)</b>\\n\\n"
+            monthly_text = "🗓️ <b>Monthly Performance (Last 12 Months)</b>\n\n"
             
             total_pnl_all_months = 0 # Renamed
             total_trades_all_months = 0 # Renamed
@@ -1060,16 +1052,16 @@ class InfoCommands:
                 if month_stats_item['has_trades']:
                     pnl_emoji = "🟢" if month_stats_item['pnl'] >= 0 else "🔴"
                     pnl_str = formatter.format_price_with_symbol(month_stats_item['pnl'])
-                    monthly_text += f"📅 <b>{month_stats_item['month_formatted']}</b>\\n"
-                    monthly_text += f"   {pnl_emoji} P&L: {pnl_str} ({month_stats_item['pnl_pct']:+.1f}%)\\n"
-                    monthly_text += f"   🔄 Trades: {month_stats_item['trades']}\\n\\n"
+                    monthly_text += f"📅 <b>{month_stats_item['month_formatted']}</b>\n"
+                    monthly_text += f"   {pnl_emoji} P&L: {pnl_str} ({month_stats_item['pnl_pct']:+.1f}%)\n"
+                    monthly_text += f"   🔄 Trades: {month_stats_item['trades']}\n\n"
                     
                     total_pnl_all_months += month_stats_item['pnl']
                     total_trades_all_months += month_stats_item['trades']
                     trading_months_count += 1
                 else:
-                    monthly_text += f"📅 <b>{month_stats_item['month_formatted']}</b>\\n"
-                    monthly_text += f"   📭 No trading activity\\n\\n"
+                    monthly_text += f"📅 <b>{month_stats_item['month_formatted']}</b>\n"
+                    monthly_text += f"   📭 No trading activity\n\n"
             
             if trading_months_count > 0:
                 avg_monthly_pnl = total_pnl_all_months / trading_months_count
@@ -1077,11 +1069,11 @@ class InfoCommands:
                 total_pnl_all_months_str = formatter.format_price_with_symbol(total_pnl_all_months)
                 avg_monthly_pnl_str = formatter.format_price_with_symbol(avg_monthly_pnl)
                 
-                monthly_text += f"📈 <b>Period Summary:</b>\\n"
-                monthly_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_months_str}\\n"
-                monthly_text += f"   📊 Trading Months: {trading_months_count}/12\\n"
-                monthly_text += f"   🗓️ Avg Monthly P&L: {avg_monthly_pnl_str}\\n"
-                monthly_text += f"   🔄 Total Trades: {total_trades_all_months}\\n"
+                monthly_text += f"📈 <b>Period Summary:</b>\n"
+                monthly_text += f"   {avg_pnl_emoji} Total P&L: {total_pnl_all_months_str}\n"
+                monthly_text += f"   📊 Trading Months: {trading_months_count}/12\n"
+                monthly_text += f"   🗓️ Avg Monthly P&L: {avg_monthly_pnl_str}\n"
+                monthly_text += f"   🔄 Total Trades: {total_trades_all_months}\n"
             
             await context.bot.send_message(chat_id=chat_id, text=monthly_text.strip(), parse_mode='HTML')
                 
@@ -1333,6 +1325,7 @@ Tap any button below for instant access to bot functions:
                 InlineKeyboardButton("📝 Logs", callback_data="/logs")
             ],
             [
+                InlineKeyboardButton("🎲 Risk", callback_data="/risk"),
                 InlineKeyboardButton("⚙️ Help", callback_data="/help")
             ]
         ]