feat: add market data architecture and complete migration through build 039

This commit is contained in:
2026-07-14 09:58:16 +03:00
parent 26deb861bc
commit a996f2f797
443 changed files with 80452 additions and 1335 deletions

View File

@@ -0,0 +1,49 @@
# 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