mirror of
https://github.com/QuantEngines/fx_quant_engine.git
synced 2026-07-28 02:47:50 +00:00
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from datetime import datetime, timedelta, timezone
|
|
|
|
from options_quant_engine.ingestion.adapters import MockAdapter
|
|
from options_quant_engine.ingestion.base import BaseDataAdapter
|
|
from options_quant_engine.ingestion.router import DataSourceRouter
|
|
|
|
|
|
class FailingAdapter(BaseDataAdapter):
|
|
def fetch_price_data(self, asset, start, end):
|
|
raise RuntimeError("fail")
|
|
|
|
def fetch_macro_data(self, key, start, end):
|
|
raise RuntimeError("fail")
|
|
|
|
def fetch_rate_data(self, asset, start, end):
|
|
raise RuntimeError("fail")
|
|
|
|
def health_check(self):
|
|
return False
|
|
|
|
|
|
def test_fallback_to_mock_when_primary_fails() -> None:
|
|
cfg = {
|
|
"enabled_sources": {"nse": True, "mock": True},
|
|
"source_priority": {"default": ["nse", "mock"]},
|
|
"asset_source_map": {"USDINR": ["nse", "mock"]},
|
|
"reliability_tags": {"nse": "high", "mock": "low"},
|
|
"latency_tags_ms": {"nse": 500, "mock": 1},
|
|
}
|
|
router = DataSourceRouter({"nse": FailingAdapter(), "mock": MockAdapter()}, cfg)
|
|
end = datetime.now(timezone.utc)
|
|
start = end - timedelta(days=30)
|
|
out = router.fetch_price_data("USDINR", start, end)
|
|
assert out.success is True
|
|
assert out.source == "mock"
|