mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-28 20:23:36 +00:00
feat: historical dividends
This commit is contained in:
@@ -23,6 +23,8 @@ class FMPHistoricalDividendsQueryParams(HistoricalDividendsQueryParams):
|
||||
Source: https://site.financialmodelingprep.com/developer/docs/#Historical-Dividends
|
||||
"""
|
||||
|
||||
__validator_dict__ = {"check_single": ("symbol",)}
|
||||
|
||||
|
||||
class FMPHistoricalDividendsData(HistoricalDividendsData):
|
||||
"""FMP Historical Dividends Data."""
|
||||
|
||||
@@ -23,6 +23,7 @@ class IntrinioHistoricalDividendsQueryParams(HistoricalDividendsQueryParams):
|
||||
"""
|
||||
|
||||
__alias_dict__ = {"limit": "page_size"}
|
||||
__validator_dict__ = {"check_single": ("symbol",)}
|
||||
|
||||
limit: Optional[int] = Field(
|
||||
default=100,
|
||||
|
||||
@@ -17,6 +17,8 @@ _warn = warnings.warn
|
||||
class YFinanceHistoricalDividendsQueryParams(HistoricalDividendsQueryParams):
|
||||
"""YFinance Historical Dividends Query."""
|
||||
|
||||
__validator_dict__ = {"check_single": ("symbol",)}
|
||||
|
||||
|
||||
class YFinanceHistoricalDividendsData(HistoricalDividendsData):
|
||||
"""YFinance Historical Dividends Data. All data is split-adjusted."""
|
||||
@@ -43,19 +45,12 @@ class YFinanceHistoricalDividendsFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
"""Extract the raw data from YFinance."""
|
||||
symbols = query.symbol.split(",")
|
||||
symbol = symbols[0]
|
||||
if len(symbols) > 1:
|
||||
_warn(
|
||||
"Lists of symbols are not allowed for this function. "
|
||||
f"Multiple symbols will be ignored in favour of the first symbol. {symbol}"
|
||||
)
|
||||
try:
|
||||
ticker = Ticker(symbol).get_dividends()
|
||||
ticker = Ticker(query.symbol).get_dividends()
|
||||
if isinstance(ticker, List) and not ticker or ticker.empty: # type: ignore
|
||||
raise ValueError(f"No dividend data found for {symbol}")
|
||||
raise ValueError(f"No dividend data found for {query.symbol}")
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Error getting data for {symbol}: {e}") from e
|
||||
raise RuntimeError(f"Error getting data for {query.symbol}: {e}") from e
|
||||
ticker.index.name = "ex_dividend_date"
|
||||
ticker.name = "amount" # type: ignore
|
||||
if query.start_date is not None:
|
||||
|
||||
Reference in New Issue
Block a user