From 9618f8b1b698f43fb4bcc7fad38c2a7570e0ebb7 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 13:35:08 -0400 Subject: [PATCH 01/21] add Currencies and Exchanges dataclasses --- polygon/rest/models/markets.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/polygon/rest/models/markets.py b/polygon/rest/models/markets.py index b2b3078f..9fba379b 100644 --- a/polygon/rest/models/markets.py +++ b/polygon/rest/models/markets.py @@ -1,6 +1,16 @@ -from typing import Optional, Dict +from typing import Optional from dataclasses import dataclass +@dataclass +class Currencies: + crypto: Optional[str] = None + fx: Optional[str] = None + +@dataclass +class Exchanges: + nasdaq: Optional[str] = None + nyse: Optional[str] = None + otc: Optional[str] = None @dataclass class MarketHoliday: @@ -21,9 +31,9 @@ def from_dict(d): class MarketStatus: "MarketStatus contains data for the current trading status of the exchanges and overall financial markets." after_hours: Optional[bool] = None - currencies: Optional[Dict[str, str]] = None + currencies: Optional[Currencies] = None early_hours: Optional[bool] = None - exchanges: Optional[Dict[str, str]] = None + exchanges: Optional[Exchanges] = None market: Optional[str] = None server_time: Optional[str] = None From 3c1f5e185ea4efbd9950982d2756cbc8a239f6ca Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 13:38:14 -0400 Subject: [PATCH 02/21] moved ticker enum definitions from tickers to __init__ --- polygon/rest/models/__init__.py | 30 +++++++++++++++++++++++++++++- polygon/rest/models/tickers.py | 21 +-------------------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index a6a9c916..25e7c0e9 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -8,7 +8,6 @@ from enum import Enum - class Sort(Enum): ASC = "asc" DESC = "desc" @@ -17,3 +16,32 @@ class Sort(Enum): class Order(Enum): ASC = "asc" DESC = "desc" + +class Locale(Enum): + US = "us" + GLOBAL = "global" + +class Market(Enum): + STOCKS = "stocks" + CRYPTO = "crypto" + FX = "fx" + + +class AssetClass(Enum): + STOCKS = "stocks" + OPTIONS = "options" + CRYPTO = "crypto" + FX = "fx" + +class DividendType(Enum): + CD = "CD" + SC = "SC" + LT = "LT" + ST = "ST" + +class Frequency(Enum): + OneTime = 0 + Anually = 1 + BiAnually = 2 + Quarterly = 4 + Monthly = 12 diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index d5382a8a..dcccee79 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -1,26 +1,7 @@ from typing import Optional, List -from enum import Enum +from . import Locale, Market, AssetClass from dataclasses import dataclass - -class Locale(Enum): - US = "us" - GLOBAL = "global" - - -class Market(Enum): - STOCKS = "stocks" - CRYPTO = "crypto" - FX = "fx" - - -class AssetClass(Enum): - STOCKS = "stocks" - OPTIONS = "options" - CRYPTO = "crypto" - FX = "fx" - - @dataclass class Address: address1: Optional[str] = None From 17d1a27a52917e7c6b5f7e569821b2f2caa36a70 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 13:43:05 -0400 Subject: [PATCH 03/21] moved enum definitions from dividends to __init__ --- polygon/rest/models/dividends.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index b691812a..ae551147 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -1,23 +1,7 @@ from typing import Optional -from enum import Enum +from . import DividendType, Frequency from dataclasses import dataclass - -class DividendType(Enum): - CD = "CD" - SC = "SC" - 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." From 946c12ea030a2ae0f22801d1e484b5cf77c79cfc Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 14:00:58 -0400 Subject: [PATCH 04/21] update get_ticker_news to list_ticker_news --- polygon/rest/reference.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index bcf0a8ac..06f66bdb 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -127,7 +127,7 @@ def get_ticker_details( path=url, params=params, deserializer=TickerDetails.from_dict, raw=raw ) - def get_ticker_news( + def list_ticker_news( self, ticker: Optional[str] = None, ticker_lt: Optional[str] = None, @@ -141,7 +141,7 @@ def get_ticker_news( published_utc_gte: Optional[str] = None, params: Optional[Dict[str, Any]] = None, raw: bool = False, - ) -> Union[TickerDetails, HTTPResponse]: + ) -> Union[Iterator[TickerNews], HTTPResponse]: """ Get the most recent news articles relating to a stock ticker symbol, including a summary of the article and a link to the original source. :param ticker: Return results that contain this ticker. @@ -155,8 +155,11 @@ def get_ticker_news( """ url = "/v2/reference/news" - return self._get( - path=url, params=params, deserializer=TickerNews.from_dict, raw=raw + return self._paginate( + path=url, + params=self._get_params(self.list_ticker_news, locals()), + raw=raw, + deserializer=TickerNews.from_dict, ) def get_ticker_types( From 2655722735859292f4d8e6f17ff06fe153e8028e Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:12:17 -0400 Subject: [PATCH 05/21] add Condition dataclass --- polygon/rest/models/conditions.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 polygon/rest/models/conditions.py diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py new file mode 100644 index 00000000..75f432f3 --- /dev/null +++ b/polygon/rest/models/conditions.py @@ -0,0 +1,28 @@ +from typing import Optional, List +from . import AssetClass +from dataclasses import dataclass + + +@dataclass +class SipMapping: + CTA: Optional[str] = None + OPRA: Optional[str] = None + UTP: Optional[str] = None + + +@dataclass +class Condition: + "Condition contains data for a condition that Polygon.io uses." + abbreviation: Optional[str] = None + asset_class: Optional[AssetClass] = None + data_types: Optional[List[str]] = None + description: Optional[str] = None + exchange: Optional[int] = None + id: Optional[int] = None + legacy: Optional[bool] = None + name: Optional[str] = None + sip_mapping: Optional[SipMapping] = None + + @staticmethod + def from_dict(d): + return Condition(**d) \ No newline at end of file From 34d130d0327facbe4b8e7a05e53fe6cdafcebd5f Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:13:34 -0400 Subject: [PATCH 06/21] lint __init__ --- polygon/rest/models/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index 25e7c0e9..63bcccc4 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -12,7 +12,6 @@ class Sort(Enum): ASC = "asc" DESC = "desc" - class Order(Enum): ASC = "asc" DESC = "desc" @@ -26,7 +25,6 @@ class Market(Enum): CRYPTO = "crypto" FX = "fx" - class AssetClass(Enum): STOCKS = "stocks" OPTIONS = "options" From 71492f6c8f9cfb6ca5b16d0485b66ff7512ad9df Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:25:35 -0400 Subject: [PATCH 07/21] add conditions import and DataType enum --- polygon/rest/models/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index 63bcccc4..ab9d1460 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -5,6 +5,7 @@ from .tickers import * from .splits import * from .dividends import * +from .conditions import * from enum import Enum @@ -43,3 +44,8 @@ class Frequency(Enum): BiAnually = 2 Quarterly = 4 Monthly = 12 + +class DataType(Enum): + DataTrade = "trade" + DataBBO = "bbo" + DataNBBO = "nbbo" \ No newline at end of file From a79a81ebd6908921c2a76b75865740868e3d1367 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:26:42 -0400 Subject: [PATCH 08/21] remove List import --- polygon/rest/models/conditions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index 75f432f3..06dbe7c7 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -1,5 +1,5 @@ -from typing import Optional, List -from . import AssetClass +from typing import Optional +from . import AssetClass, DataType from dataclasses import dataclass @@ -15,7 +15,7 @@ class Condition: "Condition contains data for a condition that Polygon.io uses." abbreviation: Optional[str] = None asset_class: Optional[AssetClass] = None - data_types: Optional[List[str]] = None + data_types: Optional[DataType] = None description: Optional[str] = None exchange: Optional[int] = None id: Optional[int] = None From 47ce065207478bcca67b717140ef82142bf5e30a Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:38:16 -0400 Subject: [PATCH 09/21] add SIP enum --- polygon/rest/models/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index ab9d1460..f0d32d02 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -48,4 +48,9 @@ class Frequency(Enum): class DataType(Enum): DataTrade = "trade" DataBBO = "bbo" - DataNBBO = "nbbo" \ No newline at end of file + DataNBBO = "nbbo" + +class SIP(Enum): + CTA = "CTA" + UTP = "UTP" + OPRA = "OPRA" \ No newline at end of file From 009fee8ce4f5d86f66015cd783e176129dfaa423 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:38:39 -0400 Subject: [PATCH 10/21] add ConditionsClient --- polygon/rest/reference.py | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index 06f66bdb..e11c7d94 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -1,4 +1,3 @@ -from polygon.rest.models.dividends import DividendType from .base import BaseClient from typing import Optional, Any, Dict, List, Union, Iterator from .models import ( @@ -14,7 +13,11 @@ Locale, Split, Dividend, + DividendType, Frequency, + Condition, + DataType, + SIP, ) from urllib3 import HTTPResponse @@ -77,6 +80,7 @@ def list_tickers( ) -> Union[Iterator[Ticker], HTTPResponse]: """ Query all ticker symbols which are supported by Polygon.io. This API currently includes Stocks/Equities, Crypto, and Forex. + :param ticker: Specify a ticker symbol. Defaults to empty string which queries all tickers. :param ticker_lt: Ticker less than :param ticker_lte: Ticker less than or equal to @@ -115,6 +119,7 @@ def get_ticker_details( ) -> Union[TickerDetails, HTTPResponse]: """ Get a single ticker supported by Polygon.io. This response will have detailed information about the ticker and the company behind it. + :param ticker: The ticker symbol of the asset. :param date: Specify a point in time to get information about the ticker available on that date. When retrieving information from SEC filings, we compare this date with the period of report date on the SEC filing. :param params: Any additional query params @@ -144,6 +149,7 @@ def list_ticker_news( ) -> Union[Iterator[TickerNews], HTTPResponse]: """ Get the most recent news articles relating to a stock ticker symbol, including a summary of the article and a link to the original source. + :param ticker: Return results that contain this ticker. :param published_utc: Return results published on, before, or after this date. :param limit: Limit the number of results returned, default is 10 and max is 1000. @@ -322,3 +328,39 @@ def list_dividends( raw=raw, deserializer=Dividend.from_dict, ) + +class ConditionsClient(BaseClient): + def list_conditions( + self, + asset_class: Optional[Union[str, AssetClass]] = None, + data_type: Optional[Union[str, DataType]] = None, + id: Optional[int] = None, + sip: Optional[Union[str, SIP]] = 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[Condition], HTTPResponse]: + """ + List all conditions that Polygon.io uses. + + :param asset_class: Filter for conditions within a given asset class. + :param data_type: Data types that this condition applies to. + :param id: Filter for conditions with a given ID. + :param sip: Filter by SIP. If the condition contains a mapping for that SIP, the condition will be returned. + :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 conditions + """ + url = "/v3/reference/conditions" + + return self._paginate( + path=url, + params=self._get_params(self.list_conditions, locals()), + raw=raw, + deserializer=Condition.from_dict, + ) \ No newline at end of file From e4a34a96f850b6bdebec4113fa7d530ddb290c29 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:42:10 -0400 Subject: [PATCH 11/21] fix syntax for enums --- polygon/rest/reference.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index e11c7d94..7becbc6b 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -170,8 +170,8 @@ def list_ticker_news( def get_ticker_types( self, - asset_class: Optional[AssetClass] = None, - locale: Optional[Locale] = None, + asset_class: Optional[Union[str, AssetClass]] = None, + locale: Optional[Union[str, Locale]] = None, params: Optional[Dict[str, Any]] = None, raw: bool = False, ) -> Union[TickerTypes, HTTPResponse]: @@ -269,13 +269,13 @@ def list_dividends( pay_date_lte: Optional[str] = None, pay_date_gt: Optional[str] = None, pay_date_gte: Optional[str] = None, - frequency: Optional[Frequency] = None, + frequency: Optional[Union[int, 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, + dividend_type: Optional[Union[str, DividendType]] = None, limit: Optional[int] = None, sort: Optional[Union[str, Sort]] = None, order: Optional[Union[str, Order]] = None, From 6d2b1cb9d6de8b985989d42c8cb3ed26bb90008b Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:42:51 -0400 Subject: [PATCH 12/21] add ConditionsClient import --- polygon/rest/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index a101edf1..9bba8762 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -1,7 +1,7 @@ from .aggs import AggsClient from .trades import TradesClient from .quotes import QuotesClient -from .reference import MarketsClient, TickersClient, SplitsClient, DividendsClient +from .reference import MarketsClient, TickersClient, SplitsClient, DividendsClient, ConditionsClient class RESTClient( @@ -12,5 +12,6 @@ class RESTClient( TickersClient, SplitsClient, DividendsClient, + ConditionsClient ): pass From 5edf8602bb3e395dd8224f668d89e794ea354728 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:43:20 -0400 Subject: [PATCH 13/21] lint --- polygon/rest/__init__.py | 10 ++++++++-- polygon/rest/models/__init__.py | 11 ++++++++++- polygon/rest/models/conditions.py | 2 +- polygon/rest/models/dividends.py | 1 + polygon/rest/models/markets.py | 3 +++ polygon/rest/models/tickers.py | 1 + polygon/rest/reference.py | 3 ++- 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index 9bba8762..7ad46951 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -1,7 +1,13 @@ from .aggs import AggsClient from .trades import TradesClient from .quotes import QuotesClient -from .reference import MarketsClient, TickersClient, SplitsClient, DividendsClient, ConditionsClient +from .reference import ( + MarketsClient, + TickersClient, + SplitsClient, + DividendsClient, + ConditionsClient, +) class RESTClient( @@ -12,6 +18,6 @@ class RESTClient( TickersClient, SplitsClient, DividendsClient, - ConditionsClient + ConditionsClient, ): pass diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index f0d32d02..afbcf81f 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -9,35 +9,42 @@ from enum import Enum + class Sort(Enum): ASC = "asc" DESC = "desc" + class Order(Enum): ASC = "asc" DESC = "desc" + class Locale(Enum): US = "us" GLOBAL = "global" + class Market(Enum): STOCKS = "stocks" CRYPTO = "crypto" FX = "fx" + class AssetClass(Enum): STOCKS = "stocks" OPTIONS = "options" CRYPTO = "crypto" FX = "fx" + class DividendType(Enum): CD = "CD" SC = "SC" LT = "LT" ST = "ST" + class Frequency(Enum): OneTime = 0 Anually = 1 @@ -45,12 +52,14 @@ class Frequency(Enum): Quarterly = 4 Monthly = 12 + class DataType(Enum): DataTrade = "trade" DataBBO = "bbo" DataNBBO = "nbbo" + class SIP(Enum): CTA = "CTA" UTP = "UTP" - OPRA = "OPRA" \ No newline at end of file + OPRA = "OPRA" diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index 06dbe7c7..d3d33563 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -25,4 +25,4 @@ class Condition: @staticmethod def from_dict(d): - return Condition(**d) \ No newline at end of file + return Condition(**d) diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index ae551147..a93d6b6f 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -2,6 +2,7 @@ from . import DividendType, Frequency from dataclasses import dataclass + @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." diff --git a/polygon/rest/models/markets.py b/polygon/rest/models/markets.py index 9fba379b..efa5b2ff 100644 --- a/polygon/rest/models/markets.py +++ b/polygon/rest/models/markets.py @@ -1,17 +1,20 @@ from typing import Optional from dataclasses import dataclass + @dataclass class Currencies: crypto: Optional[str] = None fx: Optional[str] = None + @dataclass class Exchanges: nasdaq: Optional[str] = None nyse: Optional[str] = None otc: Optional[str] = None + @dataclass class MarketHoliday: "MarketHoliday contains data for upcoming market holidays and their open/close times." diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index dcccee79..e489c715 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -2,6 +2,7 @@ from . import Locale, Market, AssetClass from dataclasses import dataclass + @dataclass class Address: address1: Optional[str] = None diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index 7becbc6b..09663216 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -329,6 +329,7 @@ def list_dividends( deserializer=Dividend.from_dict, ) + class ConditionsClient(BaseClient): def list_conditions( self, @@ -363,4 +364,4 @@ def list_conditions( params=self._get_params(self.list_conditions, locals()), raw=raw, deserializer=Condition.from_dict, - ) \ No newline at end of file + ) From 484e5bb7aa15f2fa7795997efe95cb9e6a36358a Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:51:47 -0400 Subject: [PATCH 14/21] add exchanges import and ExchangeType Enum --- polygon/rest/models/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index afbcf81f..ed35d75a 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -6,6 +6,7 @@ from .splits import * from .dividends import * from .conditions import * +from .exchanges import * from enum import Enum @@ -63,3 +64,8 @@ class SIP(Enum): CTA = "CTA" UTP = "UTP" OPRA = "OPRA" + +class ExchangeType(Enum): + exchange = "exchange" + TRF = "TRF" + SIP = "SIP" \ No newline at end of file From 657a4e3ccf4fe630720dc1c7af1c910e3f12595b Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 15:53:31 -0400 Subject: [PATCH 15/21] add Exchange dataClass --- polygon/rest/models/exchanges.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 polygon/rest/models/exchanges.py diff --git a/polygon/rest/models/exchanges.py b/polygon/rest/models/exchanges.py new file mode 100644 index 00000000..78c747b7 --- /dev/null +++ b/polygon/rest/models/exchanges.py @@ -0,0 +1,22 @@ +from typing import Optional +from . import AssetClass, Locale, ExchangeType +from dataclasses import dataclass + + +@dataclass +class Exchange: + "Exchange contains data for a condition that Polygon.io uses." + acronym: Optional[str] = None + asset_class: Optional[AssetClass] = None + id: Optional[int] = None + locale: Optional[Locale] = None + mic: Optional[str] = None + name: Optional[str] = None + operating_mic: Optional[str] = None + participant_id: Optional[str] = None + type: Optional[ExchangeType] = None + url: Optional[str] = None + + @staticmethod + def from_dict(d): + return Exchange(**d) \ No newline at end of file From f0a704b1d59ae39f0134cb1980d38514339f7f26 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 16:15:03 -0400 Subject: [PATCH 16/21] finish dataclass model --- polygon/rest/models/conditions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index d3d33563..e3c64d2f 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -10,6 +10,25 @@ class SipMapping: UTP: Optional[str] = None +@dataclass +class Consolidated: + updates_high_low: Optional[bool] = None + updates_open_close: Optional[bool] = None + updates_volume: Optional[bool] = None + +@dataclass +class MarketCenter: + updates_high_low: Optional[bool] = None + updates_open_close: Optional[bool] = None + updates_volume: Optional[bool] = None + + +@dataclass +class UpdateRules: + consolidated: Optional[Consolidated] = None + market_center: Optional[MarketCenter] = None + + @dataclass class Condition: "Condition contains data for a condition that Polygon.io uses." @@ -22,6 +41,8 @@ class Condition: legacy: Optional[bool] = None name: Optional[str] = None sip_mapping: Optional[SipMapping] = None + Type: Optional[str] = None #todo: 'type' is a keyword so here I capitalized. Should we capital case all dataclasses? + update_rules: Optional[UpdateRules] = None @staticmethod def from_dict(d): From 75bea099f80e198247a7fac18809b00cae21127e Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 16:21:45 -0400 Subject: [PATCH 17/21] add Exchanges CLient --- polygon/rest/reference.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index 09663216..f50bc66a 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -18,6 +18,7 @@ Condition, DataType, SIP, + Exchange ) from urllib3 import HTTPResponse @@ -177,6 +178,7 @@ def get_ticker_types( ) -> Union[TickerTypes, HTTPResponse]: """ List all ticker types that Polygon.io has. + :param asset_class: Filter by asset class. :param locale: Filter by locale. :param params: Any additional query params @@ -365,3 +367,27 @@ def list_conditions( raw=raw, deserializer=Condition.from_dict, ) + +class ExchangesClient(BaseClient): + def get_exchanges( + self, + asset_class: Optional[Union[str, AssetClass]] = None, + locale: Optional[Union[str, Locale]] = None, + params: Optional[Dict[str, Any]] = None, + raw: bool = False + ) -> Union[Exchange, HTTPResponse]: + """ + List all exchanges that Polygon.io knows about. + + :param asset_class: Filter by asset class. + :param locale: Filter by locale. + :param params: Any additional query params + :param raw: Return HTTPResponse object instead of results object + :return: List of quotes + """ + url = "/v3/reference/exchanges" + + return self._get( + path=url, params=params, deserializer=Exchange.from_dict, raw=raw + ) + From de366b5021bcd68c7efe666ef6b1e7681b2e9a41 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 16:22:31 -0400 Subject: [PATCH 18/21] import ExchangesClient --- polygon/rest/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index 7ad46951..d5269d9d 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -7,6 +7,7 @@ SplitsClient, DividendsClient, ConditionsClient, + ExchangesClient ) @@ -19,5 +20,6 @@ class RESTClient( SplitsClient, DividendsClient, ConditionsClient, + ExchangesClient, ): pass From 762bde65698fb49037fe7eb7a4db3ef18106099a Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Wed, 27 Apr 2022 16:22:54 -0400 Subject: [PATCH 19/21] lint --- polygon/rest/__init__.py | 2 +- polygon/rest/models/__init__.py | 3 ++- polygon/rest/models/conditions.py | 5 ++++- polygon/rest/models/exchanges.py | 2 +- polygon/rest/reference.py | 10 +++++----- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/polygon/rest/__init__.py b/polygon/rest/__init__.py index d5269d9d..31f100f1 100644 --- a/polygon/rest/__init__.py +++ b/polygon/rest/__init__.py @@ -7,7 +7,7 @@ SplitsClient, DividendsClient, ConditionsClient, - ExchangesClient + ExchangesClient, ) diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index ed35d75a..e4666be0 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -65,7 +65,8 @@ class SIP(Enum): UTP = "UTP" OPRA = "OPRA" + class ExchangeType(Enum): exchange = "exchange" TRF = "TRF" - SIP = "SIP" \ No newline at end of file + SIP = "SIP" diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index e3c64d2f..84be8ba1 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -16,6 +16,7 @@ class Consolidated: updates_open_close: Optional[bool] = None updates_volume: Optional[bool] = None + @dataclass class MarketCenter: updates_high_low: Optional[bool] = None @@ -41,7 +42,9 @@ class Condition: legacy: Optional[bool] = None name: Optional[str] = None sip_mapping: Optional[SipMapping] = None - Type: Optional[str] = None #todo: 'type' is a keyword so here I capitalized. Should we capital case all dataclasses? + Type: Optional[ + str + ] = None # todo: 'type' is a keyword so here I capitalized. Should we capital case all dataclasses? update_rules: Optional[UpdateRules] = None @staticmethod diff --git a/polygon/rest/models/exchanges.py b/polygon/rest/models/exchanges.py index 78c747b7..11fd2590 100644 --- a/polygon/rest/models/exchanges.py +++ b/polygon/rest/models/exchanges.py @@ -19,4 +19,4 @@ class Exchange: @staticmethod def from_dict(d): - return Exchange(**d) \ No newline at end of file + return Exchange(**d) diff --git a/polygon/rest/reference.py b/polygon/rest/reference.py index f50bc66a..bc0c7487 100644 --- a/polygon/rest/reference.py +++ b/polygon/rest/reference.py @@ -18,7 +18,7 @@ Condition, DataType, SIP, - Exchange + Exchange, ) from urllib3 import HTTPResponse @@ -368,13 +368,14 @@ def list_conditions( deserializer=Condition.from_dict, ) + class ExchangesClient(BaseClient): def get_exchanges( - self, + self, asset_class: Optional[Union[str, AssetClass]] = None, locale: Optional[Union[str, Locale]] = None, - params: Optional[Dict[str, Any]] = None, - raw: bool = False + params: Optional[Dict[str, Any]] = None, + raw: bool = False, ) -> Union[Exchange, HTTPResponse]: """ List all exchanges that Polygon.io knows about. @@ -390,4 +391,3 @@ def get_exchanges( return self._get( path=url, params=params, deserializer=Exchange.from_dict, raw=raw ) - From 1eeb91abf265d4f31b707a6fa6e573c532007045 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Thu, 28 Apr 2022 10:21:32 -0400 Subject: [PATCH 20/21] moved enums to shared file to prevent circular import --- polygon/rest/models/__init__.py | 64 +------------------------------ polygon/rest/models/conditions.py | 2 +- polygon/rest/models/dividends.py | 2 +- polygon/rest/models/exchanges.py | 2 +- polygon/rest/models/shared.py | 62 ++++++++++++++++++++++++++++++ polygon/rest/models/tickers.py | 2 +- 6 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 polygon/rest/models/shared.py diff --git a/polygon/rest/models/__init__.py b/polygon/rest/models/__init__.py index e4666be0..85139477 100644 --- a/polygon/rest/models/__init__.py +++ b/polygon/rest/models/__init__.py @@ -7,66 +7,4 @@ from .dividends import * from .conditions import * from .exchanges import * - -from enum import Enum - - -class Sort(Enum): - ASC = "asc" - DESC = "desc" - - -class Order(Enum): - ASC = "asc" - DESC = "desc" - - -class Locale(Enum): - US = "us" - GLOBAL = "global" - - -class Market(Enum): - STOCKS = "stocks" - CRYPTO = "crypto" - FX = "fx" - - -class AssetClass(Enum): - STOCKS = "stocks" - OPTIONS = "options" - CRYPTO = "crypto" - FX = "fx" - - -class DividendType(Enum): - CD = "CD" - SC = "SC" - LT = "LT" - ST = "ST" - - -class Frequency(Enum): - OneTime = 0 - Anually = 1 - BiAnually = 2 - Quarterly = 4 - Monthly = 12 - - -class DataType(Enum): - DataTrade = "trade" - DataBBO = "bbo" - DataNBBO = "nbbo" - - -class SIP(Enum): - CTA = "CTA" - UTP = "UTP" - OPRA = "OPRA" - - -class ExchangeType(Enum): - exchange = "exchange" - TRF = "TRF" - SIP = "SIP" +from .shared import * diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index 84be8ba1..52b1e6aa 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -1,5 +1,5 @@ from typing import Optional -from . import AssetClass, DataType +from .shared import AssetClass, DataType from dataclasses import dataclass diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index a93d6b6f..f70adf9f 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -1,5 +1,5 @@ from typing import Optional -from . import DividendType, Frequency +from .shared import DividendType, Frequency from dataclasses import dataclass diff --git a/polygon/rest/models/exchanges.py b/polygon/rest/models/exchanges.py index 11fd2590..64527710 100644 --- a/polygon/rest/models/exchanges.py +++ b/polygon/rest/models/exchanges.py @@ -1,5 +1,5 @@ from typing import Optional -from . import AssetClass, Locale, ExchangeType +from .shared import AssetClass, Locale, ExchangeType from dataclasses import dataclass diff --git a/polygon/rest/models/shared.py b/polygon/rest/models/shared.py new file mode 100644 index 00000000..94739b16 --- /dev/null +++ b/polygon/rest/models/shared.py @@ -0,0 +1,62 @@ +from enum import Enum + + +class Sort(Enum): + ASC = "asc" + DESC = "desc" + + +class Order(Enum): + ASC = "asc" + DESC = "desc" + + +class Locale(Enum): + US = "us" + GLOBAL = "global" + + +class Market(Enum): + STOCKS = "stocks" + CRYPTO = "crypto" + FX = "fx" + + +class AssetClass(Enum): + STOCKS = "stocks" + OPTIONS = "options" + CRYPTO = "crypto" + FX = "fx" + + +class DividendType(Enum): + CD = "CD" + SC = "SC" + LT = "LT" + ST = "ST" + + +class Frequency(Enum): + OneTime = 0 + Anually = 1 + BiAnually = 2 + Quarterly = 4 + Monthly = 12 + + +class DataType(Enum): + DataTrade = "trade" + DataBBO = "bbo" + DataNBBO = "nbbo" + + +class SIP(Enum): + CTA = "CTA" + UTP = "UTP" + OPRA = "OPRA" + + +class ExchangeType(Enum): + exchange = "exchange" + TRF = "TRF" + SIP = "SIP" \ No newline at end of file diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index e489c715..681fd669 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -1,5 +1,5 @@ from typing import Optional, List -from . import Locale, Market, AssetClass +from .shared import Locale, Market, AssetClass from dataclasses import dataclass From 9b780bf0d81b63fd1420e816582377fcddaa2a28 Mon Sep 17 00:00:00 2001 From: Darcy Linde <{47221647+Darcy-Linde@users.noreply.github.com}> Date: Thu, 28 Apr 2022 10:22:24 -0400 Subject: [PATCH 21/21] lint --- polygon/rest/models/shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polygon/rest/models/shared.py b/polygon/rest/models/shared.py index 94739b16..c8af7626 100644 --- a/polygon/rest/models/shared.py +++ b/polygon/rest/models/shared.py @@ -59,4 +59,4 @@ class SIP(Enum): class ExchangeType(Enum): exchange = "exchange" TRF = "TRF" - SIP = "SIP" \ No newline at end of file + SIP = "SIP"