diff --git a/freqtrade/commands/trade_commands.py b/freqtrade/commands/trade_commands.py index 535844844..0707cc803 100644 --- a/freqtrade/commands/trade_commands.py +++ b/freqtrade/commands/trade_commands.py @@ -1,4 +1,5 @@ import logging +import signal from typing import Any, Dict @@ -12,15 +13,20 @@ def start_trading(args: Dict[str, Any]) -> int: # Import here to avoid loading worker module when it's not used from freqtrade.worker import Worker + def term_handler(signum, frame): + # Raise KeyboardInterrupt - so we can handle it in the same way as Ctrl-C + raise KeyboardInterrupt() + # Create and run worker worker = None try: + signal.signal(signal.SIGTERM, term_handler) worker = Worker(args) worker.run() except Exception as e: logger.error(str(e)) logger.exception("Fatal exception!") - except KeyboardInterrupt: + except (KeyboardInterrupt): logger.info('SIGINT received, aborting ...') finally: if worker: