Ver Fonte

Refactor InfoCommands for improved message formatting and clarity

- Updated message construction for daily, weekly, and monthly performance reports to enhance readability by removing unnecessary escape characters.
- Improved handling of trading activity messages to provide clearer summaries.
- Added a new "Risk" command to the trading commands interface for better user access to risk-related features.
Carles Sentis há 3 dias atrás
pai
commit
9a02105274
2 ficheiros alterados com 19 adições e 18 exclusões
  1. 18 18
      src/commands/info_commands.py
  2. 1 0
      src/commands/trading_commands.py

+ 18 - 18
src/commands/info_commands.py

@@ -904,8 +904,8 @@ class InfoCommands:
             
             if not daily_stats:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "📅 <b>Daily Performance</b>\\n"
-                    "📭 No daily performance data available yet.\\n"
+                    "📅 <b>Daily Performance</b>\n"
+                    "📭 No daily performance data available yet.\n"
                     "💡 Daily stats are calculated from completed trades. Start trading to see them!",
                     parse_mode='HTML'
                 )
@@ -930,7 +930,7 @@ class InfoCommands:
                     period_lines.append(f"📊 <b>{day_stats_item['date_formatted']}</b>: 📭 No trading activity")
             
             if period_lines: # Add collected period lines if any
-                daily_text_parts.append("\\n".join(period_lines))
+                daily_text_parts.append("\n".join(period_lines))
 
             if trading_days_count > 0:
                 avg_daily_pnl = total_pnl_all_days / trading_days_count
@@ -938,15 +938,15 @@ 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_parts.append(f"\\n\\n📈 <b>Period Summary:</b>")
+                daily_text_parts.append(f"\n\n📈 <b>Period Summary:</b>")
                 daily_text_parts.append(f"  Total P&L: {avg_pnl_emoji} {total_pnl_all_days_str} | Avg Daily: {avg_daily_pnl_str}")
                 daily_text_parts.append(f"  Trading Days: {trading_days_count}/10 | Total Trades: {total_trades_all_days}")
             else:
                 if not period_lines: # If there were no stat items at all, the header is the only part
                     daily_text_parts = [daily_text_parts[0]] # Keep only the title
-                daily_text_parts.append("\\n\\n📉 No trading activity in the last 10 days.")
+                daily_text_parts.append("\n\n📉 No trading activity in the last 10 days.")
 
-            await context.bot.send_message(chat_id=chat_id, text="\\n".join(daily_text_parts).strip(), parse_mode='HTML')
+            await context.bot.send_message(chat_id=chat_id, text="\n".join(daily_text_parts).strip(), parse_mode='HTML')
                 
         except Exception as e:
             error_message = f"❌ Error processing daily command: {str(e)}"
@@ -970,8 +970,8 @@ class InfoCommands:
             
             if not weekly_stats_list:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "📊 <b>Weekly Performance</b>\\n"
-                    "📭 No weekly performance data available yet.\\n"
+                    "📊 <b>Weekly Performance</b>\n"
+                    "📭 No weekly performance data available yet.\n"
                     "💡 Weekly stats are calculated from completed trades. Start trading to see them!",
                     parse_mode='HTML'
                 )
@@ -996,7 +996,7 @@ class InfoCommands:
                     period_lines.append(f"📈 <b>{week_stats_item['week_formatted']}</b>: 📭 No trading activity")
 
             if period_lines:
-                weekly_text_parts.append("\\n".join(period_lines))
+                weekly_text_parts.append("\n".join(period_lines))
             
             if trading_weeks_count > 0:
                 avg_weekly_pnl = total_pnl_all_weeks / trading_weeks_count
@@ -1004,15 +1004,15 @@ 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_parts.append(f"\\n\\n📅 <b>Period Summary:</b>")
+                weekly_text_parts.append(f"\n\n📅 <b>Period Summary:</b>")
                 weekly_text_parts.append(f"  Total P&L: {avg_pnl_emoji} {total_pnl_all_weeks_str} | Avg Weekly: {avg_weekly_pnl_str}")
                 weekly_text_parts.append(f"  Trading Weeks: {trading_weeks_count}/10 | Total Trades: {total_trades_all_weeks}")
             else:
                 if not period_lines:
                     weekly_text_parts = [weekly_text_parts[0]]
-                weekly_text_parts.append("\\n\\n📉 No trading activity in the last 10 weeks.")
+                weekly_text_parts.append("\n\n📉 No trading activity in the last 10 weeks.")
             
-            await context.bot.send_message(chat_id=chat_id, text="\\n".join(weekly_text_parts).strip(), parse_mode='HTML')
+            await context.bot.send_message(chat_id=chat_id, text="\n".join(weekly_text_parts).strip(), parse_mode='HTML')
                 
         except Exception as e:
             error_message = f"❌ Error processing weekly command: {str(e)}"
@@ -1036,8 +1036,8 @@ class InfoCommands:
             
             if not monthly_stats_list:
                 await context.bot.send_message(chat_id=chat_id, text=
-                    "🗓️ <b>Monthly Performance</b>\\n"
-                    "📭 No monthly performance data available yet.\\n"
+                    "🗓️ <b>Monthly Performance</b>\n"
+                    "📭 No monthly performance data available yet.\n"
                     "💡 Monthly stats are calculated from completed trades. Start trading to see them!",
                     parse_mode='HTML'
                 )
@@ -1062,7 +1062,7 @@ class InfoCommands:
                     period_lines.append(f"📅 <b>{month_stats_item['month_formatted']}</b>: 📭 No trading activity")
 
             if period_lines:
-                monthly_text_parts.append("\\n".join(period_lines))
+                monthly_text_parts.append("\n".join(period_lines))
             
             if trading_months_count > 0:
                 avg_monthly_pnl = total_pnl_all_months / trading_months_count
@@ -1070,15 +1070,15 @@ 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_parts.append(f"\\n\\n📈 <b>Period Summary:</b>")
+                monthly_text_parts.append(f"\n\n📈 <b>Period Summary:</b>")
                 monthly_text_parts.append(f"  Total P&L: {avg_pnl_emoji} {total_pnl_all_months_str} | Avg Monthly: {avg_monthly_pnl_str}")
                 monthly_text_parts.append(f"  Trading Months: {trading_months_count}/12 | Total Trades: {total_trades_all_months}")
             else:
                 if not period_lines:
                     monthly_text_parts = [monthly_text_parts[0]]
-                monthly_text_parts.append("\\n\\n📉 No trading activity in the last 12 months.")
+                monthly_text_parts.append("\n\n📉 No trading activity in the last 12 months.")
             
-            await context.bot.send_message(chat_id=chat_id, text="\\n".join(monthly_text_parts).strip(), parse_mode='HTML')
+            await context.bot.send_message(chat_id=chat_id, text="\n".join(monthly_text_parts).strip(), parse_mode='HTML')
                 
         except Exception as e:
             error_message = f"❌ Error processing monthly command: {str(e)}"

+ 1 - 0
src/commands/trading_commands.py

@@ -643,6 +643,7 @@ This action cannot be undone.
                 "weekly": self.info_commands_handler.weekly_command,
                 "monthly": self.info_commands_handler.monthly_command,
                 "trades": self.info_commands_handler.trades_command,
+                "risk": self.info_commands_handler.risk_command,
                 # Note: 'help' is handled separately below as its main handler is in TelegramTradingBot core
             })