Merge pull request #2807 from hroff-1902/refactor-freqtrade-2

Add notify_status() to FreqtradeBot
This commit is contained in:
Matthias 2020-01-27 06:44:20 +01:00 committed by GitHub
commit 5d7317ef77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 17 deletions

View File

@ -95,6 +95,16 @@ class FreqtradeBot:
# Protect sell-logic from forcesell and viceversa
self._sell_lock = Lock()
def notify_status(self, msg: str) -> None:
"""
Public method for users of this class (worker, etc.) to send notifications
via RPC about changes in the bot status.
"""
self.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': msg
})
def cleanup(self) -> None:
"""
Cleanup pending resources on an already stopped bot

View File

@ -12,7 +12,6 @@ from freqtrade import __version__, constants
from freqtrade.configuration import Configuration
from freqtrade.exceptions import OperationalException, TemporaryError
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.rpc import RPCMessageType
from freqtrade.state import State
logger = logging.getLogger(__name__)
@ -84,10 +83,8 @@ class Worker:
# Log state transition
if state != old_state:
self.freqtrade.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': f'{state.name.lower()}'
})
self.freqtrade.notify_status(f'{state.name.lower()}')
logger.info('Changing state to: %s', state.name)
if state == State.RUNNING:
self.freqtrade.startup()
@ -136,10 +133,9 @@ class Worker:
except OperationalException:
tb = traceback.format_exc()
hint = 'Issue `/start` if you think it is safe to restart.'
self.freqtrade.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': f'OperationalException:\n```\n{tb}```{hint}'
})
self.freqtrade.notify_status(f'OperationalException:\n```\n{tb}```{hint}')
logger.exception('OperationalException. Stopping trader ...')
self.freqtrade.state = State.STOPPED
@ -159,10 +155,7 @@ class Worker:
# Load and validate config and create new instance of the bot
self._init(True)
self.freqtrade.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': 'config reloaded'
})
self.freqtrade.notify_status('config reloaded')
# Tell systemd that we completed reconfiguration
if self._sd_notify:
@ -176,8 +169,5 @@ class Worker:
self._sd_notify.notify("STOPPING=1")
if self.freqtrade:
self.freqtrade.rpc.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': 'process died'
})
self.freqtrade.notify_status('process died')
self.freqtrade.cleanup()