feat: complete advisory market data refresh pipeline

This commit is contained in:
Windows
2026-09-11 18:39:57 +08:00
parent 95633188f1
commit 930dd59d67
6 changed files with 327 additions and 5 deletions
@@ -7,6 +7,35 @@ import pytest
from app.infrastructure.fund_market_adapter import EastmoneyFundAdapter
def test_hq_exchange_history_parser_contract(monkeypatch: pytest.MonkeyPatch) -> None:
import hq
class Response:
def raise_for_status(self) -> None:
return None
def json(self) -> dict[str, object]:
return {"data": {"klines": [
"2026-09-09,1.20,1.23,1.24,1.19,100000,1234567.89,4.1,2.5,0.03,1.2",
"2026-09-08,1.20,1.21,1.22,1.19,90000,1000000,2.5,1.0,0.01,1.0",
"malformed",
]}}
def get(*args: object, **kwargs: object) -> Response:
del args, kwargs
return Response()
monkeypatch.setattr(hq.httpx, "get", get)
rows = hq.get_southern_fund_exchange_history("159511", "2026-09-09", "2026-09-09")
assert rows == [{
"fund_code": "159511",
"trade_date": "2026-09-09",
"close_price": "1.23",
"turnover_amount": "1234567.89",
}]
@pytest.mark.asyncio
async def test_adapter_parses_names_quotes_and_history() -> None:
def handler(request: httpx.Request) -> httpx.Response:
@@ -18,6 +18,33 @@ def test_history_sync_row_accepts_a_positive_public_nav() -> None:
assert result["source"] == "eastmoney_hq_nav"
def test_history_sync_row_keeps_verified_exchange_turnover() -> None:
now = datetime.now(UTC).replace(tzinfo=None)
result = ProductHistorySyncService._row(
7,
{"trade_date": "2026-09-09", "nav": "1.234500", "turnover_amount": "123456.78"},
now,
)
assert result is not None
assert result["turnover_amount"] == Decimal("123456.78")
def test_history_sync_row_rejects_negative_or_invalid_turnover() -> None:
now = datetime.now(UTC).replace(tzinfo=None)
negative = ProductHistorySyncService._row(
7, {"trade_date": "2026-09-09", "nav": "1", "turnover_amount": "-1"}, now
)
invalid = ProductHistorySyncService._row(
7, {"trade_date": "2026-09-09", "nav": "1", "turnover_amount": "bad"}, now
)
assert negative is not None and negative["turnover_amount"] is None
assert invalid is not None and invalid["turnover_amount"] is None
def test_history_sync_row_rejects_invalid_or_non_positive_nav() -> None:
now = datetime.now(UTC).replace(tzinfo=None)
@@ -25,4 +52,3 @@ def test_history_sync_row_rejects_invalid_or_non_positive_nav() -> None:
assert ProductHistorySyncService._row(
7, {"trade_date": "2026-09-09", "nav": "0"}, now
) is None