Forráskód Böngészése

Enhance copy trading start command with config address support

- Implemented automatic use of target trader's address from configuration if available, improving user experience.
- Added validation for the config address format to ensure correctness before proceeding.
- Updated confirmation message to include detailed information about the target trader and copy trading parameters.
- Provided fallback messaging for users without a configured address, encouraging them to set it for one-click start.
Carles Sentis 5 napja
szülő
commit
5d898ce26c
2 módosított fájl, 62 hozzáadás és 10 törlés
  1. 61 9
      src/commands/copy_trading_commands.py
  2. 1 1
      trading_bot.py

+ 61 - 9
src/commands/copy_trading_commands.py

@@ -350,15 +350,67 @@ This will:
                 await self.copy_status_command(update, context)
                 
             elif callback_data == "copy_start_prompt":
-                await query.edit_message_text(
-                    text=(
-                        "🚀 <b>Start Copy Trading</b>\n\n"
-                        "Please provide the target trader's address:\n\n"
-                        "Usage: /copy start [target_address]\n"
-                        "Example: /copy start 0x1234567890abcdef1234567890abcdef12345678"
-                    ),
-                    parse_mode='HTML'
-                )
+                # Check if we have a config address to use automatically
+                config_address = Config.COPY_TRADING_TARGET_ADDRESS
+                
+                if config_address and config_address.strip():
+                    # Auto-start with config address - show confirmation directly
+                    await query.edit_message_text("🔍 Using target address from config...")
+                    
+                    # Validate the config address format
+                    if not config_address.startswith('0x') or len(config_address) != 42:
+                        await query.edit_message_text(
+                            text="❌ Invalid address in config file. Address must start with '0x' and be 42 characters long.",
+                            parse_mode='HTML'
+                        )
+                        return
+                    
+                    # Show confirmation directly
+                    message = f"""
+🚀 <b>Start Copy Trading Confirmation</b>
+
+🎯 <b>Target Trader:</b> <code>{config_address}</code>
+📍 <b>Address Source:</b> config file
+💰 <b>Portfolio Allocation:</b> {copy_monitor.portfolio_percentage:.1%}
+📊 <b>Copy Mode:</b> {copy_monitor.copy_mode}
+⚡ <b>Max Leverage:</b> {copy_monitor.max_leverage}x
+💵 <b>Min Position Size:</b> ${copy_monitor.min_position_size}
+⏱️ <b>Execution Delay:</b> {copy_monitor.execution_delay}s
+
+⚠️ <b>Are you sure you want to start copy trading?</b>
+
+This will:
+• Monitor the target trader's positions
+• Automatically copy NEW trades (existing positions ignored)
+• Allocate {copy_monitor.portfolio_percentage:.1%} of your portfolio per trade
+• Send notifications for each copied trade
+                    """
+                    
+                    keyboard = [
+                        [
+                            InlineKeyboardButton("✅ Start Copy Trading", callback_data=f"copy_start_confirm_{config_address}"),
+                            InlineKeyboardButton("❌ Cancel", callback_data="copy_cancel")
+                        ]
+                    ]
+                    reply_markup = InlineKeyboardMarkup(keyboard)
+                    
+                    await query.edit_message_text(
+                        text=message,
+                        parse_mode='HTML',
+                        reply_markup=reply_markup
+                    )
+                else:
+                    # No config address, ask for one
+                    await query.edit_message_text(
+                        text=(
+                            "🚀 <b>Start Copy Trading</b>\n\n"
+                            "Please provide the target trader's address:\n\n"
+                            "Usage: /copy start [target_address]\n"
+                            "Example: /copy start 0x1234567890abcdef1234567890abcdef12345678\n\n"
+                            "💡 <b>Tip:</b> Set COPY_TRADING_TARGET_ADDRESS in your .env file for one-click start."
+                        ),
+                        parse_mode='HTML'
+                    )
                 
             elif callback_data.startswith("copy_start_confirm_"):
                 target_address = callback_data.replace("copy_start_confirm_", "")

+ 1 - 1
trading_bot.py

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