07.4.4.1.13 — AutoTrade Runtime Journal, Execution Refactor & Trade Analytics
This commit is contained in:
74
app/src/trading/execution/resets.py
Normal file
74
app/src/trading/execution/resets.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# app/src/trading/execution/resets.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Protocol
|
||||
|
||||
from src.trading.auto.state import AutoTradeState
|
||||
|
||||
|
||||
class _ExecutionResetsProtocol(Protocol):
|
||||
"""
|
||||
Protocol для reset mixin.
|
||||
|
||||
Сейчас пустой, но оставлен для единообразия архитектуры.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ExecutionResetsMixin(_ExecutionResetsProtocol):
|
||||
"""
|
||||
Общие reset-функции execution слоя.
|
||||
|
||||
Здесь находятся методы очистки runtime/protection/
|
||||
lifecycle состояния позиции.
|
||||
|
||||
Это позволяет избежать циклических зависимостей между:
|
||||
- position_actions.py
|
||||
- position_protection.py
|
||||
- runtime_actions.py
|
||||
"""
|
||||
|
||||
def _reset_runtime_protection_state(
|
||||
self,
|
||||
state: AutoTradeState,
|
||||
) -> None:
|
||||
"""
|
||||
Полный reset runtime protection состояния позиции.
|
||||
Вызывается после закрытия позиции.
|
||||
"""
|
||||
|
||||
state.position_protection_status = None
|
||||
state.position_protection_reason = None
|
||||
|
||||
state.break_even_armed = False
|
||||
state.break_even_price = None
|
||||
|
||||
state.trailing_stop_active = False
|
||||
state.trailing_stop_price = None
|
||||
|
||||
state.profit_lock_active = False
|
||||
state.profit_lock_price = None
|
||||
|
||||
state.runtime_protection_action = None
|
||||
state.runtime_protection_reason = None
|
||||
state.runtime_protection_updated_at = None
|
||||
|
||||
def _reset_position_lifecycle_state(
|
||||
self,
|
||||
state: AutoTradeState,
|
||||
) -> None:
|
||||
"""
|
||||
Reset lifecycle состояния позиции.
|
||||
Используется после полного закрытия позиции.
|
||||
"""
|
||||
|
||||
state.position_opened_monotonic_at = None
|
||||
|
||||
state.last_flip_old_side = None
|
||||
state.last_flip_new_side = None
|
||||
state.last_flip_pnl_usd = None
|
||||
state.last_flip_reason = None
|
||||
|
||||
state.execution_block_reason = None
|
||||
state.last_flip_block_reason = None
|
||||
Reference in New Issue
Block a user