rebuild(stage-6): deliver emotion and market pools
This commit is contained in:
@@ -92,6 +92,44 @@ class TushareProvider:
|
||||
unit="yuan/share",
|
||||
)
|
||||
|
||||
def snapshot_inputs(
|
||||
self, trade_date: str, previous_trade_date: str
|
||||
) -> dict[str, ProviderResult | dict[str, Any]]:
|
||||
current = _compact(trade_date)
|
||||
previous = _compact(previous_trade_date)
|
||||
daily = self._query(
|
||||
"daily",
|
||||
{"trade_date": current},
|
||||
"ts_code,trade_date,open,high,low,close,pre_close,pct_chg,vol,amount",
|
||||
unit="mixed",
|
||||
)
|
||||
event_fields = (
|
||||
"trade_date,ts_code,industry,name,close,pct_chg,amount,limit_amount,"
|
||||
"float_mv,total_mv,turnover_ratio,fd_amount,first_time,last_time,"
|
||||
"open_times,up_stat,limit_times"
|
||||
)
|
||||
datasets: dict[str, ProviderResult | dict[str, Any]] = {"daily": daily}
|
||||
datasets["price_limits"] = self._query(
|
||||
"stk_limit",
|
||||
{"trade_date": current},
|
||||
"ts_code,trade_date,up_limit,down_limit",
|
||||
unit="yuan/share",
|
||||
)
|
||||
for key, limit_type, date in (
|
||||
("limit_up", "U", current),
|
||||
("limit_down", "D", current),
|
||||
("broken", "Z", current),
|
||||
("previous_limit_up", "U", previous),
|
||||
):
|
||||
datasets[key] = self._query(
|
||||
"limit_list_d",
|
||||
{"trade_date": date, "limit_type": limit_type},
|
||||
event_fields,
|
||||
unit="mixed",
|
||||
empty_is_complete=True,
|
||||
)
|
||||
return datasets
|
||||
|
||||
def _query(
|
||||
self,
|
||||
api_name: str,
|
||||
@@ -100,6 +138,7 @@ class TushareProvider:
|
||||
*,
|
||||
unit: str,
|
||||
adjustment: str = "not_applicable",
|
||||
empty_is_complete: bool = False,
|
||||
) -> ProviderResult:
|
||||
if not self.configured:
|
||||
raise ProviderError("行情服务尚未配置")
|
||||
@@ -126,7 +165,8 @@ class TushareProvider:
|
||||
data = payload.get("data") or {}
|
||||
columns = data.get("fields") or []
|
||||
rows = tuple(dict(zip(columns, item, strict=False)) for item in data.get("items") or [])
|
||||
return ProviderResult(rows, _metadata(self.source, unit, 1 if rows else 0, adjustment))
|
||||
coverage = 1 if rows or empty_is_complete else 0
|
||||
return ProviderResult(rows, _metadata(self.source, unit, coverage, adjustment))
|
||||
|
||||
def _token(self) -> str:
|
||||
return str(self._token_provider() or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user