Prechádzať zdrojové kódy

Increment bot version to 2.6.305 and add deposit and withdrawal commands

- Updated BOT_VERSION to 2.6.305.
- Introduced /deposit and /withdrawal commands in management_commands to allow users to record deposits and withdrawals via Telegram.
- Enhanced sync_command docstring for clarity.
- Improved error handling and user feedback for deposit and withdrawal operations.
Carles Sentis 17 hodín pred
rodič
commit
d9a91de1c6
3 zmenil súbory, kde vykonal 119 pridanie a 3 odobranie
  1. 2 0
      src/bot/core.py
  2. 116 2
      src/commands/management_commands.py
  3. 1 1
      trading_bot.py

+ 2 - 0
src/bot/core.py

@@ -160,6 +160,8 @@ class TelegramTradingBot:
         self.application.add_handler(CommandHandler("version", self.management_commands.version_command))
         self.application.add_handler(CommandHandler("keyboard", self.management_commands.keyboard_command))
         self.application.add_handler(CommandHandler("sync", self.management_commands.sync_command))
+        self.application.add_handler(CommandHandler("deposit", self.management_commands.deposit_command))
+        self.application.add_handler(CommandHandler("withdrawal", self.management_commands.withdrawal_command))
         
         # Callback and message handlers
         self.application.add_handler(CallbackQueryHandler(self.trading_commands.button_callback))

+ 116 - 2
src/commands/management_commands.py

@@ -544,7 +544,7 @@ Will trigger when {token} price moves {alarm['direction']} {target_price_str}
         )
 
     async def sync_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
-        """Handle the /sync command to clear local data and resync with exchange."""
+        """Handle the /sync command to synchronize bot state with exchange."""
         chat_id = update.effective_chat.id
         if not self._is_authorized(chat_id):
             await context.bot.send_message(chat_id=chat_id, text="❌ Unauthorized access.")
@@ -800,4 +800,118 @@ Will trigger when {token} price moves {alarm['direction']} {target_price_str}
             except:
                 await context.bot.send_message(chat_id=chat_id, text=error_message, parse_mode='HTML')
             
-            logger.error(f"Error in sync command: {e}", exc_info=True) 
+            logger.error(f"Error in sync command: {e}", exc_info=True)
+
+    async def deposit_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
+        """Handle the /deposit command to record a deposit."""
+        chat_id = update.effective_chat.id
+        if not self._is_authorized(chat_id):
+            await context.bot.send_message(chat_id=chat_id, text="❌ Unauthorized access.")
+            return
+
+        try:
+            # Parse arguments
+            if not context.args or len(context.args) != 1:
+                await context.bot.send_message(
+                    chat_id=chat_id, 
+                    text="❌ Usage: /deposit <amount>\n\nExample: /deposit 500.00"
+                )
+                return
+
+            amount = float(context.args[0])
+            if amount <= 0:
+                await context.bot.send_message(chat_id=chat_id, text="❌ Deposit amount must be positive.")
+                return
+
+            # Record the deposit
+            stats = self.trading_engine.get_stats()
+            if not stats:
+                await context.bot.send_message(chat_id=chat_id, text="❌ Trading stats not available.")
+                return
+
+            await stats.record_deposit(
+                amount=amount,
+                description=f"Manual deposit via Telegram command"
+            )
+
+            # Get updated stats
+            basic_stats = stats.get_basic_stats()
+            formatter = get_formatter()
+
+            message = f"""
+✅ <b>Deposit Recorded</b>
+
+💰 <b>Deposit Amount:</b> {await formatter.format_price_with_symbol(amount)}
+📊 <b>Updated Stats:</b>
+• Effective Initial Balance: {await formatter.format_price_with_symbol(basic_stats['initial_balance'])}
+• Current P&L: {await formatter.format_price_with_symbol(basic_stats['total_pnl'])}
+• Total Return: {basic_stats['total_return_pct']:.2f}%
+
+💡 Your P&L calculations are now updated with the deposit.
+            """
+
+            await context.bot.send_message(chat_id=chat_id, text=message.strip(), parse_mode='HTML')
+            logger.info(f"Recorded deposit of ${amount:.2f} via Telegram command")
+
+        except ValueError:
+            await context.bot.send_message(chat_id=chat_id, text="❌ Invalid amount. Please enter a valid number.")
+        except Exception as e:
+            await context.bot.send_message(chat_id=chat_id, text=f"❌ Error recording deposit: {str(e)}")
+            logger.error(f"Error in deposit command: {e}")
+
+    async def withdrawal_command(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
+        """Handle the /withdrawal command to record a withdrawal."""
+        chat_id = update.effective_chat.id
+        if not self._is_authorized(chat_id):
+            await context.bot.send_message(chat_id=chat_id, text="❌ Unauthorized access.")
+            return
+
+        try:
+            # Parse arguments
+            if not context.args or len(context.args) != 1:
+                await context.bot.send_message(
+                    chat_id=chat_id, 
+                    text="❌ Usage: /withdrawal <amount>\n\nExample: /withdrawal 200.00"
+                )
+                return
+
+            amount = float(context.args[0])
+            if amount <= 0:
+                await context.bot.send_message(chat_id=chat_id, text="❌ Withdrawal amount must be positive.")
+                return
+
+            # Record the withdrawal
+            stats = self.trading_engine.get_stats()
+            if not stats:
+                await context.bot.send_message(chat_id=chat_id, text="❌ Trading stats not available.")
+                return
+
+            await stats.record_withdrawal(
+                amount=amount,
+                description=f"Manual withdrawal via Telegram command"
+            )
+
+            # Get updated stats
+            basic_stats = stats.get_basic_stats()
+            formatter = get_formatter()
+
+            message = f"""
+✅ <b>Withdrawal Recorded</b>
+
+💸 <b>Withdrawal Amount:</b> {await formatter.format_price_with_symbol(amount)}
+📊 <b>Updated Stats:</b>
+• Effective Initial Balance: {await formatter.format_price_with_symbol(basic_stats['initial_balance'])}
+• Current P&L: {await formatter.format_price_with_symbol(basic_stats['total_pnl'])}
+• Total Return: {basic_stats['total_return_pct']:.2f}%
+
+💡 Your P&L calculations are now updated with the withdrawal.
+            """
+
+            await context.bot.send_message(chat_id=chat_id, text=message.strip(), parse_mode='HTML')
+            logger.info(f"Recorded withdrawal of ${amount:.2f} via Telegram command")
+
+        except ValueError:
+            await context.bot.send_message(chat_id=chat_id, text="❌ Invalid amount. Please enter a valid number.")
+        except Exception as e:
+            await context.bot.send_message(chat_id=chat_id, text=f"❌ Error recording withdrawal: {str(e)}")
+            logger.error(f"Error in withdrawal command: {e}") 

+ 1 - 1
trading_bot.py

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