|
@@ -655,30 +655,35 @@ The order has been submitted to Hyperliquid.
|
|
|
logger.error("❌ TELEGRAM_CHAT_ID not configured")
|
|
|
return
|
|
|
|
|
|
-
|
|
|
- self.application = Application.builder().token(Config.TELEGRAM_BOT_TOKEN).build()
|
|
|
-
|
|
|
-
|
|
|
- self.setup_handlers()
|
|
|
-
|
|
|
- logger.info("🚀 Starting Telegram trading bot...")
|
|
|
-
|
|
|
-
|
|
|
- await self.send_message(
|
|
|
- "🤖 <b>Manual Trading Bot Started</b>\n\n"
|
|
|
- f"✅ Connected to Hyperliquid {'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}\n"
|
|
|
- f"📊 Default Symbol: {Config.DEFAULT_TRADING_SYMBOL}\n"
|
|
|
- f"📱 Manual trading ready!\n"
|
|
|
- f"⏰ Started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
|
|
|
- "Use /start for quick actions or /help for all commands."
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- await self.application.run_polling()
|
|
|
+ try:
|
|
|
+
|
|
|
+ self.application = Application.builder().token(Config.TELEGRAM_BOT_TOKEN).build()
|
|
|
+
|
|
|
+
|
|
|
+ self.setup_handlers()
|
|
|
+
|
|
|
+ logger.info("🚀 Starting Telegram trading bot...")
|
|
|
+
|
|
|
+
|
|
|
+ await self.send_message(
|
|
|
+ "🤖 <b>Manual Trading Bot Started</b>\n\n"
|
|
|
+ f"✅ Connected to Hyperliquid {'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}\n"
|
|
|
+ f"📊 Default Symbol: {Config.DEFAULT_TRADING_SYMBOL}\n"
|
|
|
+ f"📱 Manual trading ready!\n"
|
|
|
+ f"⏰ Started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
|
|
|
+ "Use /start for quick actions or /help for all commands."
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+ await self.application.run_polling()
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"❌ Error in telegram bot: {e}")
|
|
|
+ raise
|
|
|
|
|
|
|
|
|
-def main():
|
|
|
- """Main entry point for the Telegram bot."""
|
|
|
+async def main_async():
|
|
|
+ """Async main entry point for the Telegram bot."""
|
|
|
try:
|
|
|
|
|
|
if not Config.validate():
|
|
@@ -691,12 +696,34 @@ def main():
|
|
|
|
|
|
|
|
|
bot = TelegramTradingBot()
|
|
|
- asyncio.run(bot.run())
|
|
|
+ await bot.run()
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
logger.info("👋 Bot stopped by user")
|
|
|
except Exception as e:
|
|
|
logger.error(f"❌ Unexpected error: {e}")
|
|
|
+ raise
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+ """Main entry point for the Telegram bot."""
|
|
|
+ try:
|
|
|
+
|
|
|
+ try:
|
|
|
+ loop = asyncio.get_running_loop()
|
|
|
+
|
|
|
+ logger.error("❌ Cannot run main() from within an asyncio context. Use main_async() instead.")
|
|
|
+ return
|
|
|
+ except RuntimeError:
|
|
|
+
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+ asyncio.run(main_async())
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(f"❌ Failed to start telegram bot: {e}")
|
|
|
+ raise
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|