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,19 +1366,40 @@ class RPC:
def health(self) -> Dict[str, Optional[Union[str, int]]]:
last_p = self._freqtrade.last_process
if last_p is None:
return {
"last_process": None,
"last_process_loc": None,
"last_process_ts": None,
}
return {
"last_process": str(last_p),
"last_process_loc": format_date(last_p.astimezone(tzlocal())),
"last_process_ts": int(last_p.timestamp()),
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,
}
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