refactor(execution): reuse shared payload builders in supervisor

This commit is contained in:
2026-07-03 11:05:59 +03:00
parent ce90e58060
commit a27774fd48

View File

@@ -10,6 +10,16 @@ from src.core.numbers import safe_float
from src.core.types import JsonDict from src.core.types import JsonDict
from src.trading.auto.state import AutoTradeState from src.trading.auto.state import AutoTradeState
from src.trading.execution.models import ExecutionDecision from src.trading.execution.models import ExecutionDecision
from src.trading.execution.payloads import (
build_decision_payload,
build_execution_price_payload,
build_execution_quality_payload,
build_market_context_payload,
build_risk_settings_payload,
build_runtime_blocks_payload,
build_runtime_payload,
build_signal_payload,
)
from src.trading.journal.service import JournalService from src.trading.journal.service import JournalService
@@ -338,67 +348,36 @@ class ExecutionSupervisorMixin(_ExecutionSupervisorProtocol):
# ---------- Event ---------- # ---------- Event ----------
"execution_type": "SUPERVISOR_BLOCK", "execution_type": "SUPERVISOR_BLOCK",
"action": action, "action": action,
"reason": reason,
# ---------- Runtime ---------- # В supervisor reason — причина блокировки.
"status": state.status, # Поэтому signal reason сохраняем отдельно ниже как signal_reason.
"strategy": state.strategy, "reason": reason,
"cycle_number": state.cycle_number,
# ---------- Instrument ---------- # ---------- Instrument ----------
"symbol": state.symbol, "symbol": state.symbol,
# ---------- Signal ---------- **build_runtime_payload(state),
"signal": state.last_signal,
"confidence": state.last_signal_confidence,
"repeat_count": state.last_signal_repeat_count,
"signal_reason": state.last_signal_reason,
# ---------- Decision ---------- # build_signal_payload даёт поле reason как причину сигнала,
"decision_status": state.decision_status, # поэтому ниже reason события перезаписываем обратно.
"decision_reason": state.decision_reason, **build_signal_payload(state),
"signal_reason": state.last_signal_reason,
"reason": reason,
**build_decision_payload(state),
"is_signal_confirmed": state.is_signal_confirmed, "is_signal_confirmed": state.is_signal_confirmed,
"is_signal_ready": state.is_signal_ready, "is_signal_ready": state.is_signal_ready,
# ---------- Runtime blocks ---------- **build_runtime_blocks_payload(state),
"entry_block_reason": state.entry_block_reason, **build_execution_quality_payload(state),
"entry_block_message": state.entry_block_message,
"execution_block_reason": state.execution_block_reason,
"execution_block_title": state.execution_block_title,
"execution_block_message": state.execution_block_message,
"execution_block_action": state.execution_block_action,
"last_flip_block_reason": state.last_flip_block_reason,
# ---------- Execution ---------- "execution_confidence_required_score": (
"execution_confidence_score": state.execution_confidence_score, state.execution_confidence_required_score
"execution_confidence_level": state.execution_confidence_level, ),
"execution_confidence_required_score": state.execution_confidence_required_score,
"execution_confidence_reason": state.execution_confidence_reason,
"execution_confidence_factors": state.execution_confidence_factors, "execution_confidence_factors": state.execution_confidence_factors,
"execution_quality": state.execution_quality, **build_execution_price_payload(state),
"execution_quality_reason": state.execution_quality_reason, **build_risk_settings_payload(state),
"execution_quality_message": state.execution_quality_message,
"spread_percent": state.spread_percent,
"snapshot_age_seconds": state.snapshot_age_seconds,
# ---------- Execution price ----------
"execution_price_source": state.execution_price_source,
"execution_price_age_seconds": state.execution_price_age_seconds,
"execution_bid_price": state.execution_bid_price,
"execution_ask_price": state.execution_ask_price,
"execution_last_price": state.execution_last_price,
"execution_price_freshness": state.execution_price_freshness,
# ---------- Risk settings ----------
"risk_percent": state.risk_percent,
"stop_loss_percent": state.stop_loss_percent,
"take_profit_percent": state.take_profit_percent,
"max_loss_usd": state.max_loss_usd,
"max_reserved_balance_percent": state.max_reserved_balance_percent,
"allocated_balance_usd": state.allocated_balance_usd,
"leverage": state.leverage,
# ---------- Position ---------- # ---------- Position ----------
"position_side": state.position_side, "position_side": state.position_side,
@@ -416,63 +395,7 @@ class ExecutionSupervisorMixin(_ExecutionSupervisorProtocol):
"loss_cooldown_active": state.loss_cooldown_active, "loss_cooldown_active": state.loss_cooldown_active,
"loss_cooldown_reason": state.loss_cooldown_reason, "loss_cooldown_reason": state.loss_cooldown_reason,
# ---------- Market score ---------- **build_market_context_payload(state),
"market_score": state.market_score,
"market_score_label": state.market_score_label,
"market_long_score": state.market_long_score,
"market_short_score": state.market_short_score,
# ---------- Market ----------
"market_state": state.market_state,
"market_trend": state.market_trend,
"market_volatility": state.market_volatility,
"market_trend_strength": state.market_trend_strength,
"market_trend_quality": state.market_trend_quality,
"market_phase": state.market_phase,
"market_phase_direction": state.market_phase_direction,
# ---------- Candle ----------
"last_closed_candle_change_percent": state.last_closed_candle_change_percent,
"last_closed_candle_direction": state.last_closed_candle_direction,
"current_interval_change_percent": state.current_interval_change_percent,
"current_interval_direction": state.current_interval_direction,
"current_interval_label": state.current_interval_label,
# ---------- Structure ----------
"market_structure": state.market_structure,
"market_structure_reason": state.market_structure_reason,
# ---------- Momentum ----------
"momentum_state": state.momentum_state,
"momentum_direction": state.momentum_direction,
"momentum_strength": state.momentum_strength,
"momentum_change_percent": state.momentum_change_percent,
"breakout_level": state.breakout_level,
"breakout_distance_percent": state.breakout_distance_percent,
"breakout_reason": state.breakout_reason,
# ---------- HTF ----------
"htf_interval": state.htf_interval,
"htf_atr_percent": state.htf_atr_percent,
"htf_atr_percent_baseline": state.htf_atr_percent_baseline,
"htf_volatility_ratio": state.htf_volatility_ratio,
"htf_volatility": state.htf_volatility,
"htf_market_state": state.htf_market_state,
"htf_trend": state.htf_trend,
"htf_trend_strength": state.htf_trend_strength,
"htf_trend_quality": state.htf_trend_quality,
"htf_market_phase": state.htf_market_phase,
"htf_alignment": state.htf_alignment,
"htf_confirmation_score": state.htf_confirmation_score,
"htf_reason": state.htf_reason,
# ---------- Market runtime ----------
"market_runtime_degraded": state.market_runtime_degraded,
"runtime_expired_reason": state.runtime_expired_reason,
"runtime_expired_message": state.runtime_expired_message,
"market_is_open": state.market_is_open,
"market_status": state.market_status,
"market_status_message": state.market_status_message,
} }
def _block_execution( def _block_execution(