feat: add dedicated standby mode allowing full remote start/stop from Telegram
This commit is contained in:
+8
-4
@@ -54,7 +54,7 @@ class TradingBot:
|
||||
10. Repeat
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, start_paused: bool = False):
|
||||
self.settings = get_settings()
|
||||
self._running = False
|
||||
self._shutdown_event = asyncio.Event()
|
||||
@@ -99,7 +99,7 @@ class TradingBot:
|
||||
self._cycle_count = 0
|
||||
self._last_news_check: Optional[datetime] = None
|
||||
self._last_regime = None
|
||||
self._trading_paused = False
|
||||
self._trading_paused = start_paused
|
||||
|
||||
def _setup_logging(self):
|
||||
"""Configure loguru logging."""
|
||||
@@ -169,9 +169,13 @@ class TradingBot:
|
||||
balance_str = f"${account['balance']:,.2f}" if account else "N/A"
|
||||
active_profile = self.settings.active_mode.capitalize()
|
||||
profile_emoji = {"Safe": "🟢", "Moderate": "🟡", "Aggressive": "🔴"}.get(active_profile, "⚪")
|
||||
|
||||
status_title = "STANDBY (Trading Off)" if self._trading_paused else "RUNNING"
|
||||
trading_state_desc = "🟡 STANDBY — Tap [▶️ Start Trading] or send /startbot from your phone to start trading" if self._trading_paused else "🟢 ACTIVE & SCANNING"
|
||||
|
||||
await self.telegram.send_bot_status(
|
||||
"RUNNING",
|
||||
f"Mode: {mode}\nBalance: {balance_str}\nSymbol: XAUUSD\nTrading Profile: {profile_emoji} {active_profile}"
|
||||
status_title,
|
||||
f"Mode: {mode}\nBalance: {balance_str}\nSymbol: XAUUSD\nTrading Profile: {profile_emoji} {active_profile}\nState: {trading_state_desc}"
|
||||
)
|
||||
|
||||
# Start interactive 2-way Telegram polling in background
|
||||
|
||||
@@ -48,7 +48,12 @@ def parse_args():
|
||||
parser.add_argument(
|
||||
"--telegram",
|
||||
action="store_true",
|
||||
help="Start interactive Telegram Command Center only",
|
||||
help="Start interactive Telegram Command Center only (in standby mode)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--standby",
|
||||
action="store_true",
|
||||
help="Start bot in standby mode (Telegram active, trading paused until started via Telegram)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--demo",
|
||||
@@ -122,34 +127,15 @@ def start_dashboard():
|
||||
|
||||
|
||||
def run_telegram():
|
||||
"""Run interactive Telegram Command Center in standalone mode with native long-polling."""
|
||||
from notifications.telegram_bot import TelegramNotifier
|
||||
from core.mt5_connector import MT5Connector
|
||||
"""Start the full Trading Bot in Standby Mode with 2-way Telegram Command Center active."""
|
||||
from core.bot import TradingBot
|
||||
|
||||
logger.info("=" * 60)
|
||||
logger.info(" Starting Telegram Command Center (Standalone Mode)")
|
||||
logger.info(" Starting XAUUSD Bot in Standby Mode (Telegram Controlled)")
|
||||
logger.info("=" * 60)
|
||||
|
||||
mt5 = MT5Connector()
|
||||
mt5.connect(max_retries=1, retry_delay=1)
|
||||
|
||||
from strategies.regime_detector import RegimeDetector
|
||||
from analysis.technical import TechnicalAnalyzer
|
||||
|
||||
class StandaloneBot:
|
||||
def __init__(self, mt5_conn):
|
||||
self.mt5 = mt5_conn
|
||||
self.regime_detector = RegimeDetector()
|
||||
self.technical = TechnicalAnalyzer()
|
||||
self._last_regime = None
|
||||
self._trading_paused = False
|
||||
|
||||
bot_wrapper = StandaloneBot(mt5)
|
||||
notifier = TelegramNotifier(bot_instance=bot_wrapper)
|
||||
try:
|
||||
notifier.run_standalone()
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Telegram Bot terminated by user")
|
||||
bot = TradingBot(start_paused=True)
|
||||
asyncio.run(bot.start())
|
||||
|
||||
|
||||
def run_backtest():
|
||||
@@ -206,7 +192,8 @@ def main():
|
||||
# Start the live trading bot
|
||||
from core.bot import TradingBot
|
||||
|
||||
bot = TradingBot()
|
||||
start_paused = getattr(args, "standby", False)
|
||||
bot = TradingBot(start_paused=start_paused)
|
||||
asyncio.run(bot.start())
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
call run.bat --standby
|
||||
pause
|
||||
@@ -1,3 +1,3 @@
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
WshShell.CurrentDirectory = "c:\Users\Mazonia\Desktop\XAUUSD-AI-Trading-Bot"
|
||||
WshShell.Run "cmd.exe /c run_bot.bat", 0, False
|
||||
WshShell.Run "cmd.exe /c run_standby.bat", 0, False
|
||||
|
||||
Reference in New Issue
Block a user