rebuild(stage-8): deliver market insight workspaces
This commit is contained in:
@@ -92,6 +92,51 @@ class IfindProvider:
|
||||
def sector_members(self, representative: str, trade_date: str) -> ProviderResult:
|
||||
raise ProviderError("iFinD is not the Shenwan constituent authority")
|
||||
|
||||
def market_insight(
|
||||
self,
|
||||
kind: str,
|
||||
trade_date: str,
|
||||
previous_trade_date: str = "",
|
||||
identifier: str = "",
|
||||
) -> dict[str, ProviderResult | None]:
|
||||
raise ProviderError("iFinD只承担许可范围内的动态竞价快照")
|
||||
|
||||
def realtime_snapshots(
|
||||
self, identifiers: tuple[str, ...], start_time: str, end_time: str
|
||||
) -> ProviderResult:
|
||||
rows: list[dict[str, Any]] = []
|
||||
for offset in range(0, len(identifiers), 80):
|
||||
batch = identifiers[offset : offset + 80]
|
||||
if not batch:
|
||||
continue
|
||||
payload = self._request(
|
||||
"snap_shot",
|
||||
{
|
||||
"codes": ",".join(batch),
|
||||
"indicators": "latest,volume,amount,preClose,turnoverRatio,volumeRatio,"
|
||||
"bid1,bidSize1,ask1,askSize1",
|
||||
"starttime": start_time,
|
||||
"endtime": end_time,
|
||||
},
|
||||
)
|
||||
rows.extend(_result(payload, "mixed", "not_applicable", SnapshotState.REALTIME).rows)
|
||||
covered = {
|
||||
str(row.get("thscode") or "") for row in rows if row.get("thscode")
|
||||
}
|
||||
return ProviderResult(
|
||||
tuple(rows),
|
||||
ObservationMetadata(
|
||||
source=self.source,
|
||||
observed_at=datetime.now(SHANGHAI),
|
||||
unit="mixed",
|
||||
adjustment="not_applicable",
|
||||
freshness_seconds=0,
|
||||
coverage=min(len(covered) / max(len(identifiers), 1), 1),
|
||||
state=SnapshotState.REALTIME,
|
||||
usage=DataUsage.CALCULATION,
|
||||
),
|
||||
)
|
||||
|
||||
def _request(self, endpoint: str, body: dict[str, Any]) -> dict[str, Any]:
|
||||
if not self.configured:
|
||||
raise ProviderError("实时行情服务尚未配置")
|
||||
|
||||
Reference in New Issue
Block a user