Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): add 8 missing tables to the AlphaVantage source (#125268)

Tom Owers5cb8eaef0a1a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index ca26d0e01c8a..10c32d2cc83a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -473,10 +473,10 @@ Diffed against: <https://www.alphavantage.co/documentation/>
- [x] `EARNINGS_CALENDAR` — upcoming earnings dates to join against the earnings table already synced (medium)
- [x] `INSIDER_TRANSACTIONS` — insider buy/sell transaction rows per symbol (medium)
- [x] `INSTITUTIONAL_HOLDINGS` — institutional holder positions per symbol (medium)
-- [ ] `SHARES_OUTSTANDING` — share count history, needed for per-share and market-cap metrics (medium)
-- [ ] `EARNINGS_ESTIMATES` — analyst estimates to compare against reported earnings (medium)
-- [ ] `ETF_PROFILE` — ETF holdings and sector breakdown, the ETF counterpart to company_overview (medium)
-- [ ] `REAL_GDP, CPI, TREASURY_YIELD, FEDERAL_FUNDS_RATE, UNEMPLOYMENT` — macro indicator series commonly joined against equity data (medium)
+- [x] `SHARES_OUTSTANDING` — share count history, needed for per-share and market-cap metrics (medium)
+- [x] `EARNINGS_ESTIMATES` — analyst estimates to compare against reported earnings (medium)
+- [x] `ETF_PROFILE` — ETF holdings and sector breakdown, the ETF counterpart to company_overview (medium)
+- [x] `REAL_GDP, CPI, TREASURY_YIELD, FEDERAL_FUNDS_RATE, UNEMPLOYMENT` — macro indicator series commonly joined against equity data (medium)
Note: Single /query endpoint parameterized by `function=`; the docs page exposes ~140 anchored functions and PostHog surfaces 17. Beyond the listed gaps, TIME_SERIES_INTRADAY, TIME_SERIES_WEEKLY_ADJUSTED/MONTHLY_ADJUSTED, the FX and digital-currency series, the commodities family and ~60 technical indicators are also absent, though indicators are cheaply derivable in the warehouse.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/alpha_vantage.py b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/alpha_vantage.py
index 1458d9b3f137..a052fbe6a91e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/alpha_vantage.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/alpha_vantage.py
@@ -56,6 +56,9 @@ _CSV_ENVELOPE_KEYS = ("Information", "Error Message", "Note")
# dividend), which would otherwise land in the warehouse as literal text in a date column.
_NULL_PLACEHOLDERS = frozenset({"none", "null", ""})
+# The economic series come from FRED, which writes a missing observation (e.g. a market holiday) as ".".
+_ECONOMIC_MISSING_VALUE = "."
+
class AlphaVantageRetryableError(Exception):
pass
@@ -263,7 +266,7 @@ def _parse_earnings(body: dict[str, Any], symbol: str) -> Iterator[dict[str, Any
def _parse_corporate_action(body: dict[str, Any], symbol: str) -> Iterator[dict[str, Any]]:
- # DIVIDENDS and SPLITS both answer with {"symbol": ..., "data": [{...}, ...]}.
+ # DIVIDENDS, SPLITS and SHARES_OUTSTANDING all answer with {"symbol": ..., "data": [{...}, ...]}.
data = body.get("data")
if not isinstance(data, list):
return
@@ -276,6 +279,70 @@ def _parse_corporate_action(body: dict[str, Any], symbol: str) -> Iterator[dict[
yield row
+def _parse_estimates(body: dict[str, Any], symbol: str) -> Iterator[dict[str, Any]]:
+ estimates = body.get("estimates")
+ if not isinstance(estimates, list):
+ return
+ for entry in estimates:
+ if not isinstance(entry, dict):
+ continue
+ yield {
+ **{key: _nullable(value) for key, value in entry.items()},
+ "date": entry["date"],
+ "horizon": entry["horizon"],
+ "symbol": symbol,
+ }
+
+
+def _parse_etf_profile(body: dict[str, Any], symbol: str) -> Iterator[dict[str, Any]]:
+ # A symbol that is not an ETF has no profile to return.
+ if not body:
+ return
+ # `sectors` and `holdings` stay nested, the same as the arrays on `news_sentiment`, so the ETF keeps
+ # one row like its `company_overview` counterpart.
+ row: dict[str, Any] = {key: _nullable(value) for key, value in body.items()}
+ row["symbol"] = symbol
+ yield row
+
+
+def _parse_economic(body: dict[str, Any], maturity: str | None) -> Iterator[dict[str, Any]]:
+ data = body.get("data")
+ if not isinstance(data, list):
+ return
+ series = {key: body.get(key) for key in ("name", "interval", "unit")}
+ for entry in data:
+ if not isinstance(entry, dict):
+ continue
+ value = entry.get("value")
+ row: dict[str, Any] = {
+ **series,
+ "date": entry["date"],
+ "value": None if value == _ECONOMIC_MISSING_VALUE else _nullable(value),
+ }
+ if maturity is not None:
+ row["maturity"] = maturity
+ yield row
+
+
+def _economic_rows(
+ session: requests.Session, api_key: str, config: AlphaVantageEndpointConfig, logger: FilteringBoundLogger
+) -> Iterator[list[dict[str, Any]]]:
+ maturities: tuple[str | None, ...] = config.maturities or (None,)
+ for maturity in maturities:
+ params: dict[str, Any] = {"function": config.function, **config.extra_params, "apikey": api_key}
+ if maturity is not None:
+ params["maturity"] = maturity
+
+ body = _fetch(session, params, logger)
+ if "Error Message" in body:
+ # Not symbol-scoped, so the refusal covers the whole table.
+ raise AlphaVantageAPIError(f"Alpha Vantage API error [{config.function}]: {body['Error Message']}")
+
+ rows = list(_parse_economic(body, maturity))
+ if rows:
+ yield rows
+
+
def _parse_news(body: dict[str, Any], symbol: str) -> Iterator[dict[str, Any]]:
feed = body.get("feed")
if not isinstance(feed, list):
@@ -409,6 +476,8 @@ _PARSERS = {
"reports": _parse_reports,
"earnings": _parse_earnings,
"corporate_action": _parse_corporate_action,
+ "estimates": _parse_estimates,
+ "etf_profile": _parse_etf_profile,
"insider": _parse_insider,
"institutional": _parse_institutional,
}
@@ -491,6 +560,11 @@ def get_rows(
yield from _earnings_calendar_rows(session, api_key, logger)
return
+ if config.kind == "economic":
+ # US macro series, so the configured symbols don't apply.
+ yield from _economic_rows(session, api_key, config, logger)
+ return
+
if config.kind == "news":
time_from = _news_time_from(db_incremental_field_last_value)
for symbol in symbols:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/canonical_descriptions.py
index c624961623a9..852361f513b0 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/canonical_descriptions.py
@@ -253,4 +253,111 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"timeOfTheDay": "Whether the report is expected before market open or after close.",
},
},
+ "shares_outstanding": {
+ "description": "Quarterly shares outstanding for each configured symbol, both diluted and basic; one row per quarter.",
+ "docs_url": "https://www.alphavantage.co/documentation/#shares-outstanding",
+ "columns": {
+ "symbol": "The ticker symbol the share count belongs to.",
+ "date": "End of the quarter the share count is reported for (YYYY-MM-DD).",
+ "shares_outstanding_diluted": "Diluted shares outstanding at the end of the quarter.",
+ "shares_outstanding_basic": "Basic shares outstanding at the end of the quarter.",
+ },
+ },
+ "earnings_estimates": {
+ "description": "Annual and quarterly analyst EPS and revenue estimates for each configured symbol, with analyst counts and revision history; one row per fiscal period.",
+ "docs_url": "https://www.alphavantage.co/documentation/#earnings-estimates",
+ "columns": {
+ "symbol": "The ticker symbol the estimate belongs to.",
+ "date": "End of the fiscal period being estimated (YYYY-MM-DD).",
+ "horizon": "Whether the period is a 'fiscal year' or a 'fiscal quarter'.",
+ "eps_estimate_average": "Average analyst EPS estimate for the period.",
+ "eps_estimate_high": "Highest analyst EPS estimate for the period.",
+ "eps_estimate_low": "Lowest analyst EPS estimate for the period.",
+ "eps_estimate_analyst_count": "Number of analysts contributing an EPS estimate.",
+ "eps_estimate_average_7_days_ago": "Average EPS estimate 7 days ago.",
+ "eps_estimate_average_30_days_ago": "Average EPS estimate 30 days ago.",
+ "eps_estimate_average_60_days_ago": "Average EPS estimate 60 days ago.",
+ "eps_estimate_average_90_days_ago": "Average EPS estimate 90 days ago.",
+ "eps_estimate_revision_up_trailing_7_days": "Number of upward EPS revisions in the last 7 days.",
+ "eps_estimate_revision_down_trailing_7_days": "Number of downward EPS revisions in the last 7 days.",
+ "eps_estimate_revision_up_trailing_30_days": "Number of upward EPS revisions in the last 30 days.",
+ "eps_estimate_revision_down_trailing_30_days": "Number of downward EPS revisions in the last 30 days.",
+ "revenue_estimate_average": "Average analyst revenue estimate for the period.",
+ "revenue_estimate_high": "Highest analyst revenue estimate for the period.",
+ "revenue_estimate_low": "Lowest analyst revenue estimate for the period.",
+ "revenue_estimate_analyst_count": "Number of analysts contributing a revenue estimate.",
+ },
+ },
+ "etf_profile": {
+ "description": "Key metrics of each configured ETF, with its sector allocation and holdings; one row per ETF.",
+ "docs_url": "https://www.alphavantage.co/documentation/#etf-profile",
+ "columns": {
+ "symbol": "The ETF ticker symbol.",
+ "net_assets": "Total net assets of the fund.",
+ "net_expense_ratio": "Net expense ratio of the fund, as a fraction.",
+ "portfolio_turnover": "Portfolio turnover of the fund, as a fraction, or 'n/a'.",
+ "dividend_yield": "Dividend yield of the fund, as a fraction.",
+ "inception_date": "Date the fund started (YYYY-MM-DD).",
+ "last_updated": "When Alpha Vantage last refreshed the profile.",
+ "leveraged": "Whether the fund is leveraged (YES or NO).",
+ "sectors": "Sector allocation of the fund as a JSON array of sector and weight.",
+ "holdings": "Constituents of the fund as a JSON array of symbol, description and weight.",
+ },
+ },
+ "real_gdp": {
+ "description": "Quarterly real gross domestic product of the United States. Not tied to the configured symbols.",
+ "docs_url": "https://www.alphavantage.co/documentation/#real-gdp",
+ "columns": {
+ "date": "Start of the observation period (YYYY-MM-DD).",
+ "value": "Real GDP for the quarter, in billions of chained dollars.",
+ "name": "Full name of the series.",
+ "interval": "Sampling interval of the series.",
+ "unit": "Unit of `value`.",
+ },
+ },
+ "cpi": {
+ "description": "Monthly consumer price index for all urban consumers in the United States. Not tied to the configured symbols.",
+ "docs_url": "https://www.alphavantage.co/documentation/#cpi",
+ "columns": {
+ "date": "Start of the observation period (YYYY-MM-DD).",
+ "value": "Consumer price index for the month (index 1982-1984=100).",
+ "name": "Full name of the series.",
+ "interval": "Sampling interval of the series.",
+ "unit": "Unit of `value`.",
+ },
+ },
+ "treasury_yield": {
+ "description": "Daily market yield on US treasury securities at constant maturities. Not tied to the configured symbols.",
+ "docs_url": "https://www.alphavantage.co/documentation/#treasury-yield",
+ "columns": {
+ "maturity": "Constant maturity of the treasury security (3month, 2year, 5year, 7year, 10year or 30year).",
+ "date": "Start of the observation period (YYYY-MM-DD).",
+ "value": "Yield for the day, in percent.",
+ "name": "Full name of the series.",
+ "interval": "Sampling interval of the series.",
+ "unit": "Unit of `value`.",
+ },
+ },
+ "federal_funds_rate": {
+ "description": "Daily effective federal funds rate of the United States. Not tied to the configured symbols.",
+ "docs_url": "https://www.alphavantage.co/documentation/#interest-rate",
+ "columns": {
+ "date": "Start of the observation period (YYYY-MM-DD).",
+ "value": "Effective federal funds rate for the day, in percent.",
+ "name": "Full name of the series.",
+ "interval": "Sampling interval of the series.",
+ "unit": "Unit of `value`.",
+ },
+ },
+ "unemployment": {
+ "description": "Monthly unemployment rate of the United States. Not tied to the configured symbols.",
+ "docs_url": "https://www.alphavantage.co/documentation/#unemployment",
+ "columns": {
+ "date": "Start of the observation period (YYYY-MM-DD).",
+ "value": "Unemployment rate for the month, in percent of the labor force.",
+ "name": "Full name of the series.",
+ "interval": "Sampling interval of the series.",
+ "unit": "Unit of `value`.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/settings.py
index bbe90c757126..9b421a118fda 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/settings.py
@@ -15,6 +15,9 @@ from products.warehouse_sources.backend.types import IncrementalField, Increment
# so they are full refresh only, and re-pulled rows dedupe on the primary key at merge time.
# NEWS_SENTIMENT (`time_from`) and INSIDER_TRANSACTIONS (`from`) are the two that do filter.
ParseKind = Literal[
+ "economic",
+ "estimates",
+ "etf_profile",
"time_series",
"quote",
"overview",
@@ -53,6 +56,10 @@ class AlphaVantageEndpointConfig:
incremental_fields: list[IncrementalField] = field(default_factory=list)
# The order rows actually arrive in, which the pipeline's cursor watermark trusts.
sort_mode: SortMode | None = "asc"
+ # Fixed query params beyond function/symbol/apikey, e.g. the finest `interval` a series offers.
+ extra_params: dict[str, str] = field(default_factory=dict)
+ # Each value is one request with `maturity=<value>`, tagged onto its rows as a `maturity` column.
+ maturities: tuple[str, ...] = ()
ALPHA_VANTAGE_ENDPOINTS: dict[str, AlphaVantageEndpointConfig] = {
@@ -213,6 +220,78 @@ ALPHA_VANTAGE_ENDPOINTS: dict[str, AlphaVantageEndpointConfig] = {
primary_keys=["symbol", "reportDate", "fiscalDateEnding"],
description="Company earnings scheduled over the next 12 months, with the consensus EPS estimate. Covers the whole market rather than the configured symbols. Full refresh.",
),
+ "shares_outstanding": AlphaVantageEndpointConfig(
+ name="shares_outstanding",
+ function="SHARES_OUTSTANDING",
+ kind="corporate_action",
+ primary_keys=["symbol", "date"],
+ description="Quarterly diluted and basic shares outstanding per symbol. One row per quarter. Full refresh.",
+ should_sync_default=False,
+ ),
+ "earnings_estimates": AlphaVantageEndpointConfig(
+ name="earnings_estimates",
+ function="EARNINGS_ESTIMATES",
+ kind="estimates",
+ # A fiscal year and its last fiscal quarter end on the same date, so `horizon` is part of the key.
+ primary_keys=["symbol", "date", "horizon"],
+ partition_key="date",
+ description="Annual and quarterly analyst EPS and revenue estimates per symbol, with analyst counts and revision history. One row per period. Full refresh.",
+ should_sync_default=False,
+ ),
+ "etf_profile": AlphaVantageEndpointConfig(
+ name="etf_profile",
+ function="ETF_PROFILE",
+ kind="etf_profile",
+ primary_keys=["symbol"],
+ description="ETF metrics (net assets, expense ratio, turnover) with the sector allocation and holdings per symbol (one row per ETF). Full refresh.",
+ should_sync_default=False,
+ ),
+ "real_gdp": AlphaVantageEndpointConfig(
+ name="real_gdp",
+ function="REAL_GDP",
+ kind="economic",
+ primary_keys=["date"],
+ extra_params={"interval": "quarterly"},
+ description="Quarterly real GDP of the United States. Not tied to the configured symbols. Full refresh.",
+ should_sync_default=False,
+ ),
+ "cpi": AlphaVantageEndpointConfig(
+ name="cpi",
+ function="CPI",
+ kind="economic",
+ primary_keys=["date"],
+ extra_params={"interval": "monthly"},
+ description="Monthly consumer price index of the United States. Not tied to the configured symbols. Full refresh.",
+ should_sync_default=False,
+ ),
+ "treasury_yield": AlphaVantageEndpointConfig(
+ name="treasury_yield",
+ function="TREASURY_YIELD",
+ kind="economic",
+ primary_keys=["maturity", "date"],
+ partition_key="date",
+ extra_params={"interval": "daily"},
+ maturities=("3month", "2year", "5year", "7year", "10year", "30year"),
+ description="Daily US treasury yields for the 3-month, 2-, 5-, 7-, 10- and 30-year maturities (one request per maturity). Not tied to the configured symbols. Full refresh.",
+ should_sync_default=False,
+ ),
+ "federal_funds_rate": AlphaVantageEndpointConfig(
+ name="federal_funds_rate",
+ function="FEDERAL_FUNDS_RATE",
+ kind="economic",
+ primary_keys=["date"],
+ extra_params={"interval": "daily"},
+ description="Daily effective federal funds rate of the United States. Not tied to the configured symbols. Full refresh.",
+ should_sync_default=False,
+ ),
+ "unemployment": AlphaVantageEndpointConfig(
+ name="unemployment",
+ function="UNEMPLOYMENT",
+ kind="economic",
+ primary_keys=["date"],
+ description="Monthly unemployment rate of the United States. Not tied to the configured symbols. Full refresh.",
+ should_sync_default=False,
+ ),
}
ENDPOINTS = tuple(ALPHA_VANTAGE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/tests/test_alpha_vantage.py b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/tests/test_alpha_vantage.py
index 8dcd3cac44cd..61183fa5204c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/tests/test_alpha_vantage.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/alpha_vantage/tests/test_alpha_vantage.py
@@ -21,6 +21,9 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.alpha_vant
_normalize_key,
_parse_corporate_action,
_parse_earnings,
+ _parse_economic,
+ _parse_estimates,
+ _parse_etf_profile,
_parse_insider,
_parse_institutional,
_parse_news,
@@ -195,12 +198,172 @@ class TestAlphaVantage:
},
]
- def test_parse_corporate_action_handles_splits_shape(self) -> None:
- body = {"symbol": "IBM", "data": [{"effective_date": "2021-11-04", "split_factor": "1.0460"}]}
- assert list(_parse_corporate_action(body, "IBM")) == [
- {"symbol": "IBM", "effective_date": "2021-11-04", "split_factor": "1.0460"}
+ @parameterized.expand(
+ [
+ (
+ "splits",
+ {"symbol": "IBM", "data": [{"effective_date": "2021-11-04", "split_factor": "1.0460"}]},
+ {"symbol": "IBM", "effective_date": "2021-11-04", "split_factor": "1.0460"},
+ ),
+ (
+ "shares_outstanding",
+ {
+ "symbol": "IBM",
+ "status": "success",
+ "data": [
+ {
+ "date": "2026-06-30",
+ "shares_outstanding_diluted": "951000000",
+ "shares_outstanding_basic": "None",
+ }
+ ],
+ },
+ {
+ "symbol": "IBM",
+ "date": "2026-06-30",
+ "shares_outstanding_diluted": "951000000",
+ "shares_outstanding_basic": None,
+ },
+ ),
+ ]
+ )
+ def test_parse_corporate_action_handles_other_shapes(self, _name: str, body: dict, expected: dict) -> None:
+ assert list(_parse_corporate_action(body, "IBM")) == [expected]
+
+ def test_parse_estimates_keeps_both_horizons_for_one_date(self) -> None:
+ # A fiscal year and its last quarter share an end date, so both rows must survive with their horizon.
+ body = {
+ "symbol": "IBM",
+ "estimates": [
+ {"date": "2026-12-31", "horizon": "fiscal year", "eps_estimate_average": "12.40"},
+ {
+ "date": "2026-12-31",
+ "horizon": "fiscal quarter",
+ "eps_estimate_average": "4.10",
+ "eps_estimate_revision_down_trailing_7_days": None,
+ },
+ "not a dict",
+ ],
+ }
+ assert list(_parse_estimates(body, "IBM")) == [
+ {"symbol": "IBM", "date": "2026-12-31", "horizon": "fiscal year", "eps_estimate_average": "12.40"},
+ {
+ "symbol": "IBM",
+ "date": "2026-12-31",
+ "horizon": "fiscal quarter",
+ "eps_estimate_average": "4.10",
+ "eps_estimate_revision_down_trailing_7_days": None,
+ },
+ ]
+
+ @parameterized.expand(
+ [("missing_estimates", {"symbol": "IBM"}), ("not_a_list", {"symbol": "IBM", "estimates": {}})]
+ )
+ def test_parse_estimates_empty(self, _name: str, body: dict) -> None:
+ assert list(_parse_estimates(body, "IBM")) == []
+
+ def test_parse_etf_profile_yields_one_row_with_nested_arrays(self) -> None:
+ sectors = [{"sector": "INFORMATION TECHNOLOGY", "weight": "0.5"}]
+ holdings = [
+ {"symbol": "ABCD", "description": "EXAMPLE CORP", "weight": "0.08"},
+ {"symbol": "n/a", "description": "CASH", "weight": "0.01"},
+ ]
+ body = {
+ "net_assets": "1000000",
+ "dividend_yield": "None",
+ "inception_date": "2001-02-03",
+ "sectors": sectors,
+ "holdings": holdings,
+ }
+ assert list(_parse_etf_profile(body, "EXMP")) == [
+ {
+ "symbol": "EXMP",
+ "net_assets": "1000000",
+ "dividend_yield": None,
+ "inception_date": "2001-02-03",
+ "sectors": sectors,
+ "holdings": holdings,
+ }
]
+ def test_parse_etf_profile_empty(self) -> None:
+ assert list(_parse_etf_profile({}, "IBM")) == []
+
+ @parameterized.expand(
+ [
+ ("value", "4.25", None, {"value": "4.25"}),
+ # FRED's placeholder for a period with no observation, verbatim from the live API.
+ ("fred_missing_marker", ".", None, {"value": None}),
+ ("null_placeholder", "None", None, {"value": None}),
+ ("maturity_tagged", "4.25", "10year", {"value": "4.25", "maturity": "10year"}),
+ ]
+ )
+ def test_parse_economic(self, _name: str, value: str, maturity: str | None, expected: dict) -> None:
+ body = {
+ "name": "Example Rate",
+ "interval": "monthly",
+ "unit": "percent",
+ "data": [{"date": "2026-09-01", "value": value}],
+ }
+ assert list(_parse_economic(body, maturity)) == [
+ {"name": "Example Rate", "interval": "monthly", "unit": "percent", "date": "2026-09-01", **expected}
+ ]
+
+ @parameterized.expand([("missing_data", {"name": "x"}), ("not_a_list", {"data": {}})])
+ def test_parse_economic_empty(self, _name: str, body: dict) -> None:
+ assert list(_parse_economic(body, None)) == []
+
+ @parameterized.expand(
+ [
+ ("real_gdp", "REAL_GDP", "quarterly", [None]),
+ ("cpi", "CPI", "monthly", [None]),
+ ("unemployment", "UNEMPLOYMENT", None, [None]),
+ ("federal_funds_rate", "FEDERAL_FUNDS_RATE", "daily", [None]),
+ ("treasury_yield", "TREASURY_YIELD", "daily", ["3month", "2year", "5year", "7year", "10year", "30year"]),
+ ]
+ )
+ def test_get_rows_requests_economic_series_once_per_maturity_without_symbols(
+ self, endpoint: str, function: str, interval: str | None, maturities: list[str | None]
+ ) -> None:
+ body = {
+ "name": "Series",
+ "interval": interval,
+ "unit": "percent",
+ "data": [{"date": "2026-09-01", "value": "1"}],
+ }
+ result = _driver("IBM, AAPL").run(endpoint, [ScriptedResponse(json=body) for _ in maturities])
+ assert result.raised is None
+ assert result.params("function") == [function] * len(maturities)
+ assert result.params("interval") == [interval] * len(maturities)
+ assert result.params("maturity") == maturities
+ assert result.params("symbol") == [None] * len(maturities)
+ assert [row.get("maturity") for row in result.rows] == maturities
+
+ def test_get_rows_fails_an_economic_series_on_error_message(self) -> None:
+ result = _driver().run("cpi", [ScriptedResponse(json={"Error Message": "Invalid API call"})])
+ assert isinstance(result.raised, AlphaVantageAPIError)
+ assert result.rows == []
+
+ @parameterized.expand(
+ [
+ ("shares_outstanding", "SHARES_OUTSTANDING", {"data": [{"date": "2026-06-30"}]}),
+ (
+ "earnings_estimates",
+ "EARNINGS_ESTIMATES",
+ {"estimates": [{"date": "2026-12-31", "horizon": "fiscal year"}]},
+ ),
+ ("etf_profile", "ETF_PROFILE", {"net_assets": "1"}),
+ ]
+ )
+ def test_get_rows_fans_new_symbol_tables_out_over_symbols(self, endpoint: str, function: str, body: dict) -> None:
+ result = _driver("EXMP, BADSYM").run(
+ endpoint, [ScriptedResponse(json=body), ScriptedResponse(json={"Error Message": "Invalid API call"})]
+ )
+ assert result.raised is None
+ assert result.params("function") == [function, function]
+ assert result.params("symbol") == ["EXMP", "BADSYM"]
+ assert [row["symbol"] for row in result.rows] == ["EXMP"]
+
@parameterized.expand([("missing_data", {"symbol": "IBM"}), ("not_a_list", {"symbol": "IBM", "data": {}})])
def test_parse_corporate_action_empty(self, _name: str, body: dict) -> None:
assert list(_parse_corporate_action(body, "IBM")) == []
@@ -638,6 +801,12 @@ class TestAlphaVantage:
("news_sentiment", ["symbol", "url"], "time_published"),
("earnings_calendar", ["symbol", "reportDate", "fiscalDateEnding"], None),
("institutional_holdings", ["symbol", "holder_name", "last_reported", "shares_held"], None),
+ ("shares_outstanding", ["symbol", "date"], None),
+ ("earnings_estimates", ["symbol", "date", "horizon"], "date"),
+ ("etf_profile", ["symbol"], None),
+ ("real_gdp", ["date"], None),
+ ("treasury_yield", ["maturity", "date"], "date"),
+ ("federal_funds_rate", ["date"], None),
]
)
def test_alpha_vantage_source_maps_primary_keys_and_partitioning(