mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-26 11:12:50 +00:00
feat: historical dividends
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Historical Dividends Standard Model."""
|
||||
|
||||
from datetime import date as dateType
|
||||
from typing import List, Optional, Set, Union
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
@@ -24,11 +24,9 @@ class HistoricalDividendsQueryParams(QueryParams):
|
||||
)
|
||||
|
||||
@field_validator("symbol", mode="before", check_fields=False)
|
||||
def upper_symbol(cls, v: Union[str, List[str], Set[str]]): # pylint: disable=E0213
|
||||
def upper_symbol(cls, v: str) -> str:
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
return v.upper()
|
||||
return ",".join([symbol.upper() for symbol in list(v)])
|
||||
return v.upper()
|
||||
|
||||
|
||||
class HistoricalDividendsData(Data):
|
||||
|
||||
@@ -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