fix(HEL-494): enforce datahub as sole website market boundary

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总管
2026-09-09 00:22:27 +08:00
co-authored by multica-agent
parent 8a7d1f3698
commit c9e2d30780
22 changed files with 212 additions and 216 deletions
-9
View File
@@ -96,15 +96,6 @@ class DatahubClient:
{"api_name": api_name, "params": params or {}, "fields": fields},
)
def put_ifind_credentials(self, refresh_token: str, access_token: str = "") -> DatahubResponse:
return self.post(
"/v1/credentials/ifind",
{
"ifind_refresh_token": refresh_token,
"ifind_access_token": access_token,
},
)
def sector_quote(self, code: str, date: str = "") -> DatahubResponse:
payload: dict[str, Any] = {"code": code}
if date:
-23
View File
@@ -1,6 +1,5 @@
from __future__ import annotations
import logging
import time
from typing import Any
@@ -8,9 +7,6 @@ from backend.data.datahub.bridge import DatahubBridge
from backend.data.datahub.errors import DatahubError
from backend.data.providers.ifind_client import IfindError
LOGGER = logging.getLogger("xiaobai.datahub")
class HubIfindProxy:
"""Website-facing iFinD facade. Talks only to xiaobai-datahub."""
@@ -18,20 +14,12 @@ class HubIfindProxy:
self._datahub = datahub
self._status: dict[str, Any] | None = None
self._status_at = 0.0
self._pending: tuple[str, str] | None = None
@property
def configured(self) -> bool:
return bool(self.status().get("configured"))
def set_credentials(self, refresh_token: str, access_token: str = "") -> None:
self._pending = (str(refresh_token or ""), str(access_token or ""))
self._status = None
self._status_at = 0.0
self._flush_credentials()
def status(self) -> dict[str, Any]:
self._flush_credentials()
now = time.monotonic()
if self._status is not None and now - self._status_at < 30:
return dict(self._status)
@@ -139,18 +127,7 @@ class HubIfindProxy:
"sample_time": str(payload[0].get("time") or "") if payload else "",
}
def _flush_credentials(self) -> None:
pending = self._pending
if pending is None or not self._datahub.settings.token:
return
try:
self._datahub.client.put_ifind_credentials(pending[0], pending[1])
self._pending = None
except DatahubError:
LOGGER.warning("datahub ifind credential push failed; will retry")
def _rows(self, api_name: str, params: dict[str, Any]) -> list[dict[str, Any]]:
self._flush_credentials()
try:
response = self._datahub.client.query_api(api_name, params)
except DatahubError as exc:
-4
View File
@@ -1,6 +1,5 @@
from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime
from typing import Any
@@ -95,11 +94,8 @@ class DataGateway:
def build_data_gateway(
credentials: dict[str, object],
tushare_token_supplier: Callable[[], str] | None = None,
datahub_settings: DatahubSettings | None = None,
) -> DataGateway:
# Website Tushare tokens are not used to assemble market clients.
del tushare_token_supplier
policy = DataSourcePolicy.load()
settings = datahub_settings or DatahubSettings.load(credentials=credentials)
datahub_client = DatahubClient(settings)