refactor(execution): simplify intelligence exit sync
This commit is contained in:
@@ -43,30 +43,28 @@ class ExecutionPositionExitDecisionMixin(_ExecutionPositionExitDecisionProtocol)
|
||||
if self._is_normal_pullback_wave(state=state, metrics=metrics):
|
||||
return None
|
||||
|
||||
giveback_reason = self._giveback_close_reason(
|
||||
giveback_reason = self._apply_intelligence_exit(
|
||||
state=state,
|
||||
metrics=metrics,
|
||||
reason=self._giveback_close_reason(
|
||||
state=state,
|
||||
metrics=metrics,
|
||||
),
|
||||
algorithm="GIVEBACK",
|
||||
)
|
||||
|
||||
if giveback_reason is not None:
|
||||
self._sync_intelligence_exit_state(
|
||||
state=state,
|
||||
reason=giveback_reason,
|
||||
algorithm="GIVEBACK",
|
||||
)
|
||||
return giveback_reason
|
||||
|
||||
time_decay_reason = self._time_decay_close_reason(
|
||||
time_decay_reason = self._apply_intelligence_exit(
|
||||
state=state,
|
||||
metrics=metrics,
|
||||
reason=self._time_decay_close_reason(
|
||||
state=state,
|
||||
metrics=metrics,
|
||||
),
|
||||
algorithm="TIME_DECAY",
|
||||
)
|
||||
|
||||
if time_decay_reason is not None:
|
||||
self._sync_intelligence_exit_state(
|
||||
state=state,
|
||||
reason=time_decay_reason,
|
||||
algorithm="TIME_DECAY",
|
||||
)
|
||||
return time_decay_reason
|
||||
|
||||
return None
|
||||
@@ -87,6 +85,24 @@ class ExecutionPositionExitDecisionMixin(_ExecutionPositionExitDecisionProtocol)
|
||||
state.runtime_protection_reason = reason
|
||||
state.runtime_protection_updated_at = time.monotonic()
|
||||
|
||||
def _apply_intelligence_exit(
|
||||
self,
|
||||
*,
|
||||
state: AutoTradeState,
|
||||
reason: str | None,
|
||||
algorithm: str,
|
||||
) -> str | None:
|
||||
if reason is None:
|
||||
return None
|
||||
|
||||
self._sync_intelligence_exit_state(
|
||||
state=state,
|
||||
reason=reason,
|
||||
algorithm=algorithm,
|
||||
)
|
||||
|
||||
return reason
|
||||
|
||||
def _giveback_close_reason(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user