build 042: remove MarketPriceCache compatibility facade
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
# app/src/integrations/exchange/market_cache.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from src.market_data.acquisition.models.quote import Quote
|
||||
from src.storage.quote_store import InMemoryQuoteStore, QuoteStoreProtocol
|
||||
|
||||
|
||||
_MARKET_PRICE_CACHE_SOURCE_NAME = "legacy-market-price-cache"
|
||||
|
||||
|
||||
class MarketPriceCache:
|
||||
# Временный compatibility facade над каноническим Quote Store.
|
||||
_store: QuoteStoreProtocol = InMemoryQuoteStore()
|
||||
|
||||
@classmethod
|
||||
def set_quote(
|
||||
cls,
|
||||
quote: Quote,
|
||||
*,
|
||||
runtime_key: str = "default",
|
||||
) -> None:
|
||||
cls._store.set(
|
||||
_MARKET_PRICE_CACHE_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key=cls._normalize_runtime_key(runtime_key),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_quote(
|
||||
cls,
|
||||
symbol: str,
|
||||
*,
|
||||
runtime_key: str = "default",
|
||||
) -> Quote | None:
|
||||
return cls._store.get(
|
||||
_MARKET_PRICE_CACHE_SOURCE_NAME,
|
||||
cls._normalize_symbol(symbol),
|
||||
runtime_key=cls._normalize_runtime_key(runtime_key),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def clear(
|
||||
cls,
|
||||
symbol: str | None = None,
|
||||
*,
|
||||
runtime_key: str | None = None,
|
||||
) -> None:
|
||||
cls._store.clear(
|
||||
source_name=_MARKET_PRICE_CACHE_SOURCE_NAME,
|
||||
symbol=(
|
||||
cls._normalize_symbol(symbol)
|
||||
if symbol is not None
|
||||
else None
|
||||
),
|
||||
runtime_key=(
|
||||
cls._normalize_runtime_key(runtime_key)
|
||||
if runtime_key is not None
|
||||
else None
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _normalize_symbol(symbol: str) -> str:
|
||||
return str(symbol).strip().upper()
|
||||
|
||||
@staticmethod
|
||||
def _normalize_runtime_key(runtime_key: str) -> str:
|
||||
return str(runtime_key).strip().lower()
|
||||
@@ -9,7 +9,6 @@ from dataclasses import dataclass
|
||||
from typing import Callable
|
||||
|
||||
from src.core.types import JsonDict
|
||||
from src.integrations.exchange.market_cache import MarketPriceCache
|
||||
from src.integrations.exchange.service import ExchangeService
|
||||
from src.integrations.exchange.ws_client import ExchangeWebSocketClient
|
||||
from src.market_data.acquisition.adapters.dzengi.websocket import (
|
||||
@@ -18,6 +17,10 @@ from src.market_data.acquisition.adapters.dzengi.websocket import (
|
||||
from src.market_data.acquisition.exceptions import (
|
||||
MarketDataAcquisitionError,
|
||||
)
|
||||
from src.storage.quote_store import (
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
get_quote_store,
|
||||
)
|
||||
from src.trading.journal.service import JournalService
|
||||
|
||||
|
||||
@@ -178,7 +181,10 @@ class MarketDataRunner:
|
||||
runtime_key=context.runtime_key,
|
||||
cache_symbol=cache_symbol,
|
||||
):
|
||||
MarketPriceCache.clear(cache_symbol)
|
||||
get_quote_store().clear(
|
||||
source_name=QUOTE_RUNTIME_SOURCE_NAME,
|
||||
symbol=cache_symbol,
|
||||
)
|
||||
|
||||
try:
|
||||
market_status = ExchangeService().get_symbol_market_status(symbol)
|
||||
@@ -371,7 +377,8 @@ class MarketDataRunner:
|
||||
|
||||
valid_payload_count += 1
|
||||
|
||||
MarketPriceCache.set_quote(
|
||||
get_quote_store().set(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key=context.runtime_key,
|
||||
)
|
||||
|
||||
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from src.core.config import load_settings
|
||||
from src.integrations.exchange.market_cache import MarketPriceCache
|
||||
from src.integrations.exchange.service import ExchangeService
|
||||
from src.integrations.exchange.ws_client import ExchangeWebSocketClient
|
||||
from src.market_data.acquisition.adapters.dzengi.websocket import (
|
||||
@@ -13,10 +12,14 @@ from src.market_data.acquisition.adapters.dzengi.websocket import (
|
||||
from src.market_data.acquisition.exceptions import (
|
||||
MarketDataAcquisitionError,
|
||||
)
|
||||
from src.storage.quote_store import (
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
get_quote_store,
|
||||
)
|
||||
from src.trading.journal.service import JournalService
|
||||
|
||||
|
||||
# запускает постоянный websocket-поток рынка и обновляет MarketPriceCache
|
||||
# запускает постоянный websocket-поток рынка и обновляет Quote Store
|
||||
async def start_market_stream() -> None:
|
||||
settings = load_settings()
|
||||
journal = JournalService()
|
||||
@@ -52,7 +55,8 @@ async def start_market_stream() -> None:
|
||||
if quote.symbol.strip().upper() != symbol.strip().upper():
|
||||
continue
|
||||
|
||||
MarketPriceCache.set_quote(
|
||||
get_quote_store().set(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key="default",
|
||||
)
|
||||
|
||||
@@ -12,7 +12,6 @@ from src.core.numbers import safe_float
|
||||
from src.core.types import NumericLike
|
||||
from src.integrations.exchange.balance_parser import parse_account_balances
|
||||
from src.integrations.exchange.exceptions import ExchangeError
|
||||
from src.integrations.exchange.market_cache import MarketPriceCache
|
||||
from src.integrations.exchange.mock_data import (
|
||||
mock_balance_summary,
|
||||
mock_exchange_health,
|
||||
@@ -71,6 +70,10 @@ from src.storage.instrument_store import (
|
||||
InMemoryInstrumentStore,
|
||||
InstrumentStoreProtocol,
|
||||
)
|
||||
from src.storage.quote_store import (
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
get_quote_store,
|
||||
)
|
||||
from src.trading.journal.service import JournalService
|
||||
|
||||
|
||||
@@ -787,7 +790,8 @@ class ExchangeService:
|
||||
if not validation.is_valid:
|
||||
raise ExchangeError(validation.message)
|
||||
|
||||
cached_quote = MarketPriceCache.get_quote(
|
||||
cached_quote = get_quote_store().get(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
validation.normalized_symbol,
|
||||
runtime_key=normalized_runtime_key,
|
||||
)
|
||||
@@ -800,7 +804,8 @@ class ExchangeService:
|
||||
return cached_quote
|
||||
|
||||
quote = self._get_fresh_quote(validation.normalized_symbol)
|
||||
MarketPriceCache.set_quote(
|
||||
get_quote_store().set(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key=normalized_runtime_key,
|
||||
)
|
||||
@@ -827,7 +832,8 @@ class ExchangeService:
|
||||
validation.normalized_symbol
|
||||
)
|
||||
|
||||
MarketPriceCache.set_quote(
|
||||
get_quote_store().set(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key=normalized_runtime_key,
|
||||
)
|
||||
@@ -855,7 +861,8 @@ class ExchangeService:
|
||||
if not validation.is_valid:
|
||||
raise ExchangeError(validation.message)
|
||||
|
||||
quote = MarketPriceCache.get_quote(
|
||||
quote = get_quote_store().get(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
validation.normalized_symbol,
|
||||
runtime_key=normalized_runtime_key,
|
||||
)
|
||||
@@ -873,7 +880,8 @@ class ExchangeService:
|
||||
quote = self._get_fresh_quote(
|
||||
validation.normalized_symbol
|
||||
)
|
||||
MarketPriceCache.set_quote(
|
||||
get_quote_store().set(
|
||||
QUOTE_RUNTIME_SOURCE_NAME,
|
||||
quote,
|
||||
runtime_key=normalized_runtime_key,
|
||||
)
|
||||
|
||||
@@ -213,3 +213,14 @@ class InMemoryQuoteStore:
|
||||
)
|
||||
|
||||
return normalized_symbol
|
||||
|
||||
|
||||
|
||||
QUOTE_RUNTIME_SOURCE_NAME = "legacy-market-price-cache"
|
||||
_SHARED_QUOTE_STORE: QuoteStoreProtocol = InMemoryQuoteStore()
|
||||
|
||||
|
||||
def get_quote_store() -> QuoteStoreProtocol:
|
||||
"""Вернуть общий runtime-экземпляр канонического Quote Store."""
|
||||
return _SHARED_QUOTE_STORE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user