07.4.3.12 — Real Risk Engine (execution-level)
This commit is contained in:
@@ -287,7 +287,7 @@ async def reset_risk(callback: CallbackQuery, state: FSMContext) -> None:
|
||||
)
|
||||
await callback.answer()
|
||||
|
||||
await asyncio.sleep(5.5)
|
||||
await asyncio.sleep(2.5)
|
||||
|
||||
if getattr(AutoTradeRunner, "_current_screen", None) != "auto_risk":
|
||||
return
|
||||
|
||||
@@ -343,6 +343,8 @@ class AutoTradeRunner:
|
||||
f"{payload.get('old_size')}:"
|
||||
f"{payload.get('new_size')}:"
|
||||
f"{payload.get('pnl')}"
|
||||
f"{payload.get('risk_reason')}:"
|
||||
f"{payload.get('is_forced')}:"
|
||||
)
|
||||
@classmethod
|
||||
def _build_execution_alert_text(
|
||||
|
||||
@@ -275,6 +275,14 @@ class ExecutionEngine:
|
||||
price_move_percent = self._calculate_price_move_percent(current_price)
|
||||
unrealized_pnl = self._calculate_pnl(current_price)
|
||||
|
||||
if self._is_max_loss_hit(state, unrealized_pnl):
|
||||
return self._close_position(
|
||||
state,
|
||||
forced_reason="MAX_LOSS",
|
||||
forced_exit_price=current_price,
|
||||
forced_pnl=unrealized_pnl,
|
||||
)
|
||||
|
||||
if self._is_stop_loss_hit(state, price_move_percent):
|
||||
return self._close_position(
|
||||
state,
|
||||
@@ -291,14 +299,6 @@ class ExecutionEngine:
|
||||
forced_pnl=unrealized_pnl,
|
||||
)
|
||||
|
||||
if self._is_max_loss_hit(state, unrealized_pnl):
|
||||
return self._close_position(
|
||||
state,
|
||||
forced_reason="MAX_LOSS",
|
||||
forced_exit_price=current_price,
|
||||
forced_pnl=unrealized_pnl,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
def _is_stop_loss_hit(
|
||||
|
||||
Reference in New Issue
Block a user