|
@@ -305,27 +305,41 @@ For support or issues, check the logs or contact the administrator.
|
|
|
logger.info(f"🚀 Starting Telegram trading bot v{self.version} (v20.x style)...")
|
|
|
|
|
|
await self.send_message(
|
|
|
- f"🤖 <b>Manual Trading Bot v{self.version} Started (v20.x style)</b>\\n\\n"
|
|
|
- f"✅ Connected to Hyperliquid {{'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}}\\n"
|
|
|
- f"📊 Default Symbol: {Config.DEFAULT_TRADING_TOKEN}\\n"
|
|
|
- f"🔄 All systems ready!\\n\\n"
|
|
|
+ f"🤖 <b>Manual Trading Bot v{self.version} Started (v20.x style)</b>\\\\n\\\\n"
|
|
|
+ f"✅ Connected to Hyperliquid {{'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}}\\\\n"
|
|
|
+ f"📊 Default Symbol: {Config.DEFAULT_TRADING_TOKEN}\\\\n"
|
|
|
+ f"🔄 All systems ready!\\\\n\\\\n"
|
|
|
"Use /start for quick actions or /help for all commands."
|
|
|
)
|
|
|
|
|
|
await self.market_monitor.start()
|
|
|
|
|
|
- logger.info("▶️ Starting PTB application (handlers, dispatcher, polling...) (v20.x style)...")
|
|
|
- await self.application.start()
|
|
|
-
|
|
|
- logger.info("Bot is now running. Awaiting external stop signal (e.g., Ctrl+C) (v20.x style)...")
|
|
|
- await self.application.run_polling(drop_pending_updates=Config.TELEGRAM_DROP_PENDING_UPDATES)
|
|
|
-
|
|
|
+ logger.info("▶️ Starting PTB application's internal tasks (update processing, job queue).")
|
|
|
+ await self.application.start()
|
|
|
+
|
|
|
+ if self.application.updater:
|
|
|
+ logger.info(f"▶️ Activating PTB updater to fetch updates (drop_pending_updates={Config.TELEGRAM_DROP_PENDING_UPDATES}).")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ await self.application.updater.start_polling(drop_pending_updates=Config.TELEGRAM_DROP_PENDING_UPDATES)
|
|
|
+ else:
|
|
|
+ logger.error("❌ Critical: Application updater is not initialized. Bot cannot receive Telegram updates.")
|
|
|
+
|
|
|
+
|
|
|
+ if not keep_running_future.done():
|
|
|
+ keep_running_future.set_exception(RuntimeError("Updater not available"))
|
|
|
+
|
|
|
+
|
|
|
+ logger.info("✅ Bot is initialized and updater is polling. Awaiting stop signal via keep_running_future or Ctrl+C.")
|
|
|
await keep_running_future
|
|
|
|
|
|
- except (KeyboardInterrupt, SystemExit):
|
|
|
- logger.info("🛑 Bot run interrupted by user/system. Initiating shutdown (v20.x style)...")
|
|
|
+ except (KeyboardInterrupt, SystemExit) as e:
|
|
|
+ logger.info(f"🛑 Bot run interrupted by {type(e).__name__}. Initiating shutdown (v20.x style)...")
|
|
|
if not keep_running_future.done():
|
|
|
- keep_running_future.set_exception(KeyboardInterrupt())
|
|
|
+ keep_running_future.set_exception(e if isinstance(e, SystemExit) else KeyboardInterrupt())
|
|
|
except asyncio.CancelledError:
|
|
|
logger.info("🛑 Bot run task cancelled. Initiating shutdown (v20.x style)...")
|
|
|
if not keep_running_future.done():
|
|
@@ -342,11 +356,20 @@ For support or issues, check the logs or contact the administrator.
|
|
|
logger.info("Market monitor stopped.")
|
|
|
|
|
|
if self.application:
|
|
|
- logger.info("Attempting to stop PTB application (v20.x style)...")
|
|
|
- await self.application.stop()
|
|
|
- logger.info("PTB application stop attempted.")
|
|
|
+
|
|
|
+ if self.application.updater and self.application.updater.running:
|
|
|
+ logger.info("Stopping PTB updater polling...")
|
|
|
+ await self.application.updater.stop()
|
|
|
+ logger.info("PTB updater polling stopped.")
|
|
|
+
|
|
|
+
|
|
|
+ if self.application.running:
|
|
|
+ logger.info("Stopping PTB application components (handlers, job queue)...")
|
|
|
+ await self.application.stop()
|
|
|
+ logger.info("PTB application components stopped.")
|
|
|
|
|
|
- logger.info("Shutting down PTB application (v20.x style)...")
|
|
|
+
|
|
|
+ logger.info("Shutting down PTB application (bot, persistence, etc.)...")
|
|
|
await self.application.shutdown()
|
|
|
logger.info("PTB application shut down.")
|
|
|
else:
|