07.4.3.14 — Auto Trading UI. Realistic Pricing & Debug Live Tools

This commit is contained in:
2026-05-09 01:34:46 +03:00
parent ee78f9774a
commit df76490783
15 changed files with 2161 additions and 464 deletions

View File

@@ -26,7 +26,7 @@ class AutoTradeRunner:
_current_screen: str | None = None
_analysis_interval_seconds = 5
_ui_interval_seconds = 60
_ui_interval_seconds = 5
_last_text: str | None = None
_last_ui_refresh_at: float = 0.0
@@ -550,17 +550,66 @@ class AutoTradeRunner:
except (TypeError, ValueError):
return ""
@classmethod
def _log_refresh_skip(cls, reason: str, payload: dict | None = None) -> None:
try:
JournalService().log_ui_info(
event_type="auto_screen_refresh_skipped",
message=f"Auto screen refresh skipped: {reason}",
screen="auto",
action="refresh_screen",
payload=payload or {},
)
except Exception:
pass
@classmethod
def _log_refresh_success(cls, payload: dict | None = None) -> None:
try:
JournalService().log_ui_info(
event_type="auto_screen_refreshed",
message="Auto screen refreshed.",
screen="auto",
action="refresh_screen",
payload=payload or {},
)
except Exception:
pass
@classmethod
def _log_refresh_error(cls, reason: str, payload: dict | None = None) -> None:
try:
JournalService().log_error(
"auto_screen_refresh_error",
f"Auto screen refresh error: {reason}",
payload or {},
)
except Exception:
pass
@classmethod
async def _refresh_screen(cls, *, force: bool = False) -> None:
if cls._current_screen != "auto":
cls._log_refresh_skip("current_screen_not_auto")
return
now = time.monotonic()
if now < cls._retry_after_until:
cls._log_refresh_skip(
"retry_after_active",
{"retry_after_until": cls._retry_after_until, "now": now},
)
return
if not force and now - cls._last_ui_refresh_at < cls._ui_interval_seconds:
cls._log_refresh_skip(
"ui_interval_not_reached",
{
"elapsed": round(now - cls._last_ui_refresh_at, 2),
"interval": cls._ui_interval_seconds,
},
)
return
if not all(
@@ -572,11 +621,22 @@ class AutoTradeRunner:
cls._render_markup,
]
):
cls._log_refresh_skip(
"screen_not_registered",
{
"has_bot": cls._bot is not None,
"chat_id": cls._chat_id,
"message_id": cls._message_id,
"has_render_text": cls._render_text is not None,
"has_render_markup": cls._render_markup is not None,
},
)
return
text = cls._render_text()
if text == cls._last_text:
cls._log_refresh_skip("text_not_changed")
return
try:
@@ -589,8 +649,23 @@ class AutoTradeRunner:
cls._last_text = text
cls._last_ui_refresh_at = now
cls._log_refresh_success(
{
"chat_id": cls._chat_id,
"message_id": cls._message_id,
"text_length": len(text),
}
)
except TelegramRetryAfter as exc:
cls._retry_after_until = time.monotonic() + exc.retry_after + 5
cls._log_refresh_error(
"telegram_retry_after",
{
"retry_after": exc.retry_after,
"retry_after_until": cls._retry_after_until,
},
)
except TelegramBadRequest as exc:
error_text = str(exc).lower()
@@ -598,6 +673,7 @@ class AutoTradeRunner:
if "message is not modified" in error_text:
cls._last_text = text
cls._last_ui_refresh_at = now
cls._log_refresh_skip("telegram_message_not_modified")
return
if "message to edit not found" in error_text:
@@ -605,7 +681,19 @@ class AutoTradeRunner:
cls._render_text = None
cls._render_markup = None
cls._last_text = None
cls._log_refresh_error(
"telegram_message_to_edit_not_found",
{"error": str(exc)},
)
return
except Exception:
pass
cls._log_refresh_error(
"telegram_bad_request",
{"error": str(exc)},
)
except Exception as exc:
cls._log_refresh_error(
"unexpected_refresh_error",
{"error": str(exc)},
)