OpenBB-finance/OpenBB · error · OpenBBError
Error: stat must be one of ['open_interest', 'volume', 'dex'
Error message
Error: stat must be one of ['open_interest', 'volume', 'dex', 'gex']
What it means
Raised at the top of OptionsChainsData.filter_data(stat=...) (options_chains_properties.py). The stat parameter only accepts the fixed set ['open_interest', 'volume', 'dex', 'gex'] (case-sensitive); anything else is rejected before any filtering happens. 'dex'/'gex' are uppercased internally for column lookup but must be passed lowercase.
Source
Thrown at openbb_platform/core/openbb_core/provider/utils/options_chains_properties.py:332
This is ignored if stat is not None.
stat: Optional[Literal["open_interest", "volume", "dex", "gex"]]
The statistical metric to filter by.
Other fields are ignored if this is not None.
by: Literal["expiration", "strike"]
Filter the `stat` by expiration or strike, default is "expiration".
If a date is supplied, "strike" is always returned.
This is ignored if `stat` is None.
"""
# pylint: disable=import-outside-toplevel
from numpy import nan
from pandas import DataFrame, concat
stats = ["open_interest", "volume", "dex", "gex"]
_stat = stat.upper() if stat in ["dex", "gex"] else stat
by = "strike" if date is not None else by
if stat is not None:
if stat not in stats:
raise OpenBBError(f"Error: stat must be one of {stats}")
if stat in ["volume", "open_interest"]:
return DataFrame(self._get_stat(stat, moneyness=moneyness, date=date)[by]).replace({nan: None}) # type: ignore
if (
_stat not in self.dataframe.columns
and self.has_greeks
and "underlying_price" not in self.dataframe.columns
):
raise OpenBBError(
f"Error: '{stat}' could not be generated because"
+ " the underlying price was not returned by the provider."
+ " Set manually with 'underlying_price' property."
)
df = DataFrame(self._get_stat(_stat, moneyness=moneyness, date=date)[by]) # type: ignore
return df.replace({nan: None})
df = self.dataframe
if moneyness is not None:View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use exactly one of: 'open_interest', 'volume', 'dex', 'gex' (lowercase)
- Derive the value from the hardcoded list or an enum rather than free text
- For other columns (e.g. 'delta', 'iv'), use the column= parameter path instead of stat=
Example fix
# before df = res.filter_data(stat="DEX") # OpenBBError: stat must be one of [...] # after df = res.filter_data(stat="dex") # or, for an arbitrary column: df = res.filter_data(column="delta", value_min=-0.5, value_max=0.5)
Defensive patterns
Strategy: type-guard
Validate before calling
VALID_STATS = {"open_interest", "volume", "dex", "gex"}
stat = stat.lower() if isinstance(stat, str) else stat
if stat is not None and stat not in VALID_STATS:
raise ValueError(f"stat must be one of {sorted(VALID_STATS)}") Type guard
from typing import Literal, Optional
Stat = Optional[Literal["open_interest", "volume", "dex", "gex"]]
def is_valid_stat(s) -> bool:
return s is None or s in {"open_interest", "volume", "dex", "gex"} Try / catch
from openbb_core.app.model.abstract.error import OpenBBError
try:
df = res.filter_data(stat=stat)
except OpenBBError as e:
if "stat must be one of" in str(e):
df = res.filter_data(stat="volume") # sensible default
else:
raise Prevention
- Type stat as a Literal union so mypy rejects bad values at write time
- Lowercase user input and whitelist-check before calling filter_data
- Use column= (not stat=) for arbitrary columns like 'delta' or 'iv'
When it happens
Trigger: Calling result.filter_data(stat='DEX') or stat='Delta', 'gamma', 'iv', 'oi' — any variant spelling or case mismatch triggers it, because only the exact lowercase four strings are allowed.
Common situations: Passing column-name-style values from the DataFrame ('DEX' computed column) back into filter_data; assuming case-insensitivity like other OpenBB lookups (country/exchange) provide.
Related errors
- 'underlying_price' was not returned in the provider data.
- Error: No validated data was found.
- Greeks are not available.
- Error: '{stat}' could not be generated because the underlyin
- Error: column '{column}' not found in data
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/c583111d015f0373.
Report an issue: GitHub.