From b8e52a5244c36f37cf84bcb3d0fb8a00f9a636c1 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:06:07 -0400 Subject: [PATCH 1/6] add dividend dataclass --- polygon/rest/models/dividends.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 polygon/rest/models/dividends.py diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py new file mode 100644 index 00000000..5e9dbdba --- /dev/null +++ b/polygon/rest/models/dividends.py @@ -0,0 +1,25 @@ +from typing import Optional +from enum import Enum +from dataclasses import dataclass + +class DividendType(Enum): + CD = "CD" + SC = "SC" + LT = "LT" + ST = "ST" + +@dataclass +class Dividend: + "Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount." + cash_amount: Optional[float] = None + declaration_date: Optional[str] = None + dividend_type: Optional[DividendType] = None + ex_dividend_date: Optional[str] = None + frequency: Optional[int] = None + pay_date: Optional[str] = None + record_date: Optional[str] = None + ticker: Optional[str] = None + + @staticmethod + def from_dict(d): + return Dividend(**d) \ No newline at end of file From 67fc5f8ff26750d88696ad249fcb9e0c68d03332 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:06:40 -0400 Subject: [PATCH 2/6] add dividends import statement --- polygon/rest/models/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index 914cc3a6..a6a9c916 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -4,6 +4,7 @@ from .markets import * from .tickers import * from .splits import * +from .dividends import * from enum import Enum From 1deb7b5759f818563631b3a71db6f0b3e944263e Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:30:44 -0400 Subject: [PATCH 3/6] add Frequency enum --- polygon/rest/models/dividends.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index 5e9dbdba..792e9a44 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -8,6 +8,13 @@ class DividendType(Enum): LT = "LT" ST = "ST" +class Frequency(Enum): + OneTime = 0 + Anually = 1 + BiAnually = 2 + Quarterly = 4 + Monthly = 12 + @dataclass class Dividend: "Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount." @@ -15,7 +22,7 @@ class Dividend: declaration_date: Optional[str] = None dividend_type: Optional[DividendType] = None ex_dividend_date: Optional[str] = None - frequency: Optional[int] = None + frequency: Optional[Frequency] = None pay_date: Optional[str] = None record_date: Optional[str] = None ticker: Optional[str] = None From 65acf6dca2828e14c5ae5149c370a5e5cd99e437 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:34:05 -0400 Subject: [PATCH 4/6] add dividends client --- polygon/rest/reference.py | 99 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index 40c915f2..67a9ab72 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -1,3 +1,4 @@ +from polygon.rest.models.dividends import DividendType from .base import BaseClient from typing import Optional, Any, Dict, List, Union, Iterator from .models import ( @@ -12,6 +13,8 @@ AssetClass, Locale, Split, + Dividend, + Frequency ) from urllib3 import HTTPResponse @@ -187,10 +190,10 @@ def list_splits( ticker_gt: Optional[str] = None, ticker_gte: Optional[str] = None, execution_date: Optional[str] = None, - execution_lt: Optional[str] = None, - execution_lte: Optional[str] = None, - execution_gt: Optional[str] = None, - execution_gte: Optional[str] = None, + execution_date_lt: Optional[str] = None, + execution_date_lte: Optional[str] = None, + execution_date_gt: Optional[str] = None, + execution_date_gte: Optional[str] = None, reverse_split: Optional[bool] = None, limit: Optional[int] = None, sort: Optional[Union[str, Sort]] = None, @@ -227,3 +230,91 @@ def list_splits( raw=raw, deserializer=Split.from_dict, ) + +class DividendsClient(BaseClient): + def list_dividends( + self, + ticker: Optional[str] = None, + ticker_lt: Optional[str] = None, + ticker_lte: Optional[str] = None, + ticker_gt: Optional[str] = None, + ticker_gte: Optional[str] = None, + ex_dividend_date: Optional[str] = None, + ex_dividend_date_lt: Optional[str] = None, + ex_dividend_date_lte: Optional[str] = None, + ex_dividend_date_gt: Optional[str] = None, + ex_dividend_date_gte: Optional[str] = None, + record_date: Optional[str] = None, + record_date_lt: Optional[str] = None, + record_date_lte: Optional[str] = None, + record_date_gt: Optional[str] = None, + record_date_gte: Optional[str] = None, + declaration_date: Optional[str] = None, + declaration_date_lt: Optional[str] = None, + declaration_date_lte: Optional[str] = None, + declaration_date_gt: Optional[str] = None, + declaration_date_gte: Optional[str] = None, + pay_date: Optional[str] = None, + pay_date_lt: Optional[str] = None, + pay_date_lte: Optional[str] = None, + pay_date_gt: Optional[str] = None, + pay_date_gte: Optional[str] = None, + frequency: Optional[Frequency] = None, + cash_amount: Optional[float] = None, + cash_amount_lt: Optional[float] = None, + cash_amount_lte: Optional[float] = None, + cash_amount_gt: Optional[float] = None, + cash_amount_gte: Optional[float] = None, + dividend_type: Optional[DividendType] = None, + limit: Optional[int] = None, + sort: Optional[Union[str, Sort]] = None, + order: Optional[Union[str, Order]] = None, + params: Optional[Dict[str, Any]] = None, + raw: bool = False, + ) -> Union[Iterator[Dividend], HTTPResponse]: + """ + Get a list of historical cash dividends, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount. + + :param ticker: Return the dividends that contain this ticker. + :param ticker_lt: Ticker less than + :param ticker_lte: Ticker less than or equal to + :param ticker_gt: Ticker greater than + :param ticker_gte: Ticker greater than or equal to + :param ex_dividend_date: Query by ex-dividend date with the format YYYY-MM-DD. + :param ex_dividend_date_lt: Ex-dividend date less than + :param ex_dividend_date_lte: Ex-dividend date less than or equal to + :param ex_dividend_date_gt: Ex-dividend date greater than + :param ex_dividend_date_gte: Ex-dividend date greater than or equal to + :param record_date: Query by record date with the format YYYY-MM-DD. + :param record_date_lt: Record date less than + :param record_date_lte: Record date less than or equal to + :param record_date_gt: Record date greater than + :param record_date_gte: Record date greater than or equal to + :param declaration_date: Query by declaration date with the format YYYY-MM-DD. + :param declaration_date_lt: Declaration date less than + :param declaration_date_lte: Declaration date less than or equal to + :param declaration_date_gt: Declaration date greater than + :param declaration_date_gte: Declaration date greater than or equal to + :param pay_date: Query by pay date with the format YYYY-MM-DD. + :param pay_date_lt: Pay date less than + :param pay_date_lte: Pay date less than or equal to + :param pay_date_gt: Pay date greater than + :param pay_date_gte: Pay date greater than or equal to + :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). + :param cash_amount: Query by the cash amount of the dividend. + :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. + :param limit: Limit the number of results returned, default is 10 and max is 1000. + :param sort: Sort field used for ordering. + :param order: Order results based on the sort field. + :param params: Any additional query params + :param raw: Return raw object instead of results object + :return: List of dividends + """ + url = "/v3/reference/dividends" + + return self._paginate( + path=url, + params=self._get_params(self.list_dividends, locals()), + raw=raw, + deserializer=Dividend.from_dict, + ) From bf3ffb3c8ba1a5b5f02d0ec97196e9aa5d562c3f Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:34:37 -0400 Subject: [PATCH 5/6] add dividendsclient import --- polygon/rest/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index a04cf1d0..dad273d4 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -1,10 +1,10 @@ from .aggs import AggsClient from .trades import TradesClient from .quotes import QuotesClient -from .reference import MarketsClient, TickersClient, SplitsClient +from .reference import MarketsClient, TickersClient, SplitsClient, DividendsClient class RESTClient( - AggsClient, TradesClient, QuotesClient, MarketsClient, TickersClient, SplitsClient + AggsClient, TradesClient, QuotesClient, MarketsClient, TickersClient, SplitsClient, DividendsClient ): pass From 4c4c3321ae1738fbf91bcc350c646985ed42f51e Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 12:35:01 -0400 Subject: [PATCH 6/6] lint --- polygon/rest/__init__.py | 8 +++++++- polygon/rest/models/dividends.py | 5 ++++- polygon/rest/reference.py | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index dad273d4..a101edf1 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -5,6 +5,12 @@ class RESTClient( - AggsClient, TradesClient, QuotesClient, MarketsClient, TickersClient, SplitsClient, DividendsClient + AggsClient, + TradesClient, + QuotesClient, + MarketsClient, + TickersClient, + SplitsClient, + DividendsClient, ): pass diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index 792e9a44..b691812a 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -2,12 +2,14 @@ from enum import Enum from dataclasses import dataclass + class DividendType(Enum): CD = "CD" SC = "SC" LT = "LT" ST = "ST" + class Frequency(Enum): OneTime = 0 Anually = 1 @@ -15,6 +17,7 @@ class Frequency(Enum): Quarterly = 4 Monthly = 12 + @dataclass class Dividend: "Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount." @@ -29,4 +32,4 @@ class Dividend: @staticmethod def from_dict(d): - return Dividend(**d) \ No newline at end of file + return Dividend(**d) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index 67a9ab72..bcf0a8ac 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -14,7 +14,7 @@ Locale, Split, Dividend, - Frequency + Frequency, ) from urllib3 import HTTPResponse @@ -231,6 +231,7 @@ def list_splits( deserializer=Split.from_dict, ) + class DividendsClient(BaseClient): def list_dividends( self,