rebuild(stage-8): deliver market insight workspaces
This commit is contained in:
@@ -12,6 +12,7 @@ from backend.data.contracts import (
|
||||
DataUsage,
|
||||
MarketEntity,
|
||||
ObservationMetadata,
|
||||
ProviderResult,
|
||||
SnapshotState,
|
||||
TradeContext,
|
||||
)
|
||||
@@ -114,6 +115,39 @@ class DataGateway:
|
||||
self._policy.assert_allowed(provider.source, DataUsage.CALCULATION)
|
||||
return provider.snapshot_inputs(trade_date, previous_trade_date)
|
||||
|
||||
def trading_dates(self, through: str, limit: int = 2) -> tuple[str, ...]:
|
||||
requested = _date(through)
|
||||
with self._database.read() as connection:
|
||||
return self._repository.open_dates(connection, requested, limit)
|
||||
|
||||
def stock_directory(self) -> dict[str, dict[str, Any]]:
|
||||
with self._database.read() as connection:
|
||||
rows = self._repository.stock_directory(connection)
|
||||
return {str(row["identifier"]): dict(row) for row in rows}
|
||||
|
||||
def insight_inputs(
|
||||
self,
|
||||
kind: str,
|
||||
trade_date: str,
|
||||
previous_trade_date: str = "",
|
||||
identifier: str = "",
|
||||
) -> dict[str, Any]:
|
||||
provider = self._provider(DataSource.TUSHARE)
|
||||
self._policy.assert_allowed(provider.source, DataUsage.CALCULATION)
|
||||
return provider.market_insight(kind, trade_date, previous_trade_date, identifier)
|
||||
|
||||
def dynamic_auction(
|
||||
self, identifiers: tuple[str, ...], start_time: str, end_time: str
|
||||
) -> ProviderResult:
|
||||
if not identifiers:
|
||||
raise MarketDataUnavailable("动态竞价候选范围为空")
|
||||
provider = self._provider(DataSource.IFIND)
|
||||
self._policy.assert_allowed(provider.source, DataUsage.CALCULATION)
|
||||
result = provider.realtime_snapshots(identifiers, start_time, end_time)
|
||||
if not result.rows:
|
||||
raise MarketDataUnavailable("当前动态竞价快照暂不可用")
|
||||
return result
|
||||
|
||||
def sector_members(
|
||||
self, trade_date: str, sector_name: str, representative: str
|
||||
) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user