# app/tests/unit/trading/debug/test_execution.py from __future__ import annotations import pytest import src.trading.debug.execution as module from src.integrations.exchange.models import ExecutionPriceSnapshot from src.trading.debug.execution import DebugExecutionEngine def _snapshot() -> ExecutionPriceSnapshot: return ExecutionPriceSnapshot( symbol="BTC/USD_LEVERAGE", last_price=100.5, bid_price=100.0, ask_price=101.0, updated_at="13.07.2026 15:00:00", source="rest_fallback", is_fresh=True, age_seconds=0.0, ) def test_debug_execution_uses_execution_snapshot( monkeypatch: pytest.MonkeyPatch, ) -> None: calls: list[tuple[str, str | None]] = [] class Service: def get_execution_snapshot( self, symbol: str, *, runtime_key: str | None = None, ) -> ExecutionPriceSnapshot: calls.append((symbol, runtime_key)) return _snapshot() monkeypatch.setattr(module, "ExchangeService", Service) engine = DebugExecutionEngine() assert engine._entry_price_for_side("BTC/USD_LEVERAGE", "LONG") == 101.0 assert engine._entry_price_for_side("BTC/USD_LEVERAGE", "SHORT") == 100.0 assert engine._exit_price_for_side("BTC/USD_LEVERAGE", "LONG") == 100.0 assert engine._exit_price_for_side("BTC/USD_LEVERAGE", "SHORT") == 101.0 assert engine._market_last_price("BTC/USD_LEVERAGE") == 100.5 assert calls == [("BTC/USD_LEVERAGE", "debug_auto")] * 5