refactor(execution): add shared payload builders

This commit is contained in:
2026-07-02 22:56:55 +03:00
parent cfd7d76806
commit 6ce14a0292

View File

@@ -0,0 +1,79 @@
# app/src/trading/execution/payloads.py
from __future__ import annotations
from src.core.types import JsonDict
from src.trading.auto.state import AutoTradeState
def build_market_payload(state: AutoTradeState) -> JsonDict:
return {
"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_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,
"market_structure": state.market_structure,
"market_structure_reason": state.market_structure_reason,
"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,
}
def build_momentum_payload(state: AutoTradeState) -> JsonDict:
return {
"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,
}
def build_htf_payload(state: AutoTradeState) -> JsonDict:
return {
"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,
}
def build_market_runtime_payload(state: AutoTradeState) -> JsonDict:
return {
"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 build_market_context_payload(state: AutoTradeState) -> JsonDict:
return {
**build_market_payload(state),
**build_momentum_payload(state),
**build_htf_payload(state),
**build_market_runtime_payload(state),
}