Add bot start and bot-startup to health endpoint

This commit is contained in:
Matthias
2024-03-09 15:01:13 +01:00
parent 98c2f81bb9
commit acbb485302
3 changed files with 38 additions and 11 deletions

View File

@@ -559,3 +559,7 @@ class SysInfo(BaseModel):
class Health(BaseModel):
last_process: Optional[datetime] = None
last_process_ts: Optional[int] = None
bot_start: Optional[datetime] = None
bot_start_ts: Optional[int] = None
bot_startup: Optional[datetime] = None
bot_startup_ts: Optional[int] = None

View File

@@ -1366,18 +1366,39 @@ class RPC:
def health(self) -> Dict[str, Optional[Union[str, int]]]:
last_p = self._freqtrade.last_process
if last_p is None:
return {
res = {
"last_process": None,
"last_process_loc": None,
"last_process_ts": None,
"bot_start": None,
"bot_start_loc": None,
"bot_start_ts": None,
"bot_startup": None,
"bot_startup_loc": None,
"bot_startup_ts": None,
}
return {
if last_p is not None:
res.update({
"last_process": str(last_p),
"last_process_loc": format_date(last_p.astimezone(tzlocal())),
"last_process_ts": int(last_p.timestamp()),
}
})
if (bot_start := KeyValueStore.get_datetime_value(KeyStoreKeys.BOT_START_TIME)):
res.update({
"bot_start": str(bot_start),
"bot_start_loc": format_date(bot_start.astimezone(tzlocal())),
"bot_start_ts": int(bot_start.timestamp()),
})
if (bot_startup := KeyValueStore.get_datetime_value(KeyStoreKeys.STARTUP_TIME)):
res.update({
"bot_startup": str(bot_startup),
"bot_startup_loc": format_date(bot_startup.astimezone(tzlocal())),
"bot_startup_ts": int(bot_startup.timestamp()),
})
return res
def _update_market_direction(self, direction: MarketDirection) -> None:
self._freqtrade.strategy.market_direction = direction

View File

@@ -10,6 +10,7 @@ from freqtrade.edge import PairInfo
from freqtrade.enums import SignalDirection, State, TradingMode
from freqtrade.exceptions import ExchangeError, InvalidOrderException, TemporaryError
from freqtrade.persistence import Order, Trade
from freqtrade.persistence.key_value_store import set_startup_time
from freqtrade.persistence.pairlock_middleware import PairLocks
from freqtrade.rpc import RPC, RPCException
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
@@ -1298,6 +1299,7 @@ def test_rpc_health(mocker, default_conf) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
set_startup_time()
rpc = RPC(freqtradebot)
result = rpc.health()
assert result['last_process'] is None