07.4.4.1.8 Execution Freshness and Market Quality Layer

This commit is contained in:
2026-05-11 20:08:29 +03:00
parent ec9904f91d
commit eb40ecc4dd
7 changed files with 1021 additions and 7 deletions

View File

@@ -159,6 +159,7 @@ def _build_waiting_text(state) -> str:
_signal_line(state),
_market_state_line(state),
_entry_block_line(state),
_execution_quality_line(state),
*_signal_confidence_lines(state),
*_execution_block_lines(state),
]
@@ -173,8 +174,7 @@ def _build_waiting_text(state) -> str:
"",
*signal_lines,
"",
"🧾 <b>Подготовка ордера</b>",
"",
"🧾 Подготовка ордера",
_order_header_line(state),
f"<b>{_price_label_for_signal(state)}</b> · {_format_usd_or_dash(price)}",
_estimated_size_text(state, price),
@@ -217,6 +217,7 @@ def _build_active_position_text(state) -> str:
f"<b>Зарезервировано</b> · $ {_format_money_compact(reserved)}",
f"<b>P&L</b> {_format_signed_usd_with_direction(pnl)}",
_market_state_line(state),
_execution_quality_line(state),
*_execution_block_lines(state),
"",
(
@@ -286,7 +287,7 @@ def _entry_block_line(state) -> str:
signal = (state.last_signal or "HOLD").upper()
if signal == "HOLD":
return f"Ожидание · {compact_message}"
return f"Условие · {compact_message}"
if signal in {"BUY", "SELL"}:
return f"Вход · {compact_message}"
@@ -294,12 +295,55 @@ def _entry_block_line(state) -> str:
return ""
def _execution_quality_line(state) -> str:
quality = getattr(state, "execution_quality", None)
reason = getattr(state, "execution_quality_reason", None)
spread_percent = getattr(state, "spread_percent", None)
age_seconds = getattr(state, "snapshot_age_seconds", None)
if not quality:
return ""
if quality == "GOOD":
return ""
if reason == "WIDE_SPREAD" and spread_percent is not None:
return f"⚠️ Рынок · spread {_format_percent(spread_percent)}"
if reason == "AGING_SNAPSHOT" and age_seconds is not None:
return f"⚠️ Рынок · данные стареют ({age_seconds:.1f}с)"
if reason == "STALE_SNAPSHOT":
return "⛔ Вход · рынок неактуален"
if reason == "HIGH_SPREAD" and spread_percent is not None:
return f"⛔ Вход · высокий spread {_format_percent(spread_percent)}"
if reason == "SNAPSHOT_UNAVAILABLE":
return "⚠️ Рынок · нет depth snapshot"
if reason == "SNAPSHOT_ERROR":
return "⛔ Вход · нет данных рынка"
message = getattr(state, "execution_quality_message", None)
if not message:
return ""
return f"⚠️ Рынок · {message}"
def _execution_block_lines(state) -> list[str]:
lines: list[str] = []
reason = getattr(state, "execution_block_reason", None)
if reason:
lines.append(f"Исполнение · {reason}")
if reason and reason not in {
"высокий spread",
"spread повышен",
"snapshot устарел",
"рынок неактуален",
}:
lines.append(f"Вход · {reason}")
adjustment = getattr(state, "execution_size_adjustment_reason", None)