Stage 04.2 - journal and event log
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import platform
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
@@ -8,6 +7,7 @@ from src.core.config import load_settings
|
||||
from src.core.constants import APP_NAME, APP_VERSION
|
||||
from src.integrations.exchange.service import ExchangeService
|
||||
from src.storage.session import check_database_health
|
||||
from src.trading.journal.service import JournalService
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -39,7 +39,9 @@ def _extract_postgres_version(raw: str) -> str:
|
||||
return "PostgreSQL"
|
||||
|
||||
|
||||
def _build_exchange_status(exchange_service: ExchangeService, default_symbol: str) -> ComponentStatus:
|
||||
def _build_exchange_status(
|
||||
exchange_service: ExchangeService, default_symbol: str
|
||||
) -> ComponentStatus:
|
||||
try:
|
||||
symbol_validation = exchange_service.validate_symbol(default_symbol)
|
||||
except Exception as exc:
|
||||
@@ -50,6 +52,7 @@ def _build_exchange_status(exchange_service: ExchangeService, default_symbol: st
|
||||
)
|
||||
|
||||
exchange_health = exchange_service.get_health()
|
||||
|
||||
if exchange_health.ok and symbol_validation.is_valid:
|
||||
return ComponentStatus(name="Биржа", state="🟢")
|
||||
|
||||
@@ -63,7 +66,7 @@ def _build_exchange_status(exchange_service: ExchangeService, default_symbol: st
|
||||
return ComponentStatus(
|
||||
name="Биржа",
|
||||
state="🔴",
|
||||
details=symbol_validation.message or "Инструмент не прошел проверку.",
|
||||
details=symbol_validation.message or "Инструмент не прошёл проверку.",
|
||||
)
|
||||
|
||||
|
||||
@@ -96,6 +99,14 @@ def _build_database_status() -> tuple[ComponentStatus, str]:
|
||||
)
|
||||
|
||||
|
||||
def _build_journal_status() -> ComponentStatus:
|
||||
ok, message = JournalService().get_journal_health()
|
||||
if ok:
|
||||
return ComponentStatus(name="Журнал", state="🟢")
|
||||
|
||||
return ComponentStatus(name="Журнал", state="🔴", details=message)
|
||||
|
||||
|
||||
def _resolve_mode_label(exchange_testnet: bool) -> str:
|
||||
return "ДЕМО аккаунт" if exchange_testnet else "РЕАЛЬНЫЙ аккаунт"
|
||||
|
||||
@@ -107,6 +118,7 @@ def get_system_snapshot() -> SystemSnapshot:
|
||||
database_status, db_label = _build_database_status()
|
||||
exchange_status = _build_exchange_status(exchange_service, settings.default_symbol)
|
||||
account_status = _build_account_status(exchange_service)
|
||||
journal_status = _build_journal_status()
|
||||
|
||||
components = [
|
||||
ComponentStatus(name="Приложение", state="🟢"),
|
||||
@@ -114,6 +126,7 @@ def get_system_snapshot() -> SystemSnapshot:
|
||||
ComponentStatus(name="Telegram", state="🟢"),
|
||||
exchange_status,
|
||||
account_status,
|
||||
journal_status,
|
||||
]
|
||||
|
||||
return SystemSnapshot(
|
||||
@@ -136,7 +149,9 @@ def _render_component(component: ComponentStatus) -> str:
|
||||
|
||||
def build_system_text() -> str:
|
||||
snapshot = get_system_snapshot()
|
||||
components_block = "\n".join(_render_component(component) for component in snapshot.components)
|
||||
components_block = "\n".join(
|
||||
_render_component(component) for component in snapshot.components
|
||||
)
|
||||
|
||||
return (
|
||||
"<b>⚙️ Система</b>\n\n"
|
||||
|
||||
Reference in New Issue
Block a user