Skip to content

Commit 9fe351a

Browse files
Darcy-Lindeclickingbuttons
authored andcommitted
Dividends (#125)
1 parent b70d892 commit 9fe351a

File tree

4 files changed

+140
-6
lines changed

4 files changed

+140
-6
lines changed

polygon/rest/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
from .aggs import AggsClient
22
from .trades import TradesClient
33
from .quotes import QuotesClient
4-
from .reference import MarketsClient, TickersClient, SplitsClient
4+
from .reference import MarketsClient, TickersClient, SplitsClient, DividendsClient
55

66

77
class RESTClient(
8-
AggsClient, TradesClient, QuotesClient, MarketsClient, TickersClient, SplitsClient
8+
AggsClient,
9+
TradesClient,
10+
QuotesClient,
11+
MarketsClient,
12+
TickersClient,
13+
SplitsClient,
14+
DividendsClient,
915
):
1016
pass

polygon/rest/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .markets import *
55
from .tickers import *
66
from .splits import *
7+
from .dividends import *
78

89
from enum import Enum
910

polygon/rest/models/dividends.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import Optional
2+
from enum import Enum
3+
from dataclasses import dataclass
4+
5+
6+
class DividendType(Enum):
7+
CD = "CD"
8+
SC = "SC"
9+
LT = "LT"
10+
ST = "ST"
11+
12+
13+
class Frequency(Enum):
14+
OneTime = 0
15+
Anually = 1
16+
BiAnually = 2
17+
Quarterly = 4
18+
Monthly = 12
19+
20+
21+
@dataclass
22+
class Dividend:
23+
"Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount."
24+
cash_amount: Optional[float] = None
25+
declaration_date: Optional[str] = None
26+
dividend_type: Optional[DividendType] = None
27+
ex_dividend_date: Optional[str] = None
28+
frequency: Optional[Frequency] = None
29+
pay_date: Optional[str] = None
30+
record_date: Optional[str] = None
31+
ticker: Optional[str] = None
32+
33+
@staticmethod
34+
def from_dict(d):
35+
return Dividend(**d)

polygon/rest/reference.py

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from polygon.rest.models.dividends import DividendType
12
from .base import BaseClient
23
from typing import Optional, Any, Dict, List, Union, Iterator
34
from .models import (
@@ -12,6 +13,8 @@
1213
AssetClass,
1314
Locale,
1415
Split,
16+
Dividend,
17+
Frequency,
1518
)
1619
from urllib3 import HTTPResponse
1720

@@ -187,10 +190,10 @@ def list_splits(
187190
ticker_gt: Optional[str] = None,
188191
ticker_gte: Optional[str] = None,
189192
execution_date: Optional[str] = None,
190-
execution_lt: Optional[str] = None,
191-
execution_lte: Optional[str] = None,
192-
execution_gt: Optional[str] = None,
193-
execution_gte: Optional[str] = None,
193+
execution_date_lt: Optional[str] = None,
194+
execution_date_lte: Optional[str] = None,
195+
execution_date_gt: Optional[str] = None,
196+
execution_date_gte: Optional[str] = None,
194197
reverse_split: Optional[bool] = None,
195198
limit: Optional[int] = None,
196199
sort: Optional[Union[str, Sort]] = None,
@@ -227,3 +230,92 @@ def list_splits(
227230
raw=raw,
228231
deserializer=Split.from_dict,
229232
)
233+
234+
235+
class DividendsClient(BaseClient):
236+
def list_dividends(
237+
self,
238+
ticker: Optional[str] = None,
239+
ticker_lt: Optional[str] = None,
240+
ticker_lte: Optional[str] = None,
241+
ticker_gt: Optional[str] = None,
242+
ticker_gte: Optional[str] = None,
243+
ex_dividend_date: Optional[str] = None,
244+
ex_dividend_date_lt: Optional[str] = None,
245+
ex_dividend_date_lte: Optional[str] = None,
246+
ex_dividend_date_gt: Optional[str] = None,
247+
ex_dividend_date_gte: Optional[str] = None,
248+
record_date: Optional[str] = None,
249+
record_date_lt: Optional[str] = None,
250+
record_date_lte: Optional[str] = None,
251+
record_date_gt: Optional[str] = None,
252+
record_date_gte: Optional[str] = None,
253+
declaration_date: Optional[str] = None,
254+
declaration_date_lt: Optional[str] = None,
255+
declaration_date_lte: Optional[str] = None,
256+
declaration_date_gt: Optional[str] = None,
257+
declaration_date_gte: Optional[str] = None,
258+
pay_date: Optional[str] = None,
259+
pay_date_lt: Optional[str] = None,
260+
pay_date_lte: Optional[str] = None,
261+
pay_date_gt: Optional[str] = None,
262+
pay_date_gte: Optional[str] = None,
263+
frequency: Optional[Frequency] = None,
264+
cash_amount: Optional[float] = None,
265+
cash_amount_lt: Optional[float] = None,
266+
cash_amount_lte: Optional[float] = None,
267+
cash_amount_gt: Optional[float] = None,
268+
cash_amount_gte: Optional[float] = None,
269+
dividend_type: Optional[DividendType] = None,
270+
limit: Optional[int] = None,
271+
sort: Optional[Union[str, Sort]] = None,
272+
order: Optional[Union[str, Order]] = None,
273+
params: Optional[Dict[str, Any]] = None,
274+
raw: bool = False,
275+
) -> Union[Iterator[Dividend], HTTPResponse]:
276+
"""
277+
Get a list of historical cash dividends, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount.
278+
279+
:param ticker: Return the dividends that contain this ticker.
280+
:param ticker_lt: Ticker less than
281+
:param ticker_lte: Ticker less than or equal to
282+
:param ticker_gt: Ticker greater than
283+
:param ticker_gte: Ticker greater than or equal to
284+
:param ex_dividend_date: Query by ex-dividend date with the format YYYY-MM-DD.
285+
:param ex_dividend_date_lt: Ex-dividend date less than
286+
:param ex_dividend_date_lte: Ex-dividend date less than or equal to
287+
:param ex_dividend_date_gt: Ex-dividend date greater than
288+
:param ex_dividend_date_gte: Ex-dividend date greater than or equal to
289+
:param record_date: Query by record date with the format YYYY-MM-DD.
290+
:param record_date_lt: Record date less than
291+
:param record_date_lte: Record date less than or equal to
292+
:param record_date_gt: Record date greater than
293+
:param record_date_gte: Record date greater than or equal to
294+
:param declaration_date: Query by declaration date with the format YYYY-MM-DD.
295+
:param declaration_date_lt: Declaration date less than
296+
:param declaration_date_lte: Declaration date less than or equal to
297+
:param declaration_date_gt: Declaration date greater than
298+
:param declaration_date_gte: Declaration date greater than or equal to
299+
:param pay_date: Query by pay date with the format YYYY-MM-DD.
300+
:param pay_date_lt: Pay date less than
301+
:param pay_date_lte: Pay date less than or equal to
302+
:param pay_date_gt: Pay date greater than
303+
:param pay_date_gte: Pay date greater than or equal to
304+
:param frequency: Query by the number of times per year the dividend is paid out. Possible values are 0 (one-time), 1 (annually), 2 (bi-annually), 4 (quarterly), and 12 (monthly).
305+
:param cash_amount: Query by the cash amount of the dividend.
306+
:param dividend_type: Query by the type of dividend. Dividends that have been paid and/or are expected to be paid on consistent schedules are denoted as CD. Special Cash dividends that have been paid that are infrequent or unusual, and/or can not be expected to occur in the future are denoted as SC.
307+
:param limit: Limit the number of results returned, default is 10 and max is 1000.
308+
:param sort: Sort field used for ordering.
309+
:param order: Order results based on the sort field.
310+
:param params: Any additional query params
311+
:param raw: Return raw object instead of results object
312+
:return: List of dividends
313+
"""
314+
url = "/v3/reference/dividends"
315+
316+
return self._paginate(
317+
path=url,
318+
params=self._get_params(self.list_dividends, locals()),
319+
raw=raw,
320+
deserializer=Dividend.from_dict,
321+
)

0 commit comments

Comments
 (0)