|
@@ -15,10 +15,13 @@ logger = logging.getLogger(__name__)
|
|
|
class TradingCommands:
|
|
|
"""Handles all trading-related Telegram commands."""
|
|
|
|
|
|
- def __init__(self, trading_engine, notification_manager):
|
|
|
- """Initialize with trading engine and notification manager."""
|
|
|
+ def __init__(self, trading_engine, notification_manager, info_commands_instance, management_commands_instance, telegram_bot_instance):
|
|
|
+ """Initialize with trading engine, notification manager, and other command instances."""
|
|
|
self.trading_engine = trading_engine
|
|
|
self.notification_manager = notification_manager
|
|
|
+ self.info_commands_instance = info_commands_instance
|
|
|
+ self.management_commands_instance = management_commands_instance
|
|
|
+ self.telegram_bot_instance = telegram_bot_instance
|
|
|
|
|
|
def _is_authorized(self, chat_id: str) -> bool:
|
|
|
"""Check if the chat ID is authorized."""
|
|
@@ -472,7 +475,7 @@ This will place a limit {exit_side} order at ${stop_price:,.2f} to protect your
|
|
|
elif position_type == "SHORT" and tp_price >= entry_price:
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Take profit price should be BELOW entry price for short positions\n\n"
|
|
|
- f"�� Your {token} SHORT position:\n"
|
|
|
+ f"📊 Your {token} SHORT position:\n"
|
|
|
f"• Entry Price: ${entry_price:,.2f}\n"
|
|
|
f"• Take Profit: ${tp_price:,.2f} ❌\n\n"
|
|
|
f"💡 Try a lower price like: /tp {token} {entry_price * 0.95:.0f}"
|
|
@@ -589,6 +592,41 @@ This action cannot be undone.
|
|
|
|
|
|
callback_data = query.data
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ command_map = {
|
|
|
+ "balance": self.info_commands_instance.balance_command,
|
|
|
+ "positions": self.info_commands_instance.positions_command,
|
|
|
+ "orders": self.info_commands_instance.orders_command,
|
|
|
+ "stats": self.info_commands_instance.stats_command,
|
|
|
+ "trades": self.info_commands_instance.trades_command,
|
|
|
+ "market": self.info_commands_instance.market_command,
|
|
|
+ "price": self.info_commands_instance.price_command,
|
|
|
+ "performance": self.info_commands_instance.performance_command,
|
|
|
+ "daily": self.info_commands_instance.daily_command,
|
|
|
+ "weekly": self.info_commands_instance.weekly_command,
|
|
|
+ "monthly": self.info_commands_instance.monthly_command,
|
|
|
+ "risk": self.info_commands_instance.risk_command,
|
|
|
+ "balance_adjustments": self.info_commands_instance.balance_adjustments_command,
|
|
|
+ "commands": self.info_commands_instance.commands_command,
|
|
|
+
|
|
|
+ "monitoring": self.management_commands_instance.monitoring_command,
|
|
|
+ "alarm": self.management_commands_instance.alarm_command,
|
|
|
+ "logs": self.management_commands_instance.logs_command,
|
|
|
+ "debug": self.management_commands_instance.debug_command,
|
|
|
+ "version": self.management_commands_instance.version_command,
|
|
|
+ "keyboard": self.management_commands_instance.keyboard_command,
|
|
|
+
|
|
|
+ "help": self.telegram_bot_instance.help_command
|
|
|
+ }
|
|
|
+
|
|
|
try:
|
|
|
if callback_data.startswith('confirm_long_'):
|
|
|
await self._execute_long_callback(query, callback_data)
|
|
@@ -605,11 +643,63 @@ This action cannot be undone.
|
|
|
elif callback_data == 'cancel_order':
|
|
|
await query.edit_message_text("❌ Order cancelled.")
|
|
|
|
|
|
-
|
|
|
- elif callback_data in ['balance', 'positions', 'orders', 'stats', 'trades', 'market', 'price',
|
|
|
- 'performance', 'daily', 'weekly', 'monthly', 'alarm', 'monitoring', 'logs', 'help']:
|
|
|
- await query.edit_message_text(f"✅ Please use /{callback_data} command to get the latest data.")
|
|
|
-
|
|
|
+
|
|
|
+ elif callback_data in command_map:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ button_text = query.message.reply_markup.inline_keyboard[0][0].text
|
|
|
+ for row in query.message.reply_markup.inline_keyboard:
|
|
|
+ for button in row:
|
|
|
+ if button.callback_data == callback_data:
|
|
|
+ button_text = button.text
|
|
|
+ break
|
|
|
+ if button_text != query.message.reply_markup.inline_keyboard[0][0].text:
|
|
|
+ break
|
|
|
+
|
|
|
+ await query.edit_message_text(f"⏳ Processing '{button_text}'...")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ current_context_args = context.args
|
|
|
+ context.args = []
|
|
|
+
|
|
|
+ command_handler_update = Update(
|
|
|
+ update_id=query.update_id,
|
|
|
+ message=query.message
|
|
|
+
|
|
|
+ )
|
|
|
+
|
|
|
+ if command_handler_update.message:
|
|
|
+ command_handler_update.effective_chat = command_handler_update.message.chat
|
|
|
+
|
|
|
+
|
|
|
+ await command_map[callback_data](command_handler_update, context)
|
|
|
+
|
|
|
+ context.args = current_context_args
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ else:
|
|
|
+ logger.warning(f"Unhandled callback_data: {callback_data}")
|
|
|
+ await query.edit_message_text(f"❓ Unknown action: {callback_data}. Please try again or use a command.")
|
|
|
+
|
|
|
except Exception as e:
|
|
|
await query.edit_message_text(f"❌ Error processing order: {e}")
|
|
|
logger.error(f"Error in button callback: {e}")
|