Skip to content

Commit d04662a

Browse files
committed
New Upcoming Dividends API has been added
1 parent 3601c57 commit d04662a

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

eodhd/APIs/UpcomingDividendsAPI.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#APIs/UpcomingDividendsAPI.py
2+
3+
from .BaseAPI import BaseAPI
4+
5+
6+
class UpcomingDividendsAPI(BaseAPI):
7+
8+
def get_upcoming_dividends_data(
9+
self,
10+
api_token: str,
11+
symbol=None,
12+
date_eq=None,
13+
date_from=None,
14+
date_to=None,
15+
page_limit=None,
16+
page_offset=None,
17+
):
18+
"""
19+
Wrapper for the /calendar/dividends endpoint.
20+
21+
Parameters
22+
----------
23+
api_token : str
24+
Your EODHD API token.
25+
symbol : str, optional
26+
Ticker symbol, e.g. "AAPL.US".
27+
Required if `date_eq` is not provided.
28+
date_eq : str, optional
29+
Exact dividend date in format YYYY-MM-DD.
30+
Required if `symbol` is not provided.
31+
date_from : str, optional
32+
Return dividends on or after this date (YYYY-MM-DD).
33+
Usually used together with `symbol`.
34+
date_to : str, optional
35+
Return dividends on or before this date (YYYY-MM-DD).
36+
Usually used together with `symbol`.
37+
page_limit : int, optional
38+
Max results per page (1–1000). Default on API side is 1000.
39+
page_offset : int, optional
40+
Offset for pagination. Default on API side is 0.
41+
"""
42+
43+
# Enforce API requirement: at least one of symbol or date_eq
44+
if symbol is None and date_eq is None:
45+
raise ValueError("Either 'symbol' or 'date_eq' must be provided.")
46+
47+
endpoint = "calendar/dividends"
48+
query_string = ""
49+
50+
if symbol is not None:
51+
query_string += f"&filter[symbol]={symbol}"
52+
if date_eq is not None:
53+
query_string += f"&filter[date_eq]={date_eq}"
54+
if date_from is not None:
55+
query_string += f"&filter[date_from]={date_from}"
56+
if date_to is not None:
57+
query_string += f"&filter[date_to]={date_to}"
58+
if page_limit is not None:
59+
query_string += f"&page[limit]={page_limit}"
60+
if page_offset is not None:
61+
query_string += f"&page[offset]={page_offset}"
62+
63+
return self._rest_get_method(
64+
api_key=api_token,
65+
endpoint=endpoint,
66+
querystring=query_string,
67+
)

0 commit comments

Comments
 (0)