mirror of
https://github.com/QuantEngines/fx_quant_engine.git
synced 2026-07-29 11:27:46 +00:00
Initial commit: fx_quant_engine and options_quant_engine scaffold
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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"
|
||||
Reference in New Issue
Block a user