Add notify_status() to FreqtradeBot
This commit is contained in:
parent
27d46ed06f
commit
30e3e434ab
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user