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):
|
if self._is_normal_pullback_wave(state=state, metrics=metrics):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
giveback_reason = self._giveback_close_reason(
|
giveback_reason = self._apply_intelligence_exit(
|
||||||
|
state=state,
|
||||||
|
reason=self._giveback_close_reason(
|
||||||
state=state,
|
state=state,
|
||||||
metrics=metrics,
|
metrics=metrics,
|
||||||
|
),
|
||||||
|
algorithm="GIVEBACK",
|
||||||
)
|
)
|
||||||
|
|
||||||
if giveback_reason is not None:
|
if giveback_reason is not None:
|
||||||
self._sync_intelligence_exit_state(
|
|
||||||
state=state,
|
|
||||||
reason=giveback_reason,
|
|
||||||
algorithm="GIVEBACK",
|
|
||||||
)
|
|
||||||
return giveback_reason
|
return giveback_reason
|
||||||
|
|
||||||
time_decay_reason = self._time_decay_close_reason(
|
time_decay_reason = self._apply_intelligence_exit(
|
||||||
|
state=state,
|
||||||
|
reason=self._time_decay_close_reason(
|
||||||
state=state,
|
state=state,
|
||||||
metrics=metrics,
|
metrics=metrics,
|
||||||
|
),
|
||||||
|
algorithm="TIME_DECAY",
|
||||||
)
|
)
|
||||||
|
|
||||||
if time_decay_reason is not None:
|
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 time_decay_reason
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -87,6 +85,24 @@ class ExecutionPositionExitDecisionMixin(_ExecutionPositionExitDecisionProtocol)
|
|||||||
state.runtime_protection_reason = reason
|
state.runtime_protection_reason = reason
|
||||||
state.runtime_protection_updated_at = time.monotonic()
|
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(
|
def _giveback_close_reason(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
|
|||||||
Reference in New Issue
Block a user