diff --git a/app/src/trading/execution/flip.py b/app/src/trading/execution/flip.py index d451d51..48ba95b 100644 --- a/app/src/trading/execution/flip.py +++ b/app/src/trading/execution/flip.py @@ -14,6 +14,7 @@ from src.trading.auto.state_reset import ( reset_execution_block_state, ) from src.trading.execution.models import ExecutionDecision +from src.trading.execution.payloads import build_market_context_payload from src.trading.execution.pricing import ExecutionPrice from src.trading.journal.service import JournalService from src.trading.position.state import PositionState @@ -121,19 +122,9 @@ class ExecutionFlipMixin(_ExecutionFlipProtocol): "repeat_count": state.last_signal_repeat_count, "reason": state.last_signal_reason, "reject_reason": reason, - # Общая оценка рынка на момент отказа flip. - "market_score": getattr(state, "market_score", None), - "market_score_label": getattr(state, "market_score_label", None), "unrealized_pnl_usd": state.unrealized_pnl_usd, - "market_state": state.market_state, - "market_trend": state.market_trend, - "market_phase": state.market_phase, - "market_trend_quality": state.market_trend_quality, - "htf_alignment": state.htf_alignment, - "htf_confirmation_score": state.htf_confirmation_score, - "momentum_state": state.momentum_state, - "momentum_direction": state.momentum_direction, "entry_timing_state": state.entry_timing_state, + **build_market_context_payload(state), "opened_at": position.opened_at, "updated_at": position.updated_at, } @@ -157,18 +148,8 @@ class ExecutionFlipMixin(_ExecutionFlipProtocol): "execution_confidence_score": state.execution_confidence_score, "repeat_count": state.last_signal_repeat_count, "reason": reason, - # Общая оценка рынка на момент блокировки flip. - "market_score": getattr(state, "market_score", None), - "market_score_label": getattr(state, "market_score_label", None), "unrealized_pnl_usd": state.unrealized_pnl_usd, - "market_state": state.market_state, - "market_trend": state.market_trend, - "market_phase": state.market_phase, - "market_structure": state.market_structure, - "htf_alignment": state.htf_alignment, - "htf_confirmation_score": state.htf_confirmation_score, - "momentum_state": state.momentum_state, - "momentum_direction": state.momentum_direction, + **build_market_context_payload(state), "opened_at": position.opened_at, "updated_at": position.updated_at, } @@ -252,18 +233,11 @@ class ExecutionFlipMixin(_ExecutionFlipProtocol): "adaptive_size_final": state.adaptive_size_final, "repeat_count": state.last_signal_repeat_count, "reason": state.last_signal_reason, - # Общая оценка рынка на момент смены направления позиции. - # Фиксируем её вместе с adaptive size, чтобы видеть контекст flip. - "market_score": getattr(state, "market_score", None), - "market_score_label": getattr(state, "market_score_label", None), "opened_at": old_opened_at, "new_opened_monotonic_at": opened_monotonic_at, "closed_at": now, "new_opened_at": now, - "market_state": state.market_state, - "market_trend": state.market_trend, - "market_phase": state.market_phase, - "market_structure": state.market_structure, + **build_market_context_payload(state), # ---------- Position health ---------- "position_hold_seconds": state.position_hold_seconds, @@ -307,10 +281,6 @@ class ExecutionFlipMixin(_ExecutionFlipProtocol): "trailing_stop_active": state.trailing_stop_active, "trailing_stop_price": state.trailing_stop_price, - "htf_alignment": state.htf_alignment, - "htf_confirmation_score": state.htf_confirmation_score, - "momentum_state": state.momentum_state, - "momentum_direction": state.momentum_direction, "pricing": PRICING_FLIP_MODE, "exit_pricing_role": exit_execution.pricing_role, "exit_price_source": exit_execution.source,