|
@@ -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}")
|