gather_financial_snapshot API¶
Shadow Ingest / API Reference / Task-Oriented
gather_financial_snapshot(
stock_codes: list[str],
statement_type: Literal['balance_sheet', 'income_statement', 'cash_flow'],
) -> polars.DataFrame
Returns the latest financial snapshot for each requested stock code.
Before You Run This Example¶
Parameters¶
| Parameter | Required | Default | Allowed values / shape | Meaning |
|---|---|---|---|---|
stock_codes |
yes | — | list of stock codes such as ['000001.XSHE'] |
Which stocks to query |
statement_type |
yes | — | 'income_statement', 'balance_sheet', 'cash_flow' |
Which financial statement snapshot to return |
Discovery Workflow¶
import shadow_ingest as si
trade_dates = si.list_market_calendar(year=2024)
stock_codes = si.list_universe(date=trade_dates[-1])
financial_df = si.gather_financial_snapshot(
stock_codes=stock_codes[:2],
statement_type='income_statement',
)
print(stock_codes[:5])
print(financial_df.columns)
Parameter Notes¶
stock_codes¶
If you are not sure which identifiers are valid, use:
import shadow_ingest as si
stock_codes = si.list_universe(date='2024-01-03')
print(stock_codes[:10])
statement_type¶
Allowed values:
income_statement: income statement snapshotbalance_sheet: balance sheet snapshotcash_flow: cash flow statement snapshot
Different statement_type values return different financial columns.
If you want to inspect the actual columns currently available for one statement type:
import shadow_ingest as si
financial_df = si.gather_financial_snapshot(
stock_codes=['000001.XSHE'],
statement_type='income_statement',
)
print(financial_df.columns)
Copy-Paste Example¶
import shadow_ingest as si
financial_df = si.gather_financial_snapshot(
stock_codes=['000001.XSHE', '600000.XSHG'],
statement_type='income_statement',
)
print(financial_df.head())
print(financial_df.schema)
Example Output¶
┌─────────────┬───────────────┬─────────┬────────────┐
│ stock_code ┆ report_period ┆ revenue ┆ net_profit │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 ┆ f64 │
╞═════════════╪═══════════════╪═════════╪════════════╡
│ 000001.XSHE ┆ 2023-09-30 ┆ 1.27e11 ┆ 3.97e10 │
│ 600000.XSHG ┆ 2023-09-30 ┆ 1.39e11 ┆ 3.67e10 │
└─────────────┴───────────────┴─────────┴────────────┘
Pandas¶
financial_pdf = financial_df.to_pandas()