07.4.4.1.3 — Journal Runtime Cleanup & Event Titles Layer
This commit is contained in:
@@ -208,7 +208,12 @@ def _log_risk_updated(action: str) -> None:
|
||||
try:
|
||||
JournalService().log_ui_info(
|
||||
event_type="risk_settings_updated",
|
||||
message="Параметры защиты позиции обновлены.",
|
||||
message=(
|
||||
"Параметры защиты позиции изменены: "
|
||||
f"SL={_format_percent(state.stop_loss_percent)}, "
|
||||
f"TP={_format_percent(state.take_profit_percent)}, "
|
||||
f"ML={_format_usd(state.max_loss_usd)}."
|
||||
),
|
||||
screen="auto",
|
||||
action=action,
|
||||
payload={
|
||||
|
||||
@@ -241,16 +241,16 @@ def _market_state_line(state) -> str:
|
||||
market_state = getattr(state, "market_state", None)
|
||||
|
||||
labels = {
|
||||
"TREND_UP": "📈 Рынок · Рост",
|
||||
"TREND_DOWN": "📉 Рынок · Падение",
|
||||
"RANGE": "🟰 Рынок · Без направления",
|
||||
"HIGH_VOLATILITY": "⚠️ Рынок · Волатильность",
|
||||
"LOW_VOLATILITY": "🟰 Рынок · Спокойный",
|
||||
"UNKNOWN": "⏳ Рынок · Анализ",
|
||||
None: "⏳ Рынок · Анализ",
|
||||
"TREND_UP": "📈 Тренд · Восходящий",
|
||||
"TREND_DOWN": "📉 Тренд · Нисходящий",
|
||||
"RANGE": "🟰 Тренд · Нет выраженного направления",
|
||||
"HIGH_VOLATILITY": "⚠️ Рынок · Высокая волатильность",
|
||||
"LOW_VOLATILITY": "🟰 Рынок · Низкая активность",
|
||||
"UNKNOWN": "⏳ Рынок · Идёт анализ",
|
||||
None: "⏳ Рынок · Идёт анализ",
|
||||
}
|
||||
|
||||
return labels.get(market_state, "⏳ Рынок · Анализ")
|
||||
return labels.get(market_state, "⏳ Рынок · Идёт анализ")
|
||||
|
||||
|
||||
def _execution_block_lines(state) -> list[str]:
|
||||
|
||||
@@ -9,6 +9,7 @@ from aiogram.types import InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from src.core.config import load_settings
|
||||
from src.core.event_titles import event_title
|
||||
|
||||
|
||||
PAGE_SIZE = 5
|
||||
@@ -20,28 +21,6 @@ LEVEL_ICONS = {
|
||||
"CRITICAL": "🆘",
|
||||
}
|
||||
|
||||
EVENT_TITLES = {
|
||||
"signal_summary": "Сводка сигнала",
|
||||
"signal_ready": "Сигнал готов",
|
||||
"position_opened": "Позиция открыта",
|
||||
"position_closed": "Позиция закрыта",
|
||||
"position_flipped": "Направление позиции изменено",
|
||||
"position_flip_blocked": "Смена направления позиции заблокирована",
|
||||
"risk_settings_updated": "Настройки защиты обновлены",
|
||||
"market_monitor_started": "Мониторинг рынка запущен",
|
||||
"market_monitor_stopped": "Мониторинг рынка остановлен",
|
||||
"market_stream_connected": "Поток рынка подключён",
|
||||
"market_stream_disconnected": "Поток рынка отключён",
|
||||
"market_symbol_changed": "Инструмент рынка изменён",
|
||||
"journal_export_error": "Ошибка экспорта журнала",
|
||||
"journal_exported": "Журнал экспортирован",
|
||||
"journal_cleared": "Журнал очищен",
|
||||
"notification_sent": "Уведомление отправлено",
|
||||
"notification_error": "Ошибка уведомления",
|
||||
"app_started": "Приложение запущено",
|
||||
"app_bootstrap_failed": "Ошибка запуска приложения",
|
||||
}
|
||||
|
||||
TECH_TO_HUMAN_MESSAGES = {
|
||||
"invalid api key": "Неверный API Key.",
|
||||
"unauthorized": "Нет доступа к аккаунту.",
|
||||
@@ -164,7 +143,7 @@ def _time_label(dt: datetime | None, raw_value: str) -> str:
|
||||
|
||||
|
||||
def _event_title(event_type: str) -> str:
|
||||
return EVENT_TITLES.get(event_type, event_type)
|
||||
return event_title(event_type)
|
||||
|
||||
|
||||
def _humanize_message(message: str) -> str:
|
||||
|
||||
@@ -97,15 +97,6 @@ async def _render_system_screen(
|
||||
) -> None:
|
||||
journal = JournalService()
|
||||
|
||||
journal.log_ui_info(
|
||||
event_type="system_open_requested",
|
||||
message="Запрошено открытие экрана системы.",
|
||||
screen="system",
|
||||
action=action,
|
||||
user_id=user_id,
|
||||
chat_id=chat_id,
|
||||
)
|
||||
|
||||
snapshot = get_system_snapshot()
|
||||
is_alert = has_system_alerts(snapshot)
|
||||
|
||||
@@ -363,6 +354,22 @@ def _log_auto_setting_updated(
|
||||
pass
|
||||
|
||||
|
||||
def _human_symbol(symbol: str | None) -> str:
|
||||
if not symbol:
|
||||
return "—"
|
||||
|
||||
base = symbol.split("_", 1)[0].upper()
|
||||
|
||||
if "/" in base:
|
||||
return base.split("/", 1)[0]
|
||||
|
||||
for suffix in ("USDT", "USD", "EUR", "BTC"):
|
||||
if base.endswith(suffix) and len(base) > len(suffix):
|
||||
return base[: -len(suffix)]
|
||||
|
||||
return base
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("settings:auto_strategy:"))
|
||||
async def set_auto_strategy(callback: CallbackQuery) -> None:
|
||||
strategy = callback.data.split(":", 2)[2].upper()
|
||||
@@ -375,7 +382,7 @@ async def set_auto_strategy(callback: CallbackQuery) -> None:
|
||||
|
||||
if previous_strategy != strategy:
|
||||
_log_auto_setting_updated(
|
||||
message=f"Стратегия автоторговли изменена на {strategy}.",
|
||||
message=f"Стратегия изменена: {strategy}.",
|
||||
action="set_strategy",
|
||||
payload={
|
||||
"previous_strategy": previous_strategy,
|
||||
@@ -423,7 +430,7 @@ async def set_auto_symbol(callback: CallbackQuery) -> None:
|
||||
|
||||
if previous_symbol != symbol:
|
||||
_log_auto_setting_updated(
|
||||
message=f"Актив автоторговли изменён на {symbol}.",
|
||||
message=f"Актив изменён: {_human_symbol(symbol)}.",
|
||||
action="set_symbol",
|
||||
payload={
|
||||
"previous_symbol": previous_symbol,
|
||||
@@ -470,7 +477,7 @@ async def set_auto_risk(callback: CallbackQuery) -> None:
|
||||
|
||||
if previous_risk != risk:
|
||||
_log_auto_setting_updated(
|
||||
message=f"Риск на сделку изменён на {risk:g}%.",
|
||||
message=f"Риск на сделку изменён: {risk:g}%.",
|
||||
action="set_risk_percent",
|
||||
payload={
|
||||
"previous_risk_percent": previous_risk,
|
||||
@@ -520,7 +527,7 @@ async def set_auto_leverage(callback: CallbackQuery) -> None:
|
||||
|
||||
if previous_leverage != leverage:
|
||||
_log_auto_setting_updated(
|
||||
message=f"Плечо автоторговли изменено на x{leverage:g}.",
|
||||
message=f"Плечо изменено: x{leverage:g}.",
|
||||
action="set_leverage",
|
||||
payload={
|
||||
"previous_leverage": previous_leverage,
|
||||
@@ -572,7 +579,7 @@ async def set_auto_max_reserved(callback: CallbackQuery) -> None:
|
||||
value_text = "off" if value is None else f"{value:g}%"
|
||||
|
||||
_log_auto_setting_updated(
|
||||
message=f"Лимит на сделку изменён на {value_text}.",
|
||||
message=f"Лимит на сделку изменён: {value_text}.",
|
||||
action="set_max_reserved_balance_percent",
|
||||
payload={
|
||||
"previous_max_reserved_balance_percent": previous_value,
|
||||
|
||||
Reference in New Issue
Block a user