Add I Am Alive Message

This commit is contained in:
Matthias 2019-10-25 15:00:16 +02:00
parent 8201f70a80
commit 0773a65333
4 changed files with 36 additions and 1 deletions

View File

@ -119,7 +119,8 @@
"initial_state": "running",
"forcebuy_enable": false,
"internals": {
"process_throttle_secs": 5
"process_throttle_secs": 5,
"keep_alive_interval": 60
},
"strategy": "DefaultStrategy",
"strategy_path": "user_data/strategies/"

View File

@ -98,6 +98,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `strategy` | DefaultStrategy | Defines Strategy class to use.
| `strategy_path` | null | Adds an additional strategy lookup path (must be a directory).
| `internals.process_throttle_secs` | 5 | **Required.** Set the process throttle. Value in second.
| `internals.keep_alive_interval` | 60 | Print keepalive message every X seconds. Set to 0 to disable keepalive messages.
| `internals.sd_notify` | false | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details.
| `logfile` | | Specify Logfile. Uses a rolling strategy of 10 files, with 1Mb per file.
| `user_data_dir` | cwd()/user_data | Directory containing user data. Defaults to `./user_data/`.

View File

@ -50,6 +50,10 @@ class FreqtradeBot:
# Init objects
self.config = config
self._last_alive_msg = 0
self.keep_alive_interval = self.config.get('internals', {}).get('keep_alive_interval', 60)
self.strategy: IStrategy = StrategyResolver(self.config).strategy
# Check config consistency here since strategies can set certain options
@ -150,6 +154,11 @@ class FreqtradeBot:
self.check_handle_timedout()
Trade.session.flush()
if (self.keep_alive_interval
and (arrow.utcnow().timestamp - self._last_alive_msg > self.keep_alive_interval)):
logger.info("I am alive.")
self._last_alive_msg = arrow.utcnow().timestamp
def _extend_whitelist_with_trades(self, whitelist: List[str], trades: List[Any]):
"""
Extend whitelist with pairs from open trades

View File

@ -3648,3 +3648,27 @@ def test_startup_trade_reinit(default_conf, edge_conf, mocker):
ftbot = get_patched_freqtradebot(mocker, edge_conf)
ftbot.startup()
assert reinit_mock.call_count == 0
def test_process_i_am_alive(default_conf, mocker, caplog):
patch_RPCManager(mocker)
patch_exchange(mocker)
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
ftbot = get_patched_freqtradebot(mocker, default_conf)
message = "I am alive."
ftbot.process()
assert log_has(message, caplog)
assert ftbot._last_alive_msg != 0
caplog.clear()
# Message is not shown before interval is up
ftbot.process()
assert not log_has(message, caplog)
caplog.clear()
# Set clock - 70 seconds
ftbot._last_alive_msg -= 70
ftbot.process()
assert log_has(message, caplog)