diff --git a/docs/source/Exceptions.rst b/docs/source/Exceptions.rst new file mode 100644 index 00000000..c33a122b --- /dev/null +++ b/docs/source/Exceptions.rst @@ -0,0 +1,18 @@ +.. _exceptions_header: + +Exceptions +============================================================== + +============================================================== +AuthError +============================================================== +.. autoclass:: polygon.websocket.__init__.AuthError + :members: + :undoc-members: + +============================================================== +NoResultsError +============================================================== +.. autoclass:: polygon.rest.base.NoResultsError + :members: + :undoc-members: \ No newline at end of file diff --git a/docs/source/Models.rst b/docs/source/Models.rst index 05dcb437..1b41c235 100644 --- a/docs/source/Models.rst +++ b/docs/source/Models.rst @@ -51,12 +51,12 @@ Last Quote ============================================================== Snapshot Min ============================================================== -.. autoclass:: polygon.rest.models.SnapshotMin +.. autoclass:: polygon.rest.models.MinuteSnapshot ============================================================== Snapshot ============================================================== -.. autoclass:: polygon.rest.models.Snapshot +.. autoclass:: polygon.rest.models.TickerSnapshot ============================================================== Day Option Contract Snapshot @@ -68,15 +68,10 @@ Option Details ============================================================== .. autoclass:: polygon.rest.models.OptionDetails -============================================================== -Option Last Quote -============================================================== -.. autoclass:: polygon.rest.models.OptionLastQuote - ============================================================== Option Greeks ============================================================== -.. autoclass:: polygon.rest.models.OptionGreeks +.. autoclass:: polygon.rest.models.Greeks ============================================================== Underlying Asset @@ -106,7 +101,7 @@ Ticker ============================================================== Address ============================================================== -.. autoclass:: polygon.rest.models.Address +.. autoclass:: polygon.rest.models.CompanyAddress ============================================================== Branding diff --git a/docs/source/index.rst b/docs/source/index.rst index efe82e2f..f3925eb1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -18,6 +18,7 @@ This documentation is for the Python client only. For details about the response Models Enums WebSocket-Enums + Exceptions Indices and tables ================== diff --git a/polygon/__init__.py b/polygon/__init__.py index 7fe320e3..39e6f09c 100644 --- a/polygon/__init__.py +++ b/polygon/__init__.py @@ -1,3 +1,3 @@ from .rest import RESTClient -from .rest.base import NoResults +from .rest.base import NoResultsError from .websocket import WebSocketClient, AuthError diff --git a/polygon/rest/base.py b/polygon/rest/base.py index c4da8afa..3f96b963 100644 --- a/polygon/rest/base.py +++ b/polygon/rest/base.py @@ -14,7 +14,7 @@ pass -class NoResults(Exception): +class NoResultsError(Exception): pass @@ -84,7 +84,7 @@ def _get( if result_key: if result_key not in obj: - raise NoResults( + raise NoResultsError( f'Expected key "{result_key}" in response {obj}.' + "Make sure you have sufficient permissions and your request parameters are valid." + f"This is the url that returned no results: {resp.geturl()}" diff --git a/polygon/rest/models/conditions.py b/polygon/rest/models/conditions.py index 32a268d0..e94984a8 100644 --- a/polygon/rest/models/conditions.py +++ b/polygon/rest/models/conditions.py @@ -1,5 +1,4 @@ -from typing import Optional -from .common import AssetClass, DataType +from typing import Optional, List from dataclasses import dataclass @@ -50,10 +49,10 @@ def from_dict(d): return UpdateRules( consolidated=None if "consolidated" not in d - else [Consolidated.from_dict(d["consolidated"])], + else Consolidated.from_dict(d["consolidated"]), market_center=None if "market_center" not in d - else [MarketCenter.from_dict(d["market_center"])], + else MarketCenter.from_dict(d["market_center"]), ) @@ -61,8 +60,8 @@ def from_dict(d): class Condition: "Condition contains data for a condition that Polygon.io uses." abbreviation: Optional[str] = None - asset_class: Optional[AssetClass] = None - data_types: Optional[DataType] = None + asset_class: Optional[str] = None + data_types: Optional[List[str]] = None description: Optional[str] = None exchange: Optional[int] = None id: Optional[int] = None @@ -85,9 +84,9 @@ def from_dict(d): name=d.get("name", None), sip_mapping=None if "sip_mapping" not in d - else [SipMapping.from_dict(d["sip_mapping"])], + else SipMapping.from_dict(d["sip_mapping"]), type=d.get("type", None), update_rules=None if "update_rules" not in d - else [UpdateRules.from_dict(d["update_rules"])], + else UpdateRules.from_dict(d["update_rules"]), ) diff --git a/polygon/rest/models/dividends.py b/polygon/rest/models/dividends.py index 014e5d4d..2ae3ba80 100644 --- a/polygon/rest/models/dividends.py +++ b/polygon/rest/models/dividends.py @@ -1,5 +1,4 @@ from typing import Optional -from .common import DividendType, Frequency from dataclasses import dataclass @@ -8,9 +7,9 @@ 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 + dividend_type: Optional[str] = None ex_dividend_date: Optional[str] = None - frequency: Optional[Frequency] = None + frequency: Optional[int] = None pay_date: Optional[str] = None record_date: Optional[str] = None ticker: Optional[str] = None diff --git a/polygon/rest/models/exchanges.py b/polygon/rest/models/exchanges.py index 1cd0e07d..ef0254fe 100644 --- a/polygon/rest/models/exchanges.py +++ b/polygon/rest/models/exchanges.py @@ -1,5 +1,4 @@ from typing import Optional -from .common import AssetClass, Locale, ExchangeType from dataclasses import dataclass @@ -7,14 +6,14 @@ class Exchange: "Exchange contains data for a condition that Polygon.io uses." acronym: Optional[str] = None - asset_class: Optional[AssetClass] = None + asset_class: Optional[str] = None id: Optional[int] = None - locale: Optional[Locale] = None + locale: Optional[str] = None mic: Optional[str] = None name: Optional[str] = None operating_mic: Optional[str] = None participant_id: Optional[str] = None - type: Optional[ExchangeType] = None + type: Optional[str] = None url: Optional[str] = None @staticmethod diff --git a/polygon/rest/models/markets.py b/polygon/rest/models/markets.py index 248e0e8e..3a3bbbc2 100644 --- a/polygon/rest/models/markets.py +++ b/polygon/rest/models/markets.py @@ -56,11 +56,11 @@ def from_dict(d): after_hours=d.get("after_hours", None), currencies=None if "currencies" not in d - else [MarketCurrencies.from_dict(d["currencies"])], + else MarketCurrencies.from_dict(d["currencies"]), early_hours=d.get("early_hours", None), exchanges=None if "exchanges" not in d - else [MarketExchanges.from_dict(d["exchanges"])], + else MarketExchanges.from_dict(d["exchanges"]), market=d.get("market", None), server_time=d.get("server_time", None), ) diff --git a/polygon/rest/models/quotes.py b/polygon/rest/models/quotes.py index 07082404..c19e711a 100644 --- a/polygon/rest/models/quotes.py +++ b/polygon/rest/models/quotes.py @@ -63,7 +63,7 @@ def from_dict(d): @dataclass -class Last: +class ForexQuote: "Contains data for a forex quote." ask: Optional[float] = None bid: Optional[float] = None @@ -72,19 +72,19 @@ class Last: @staticmethod def from_dict(d): - return Last(**d) + return ForexQuote(**d) @dataclass class LastForexQuote: "ForexLastQuote contains data for the last quote tick for a forex currency pair." - last: Optional[Last] = None + last: Optional[ForexQuote] = None symbol: Optional[str] = None @staticmethod def from_dict(d): return LastForexQuote( - last=None if "last" not in d else Last.from_dict(d["last"]), + last=None if "last" not in d else ForexQuote.from_dict(d["last"]), symbol=d.get("symbol", None), ) @@ -95,7 +95,7 @@ class RealTimeCurrencyConversion: converted: Optional[float] = None from_: Optional[str] = None initial_amount: Optional[float] = None - last: Optional[Last] = None + last: Optional[ForexQuote] = None to: Optional[str] = None @staticmethod @@ -104,6 +104,6 @@ def from_dict(d): converted=d.get("converted", None), from_=d.get("from_", None), initial_amount=d.get("initialAmount", None), - last=None if "last" not in d else Last.from_dict(d["last"]), + last=None if "last" not in d else ForexQuote.from_dict(d["last"]), to=d.get("to", None), ) diff --git a/polygon/rest/models/snapshot.py b/polygon/rest/models/snapshot.py index 2cdbb2bf..db2e3366 100644 --- a/polygon/rest/models/snapshot.py +++ b/polygon/rest/models/snapshot.py @@ -6,7 +6,7 @@ @dataclass -class SnapshotMin: +class MinuteSnapshot: "Most recent minute bar." accumulated_volume: Optional[float] = None open: Optional[float] = None @@ -18,7 +18,7 @@ class SnapshotMin: @staticmethod def from_dict(d): - return SnapshotMin( + return MinuteSnapshot( d.get("av", None), d.get("o", None), d.get("h", None), @@ -30,12 +30,12 @@ def from_dict(d): @dataclass -class Snapshot: +class TickerSnapshot: "Contains the most up-to-date market data for all traded ticker symbols." day: Optional[Agg] = None last_quote: Optional[LastQuote] = None last_trade: Optional[LastTrade] = None - min: Optional[SnapshotMin] = None + min: Optional[MinuteSnapshot] = None prev_day: Optional[Agg] = None ticker: Optional[str] = None todays_change: Optional[float] = None @@ -44,16 +44,16 @@ class Snapshot: @staticmethod def from_dict(d): - return Snapshot( - day=None if "day" not in d else [Agg.from_dict(d["day"])], + return TickerSnapshot( + day=None if "day" not in d else Agg.from_dict(d["day"]), last_quote=None if "last_quote" not in d - else [LastQuote.from_dict(d["last_quote"])], + else LastQuote.from_dict(d["last_quote"]), last_trade=None if "last_trade" not in d - else [LastTrade.from_dict(d["last_trade"])], - min=None if "min" not in d else [SnapshotMin.from_dict(d["min"])], - prev_day=None if "prev_day" not in d else [Agg.from_dict(d["prev_day"])], + else LastTrade.from_dict(d["last_trade"]), + min=None if "min" not in d else MinuteSnapshot.from_dict(d["min"]), + prev_day=None if "prev_day" not in d else Agg.from_dict(d["prev_day"]), ticker=d.get("ticker", None), todays_change=d.get("todays_change", None), todays_change_percent=d.get("todays_change_percent", None), @@ -96,7 +96,7 @@ def from_dict(d): @dataclass -class OptionLastQuote: +class LastQuoteOptionContractSnapshot: "Contains data for the most recent quote in an options contract." ask: Optional[float] = None ask_size: Optional[float] = None @@ -108,11 +108,11 @@ class OptionLastQuote: @staticmethod def from_dict(d): - return OptionLastQuote(**d) + return LastQuoteOptionContractSnapshot(**d) @dataclass -class OptionGreeks: +class Greeks: "Contains data for the greeks in an options contract." delta: Optional[float] = None gamma: Optional[float] = None @@ -121,7 +121,7 @@ class OptionGreeks: @staticmethod def from_dict(d): - return OptionGreeks(**d) + return Greeks(**d) @dataclass @@ -144,9 +144,9 @@ class OptionContractSnapshot: break_even_price: Optional[float] = None day: Optional[DayOptionContractSnapshot] = None details: Optional[OptionDetails] = None - greeks: Optional[OptionGreeks] = None + greeks: Optional[Greeks] = None implied_volatility: Optional[float] = None - last_quote: Optional[OptionLastQuote] = None + last_quote: Optional[LastQuoteOptionContractSnapshot] = None open_interest: Optional[float] = None underlying_asset: Optional[UnderlyingAsset] = None @@ -156,19 +156,19 @@ def from_dict(d): break_even_price=d.get("break_even_price", None), day=None if "day" not in d - else [DayOptionContractSnapshot.from_dict(d["day"])], + else DayOptionContractSnapshot.from_dict(d["day"]), details=None if "details" not in d - else [OptionDetails.from_dict(d["details"])], - greeks=None if "greeks" not in d else [OptionGreeks.from_dict(d["greeks"])], + else OptionDetails.from_dict(d["details"]), + greeks=None if "greeks" not in d else Greeks.from_dict(d["greeks"]), implied_volatility=d.get("implied_volatility", None), last_quote=None if "last_quote" not in d - else [OptionLastQuote.from_dict(d["last_quote"])], + else LastQuoteOptionContractSnapshot.from_dict(d["last_quote"]), open_interest=d.get("open_interest", None), underlying_asset=None if "underlying_asset" not in d - else [UnderlyingAsset.from_dict(d["underlying_asset"])], + else UnderlyingAsset.from_dict(d["underlying_asset"]), ) diff --git a/polygon/rest/models/tickers.py b/polygon/rest/models/tickers.py index ee4712b1..4f650baa 100644 --- a/polygon/rest/models/tickers.py +++ b/polygon/rest/models/tickers.py @@ -1,5 +1,4 @@ from typing import Optional, List -from .common import Locale, Market, AssetClass from dataclasses import dataclass @@ -23,6 +22,9 @@ class Branding: "Contains branding data for a ticker detail." icon_url: Optional[str] = None logo_url: Optional[str] = None + accent_color: Optional[str] = None + light_color: Optional[str] = None + dark_color: Optional[str] = None @staticmethod def from_dict(d): @@ -54,8 +56,8 @@ class Ticker: base_currency_name: Optional[str] = None delisted_utc: Optional[str] = None last_updated_utc: Optional[str] = None - locale: Optional[Locale] = None - market: Optional[Market] = None + locale: Optional[str] = None + market: Optional[str] = None name: Optional[str] = None primary_exchange: Optional[str] = None share_class_figi: Optional[str] = None @@ -81,8 +83,8 @@ class TickerDetails: ticker_root: Optional[str] = None homepage_url: Optional[str] = None list_date: Optional[str] = None - locale: Optional[Locale] = None - market: Optional[Market] = None + locale: Optional[str] = None + market: Optional[str] = None market_cap: Optional[float] = None name: Optional[str] = None phone_number: Optional[str] = None @@ -159,7 +161,7 @@ def from_dict(d): published_utc=d.get("published_utc", None), publisher=None if "publisher" not in d - else [Publisher.from_dict(d["publisher"])], + else Publisher.from_dict(d["publisher"]), tickers=d.get("tickers", None), title=d.get("title", None), ) @@ -168,10 +170,10 @@ def from_dict(d): @dataclass class TickerTypes: "TickerTypes contains data for ticker types." - asset_class: Optional[AssetClass] = None + asset_class: Optional[str] = None code: Optional[str] = None description: Optional[str] = None - locale: Optional[Locale] = None + locale: Optional[str] = None @staticmethod def from_dict(d): diff --git a/polygon/rest/snapshot.py b/polygon/rest/snapshot.py index 2aa5eefa..8784ae39 100644 --- a/polygon/rest/snapshot.py +++ b/polygon/rest/snapshot.py @@ -1,7 +1,7 @@ from .base import BaseClient from typing import Optional, Any, Dict, List, Union from .models import ( - Snapshot, + TickerSnapshot, Direction, OptionContractSnapshot, SnapshotMarketType, @@ -17,7 +17,7 @@ def get_snapshot_all( tickers: Optional[Union[str, List[str]]] = None, params: Optional[Dict[str, Any]] = None, raw: bool = False, - ) -> Union[List[Snapshot], HTTPResponse]: + ) -> Union[List[TickerSnapshot], HTTPResponse]: """ Get the most up-to-date market data for all traded stock symbols. @@ -33,7 +33,7 @@ def get_snapshot_all( return self._get( path=url, params=self._get_params(self.get_snapshot_all, locals()), - deserializer=Snapshot.from_dict, + deserializer=TickerSnapshot.from_dict, raw=raw, result_key="tickers", ) @@ -44,7 +44,7 @@ def get_snapshot_direction( market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, - ) -> Union[List[Snapshot], HTTPResponse]: + ) -> Union[List[TickerSnapshot], HTTPResponse]: """ Get the most up-to-date market data for the current top 20 gainers or losers of the day in the stocks/equities markets. @@ -61,7 +61,7 @@ def get_snapshot_direction( path=url, params=self._get_params(self.get_snapshot_direction, locals()), result_key="tickers", - deserializer=Snapshot.from_dict, + deserializer=TickerSnapshot.from_dict, raw=raw, ) @@ -71,7 +71,7 @@ def get_snapshot_ticker( market_type: Optional[Union[str, SnapshotMarketType]] = "stocks", params: Optional[Dict[str, Any]] = None, raw: bool = False, - ) -> Union[Snapshot, HTTPResponse]: + ) -> Union[TickerSnapshot, HTTPResponse]: """ Get the most up-to-date market data for all traded stock symbols. @@ -86,7 +86,7 @@ def get_snapshot_ticker( path=url, params=self._get_params(self.get_snapshot_ticker, locals()), result_key="ticker", - deserializer=Snapshot.from_dict, + deserializer=TickerSnapshot.from_dict, raw=raw, ) diff --git a/test_rest/test_conditions.py b/test_rest/test_conditions.py index f3495a6e..3ec5bb00 100644 --- a/test_rest/test_conditions.py +++ b/test_rest/test_conditions.py @@ -21,26 +21,20 @@ def test_list_conditions(self): id=1, legacy=None, name="Acquisition", - sip_mapping=[SipMapping(CTA=None, OPRA=None, UTP="A")], + sip_mapping=SipMapping(CTA=None, OPRA=None, UTP="A"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -51,26 +45,20 @@ def test_list_conditions(self): id=2, legacy=None, name="Average Price Trade", - sip_mapping=[SipMapping(CTA="B", OPRA=None, UTP="W")], + sip_mapping=SipMapping(CTA="B", OPRA=None, UTP="W"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=False, - updates_open_close=False, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=False, - updates_open_close=False, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=False, + updates_open_close=False, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=False, + updates_open_close=False, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -81,26 +69,20 @@ def test_list_conditions(self): id=3, legacy=None, name="Automatic Execution", - sip_mapping=[SipMapping(CTA="E", OPRA=None, UTP=None)], + sip_mapping=SipMapping(CTA="E", OPRA=None, UTP=None), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -111,26 +93,20 @@ def test_list_conditions(self): id=4, legacy=None, name="Bunched Trade", - sip_mapping=[SipMapping(CTA=None, OPRA=None, UTP="B")], + sip_mapping=SipMapping(CTA=None, OPRA=None, UTP="B"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -141,26 +117,20 @@ def test_list_conditions(self): id=5, legacy=None, name="Bunched Sold Trade", - sip_mapping=[SipMapping(CTA=None, OPRA=None, UTP="G")], + sip_mapping=SipMapping(CTA=None, OPRA=None, UTP="G"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=False, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=False, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=False, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=False, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -171,26 +141,20 @@ def test_list_conditions(self): id=6, legacy=True, name="CAP Election", - sip_mapping=[SipMapping(CTA="I", OPRA=None, UTP=None)], + sip_mapping=SipMapping(CTA="I", OPRA=None, UTP=None), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -201,26 +165,20 @@ def test_list_conditions(self): id=7, legacy=None, name="Cash Sale", - sip_mapping=[SipMapping(CTA="C", OPRA=None, UTP="C")], + sip_mapping=SipMapping(CTA="C", OPRA=None, UTP="C"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=False, - updates_open_close=False, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=False, - updates_open_close=False, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=False, + updates_open_close=False, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=False, + updates_open_close=False, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -231,26 +189,20 @@ def test_list_conditions(self): id=8, legacy=None, name="Closing Prints", - sip_mapping=[SipMapping(CTA=None, OPRA=None, UTP="6")], + sip_mapping=SipMapping(CTA=None, OPRA=None, UTP="6"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -261,26 +213,20 @@ def test_list_conditions(self): id=9, legacy=None, name="Cross Trade", - sip_mapping=[SipMapping(CTA="X", OPRA=None, UTP="X")], + sip_mapping=SipMapping(CTA="X", OPRA=None, UTP="X"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=True, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=True, + updates_volume=True, + ), + ), ), Condition( abbreviation=None, @@ -291,26 +237,20 @@ def test_list_conditions(self): id=10, legacy=None, name="Derivatively Priced", - sip_mapping=[SipMapping(CTA="4", OPRA=None, UTP="4")], + sip_mapping=SipMapping(CTA="4", OPRA=None, UTP="4"), type="sale_condition", - update_rules=[ - UpdateRules( - consolidated=[ - Consolidated( - updates_high_low=True, - updates_open_close=False, - updates_volume=True, - ) - ], - market_center=[ - MarketCenter( - updates_high_low=True, - updates_open_close=False, - updates_volume=True, - ) - ], - ) - ], + update_rules=UpdateRules( + consolidated=Consolidated( + updates_high_low=True, + updates_open_close=False, + updates_volume=True, + ), + market_center=MarketCenter( + updates_high_low=True, + updates_open_close=False, + updates_volume=True, + ), + ), ), ] self.assertEqual(conditions, expected) diff --git a/test_rest/test_markets.py b/test_rest/test_markets.py index 2e8b767b..64614101 100644 --- a/test_rest/test_markets.py +++ b/test_rest/test_markets.py @@ -130,13 +130,11 @@ def test_get_market_status(self): status = self.c.get_market_status() expected = MarketStatus( after_hours=None, - currencies=[MarketCurrencies(crypto="open", fx="open")], + currencies=MarketCurrencies(crypto="open", fx="open"), early_hours=None, - exchanges=[ - MarketExchanges( - nasdaq="extended-hours", nyse="extended-hours", otc="extended-hours" - ) - ], + exchanges=MarketExchanges( + nasdaq="extended-hours", nyse="extended-hours", otc="extended-hours" + ), market="extended-hours", server_time=None, ) diff --git a/test_rest/test_quotes.py b/test_rest/test_quotes.py index 98470149..17b701b6 100644 --- a/test_rest/test_quotes.py +++ b/test_rest/test_quotes.py @@ -2,7 +2,7 @@ from polygon.rest.models import ( Quote, LastQuote, - Last, + ForexQuote, LastForexQuote, RealTimeCurrencyConversion, ) @@ -339,7 +339,9 @@ def test_get_last_quote(self): def test_get_last_forex_quote(self): last_forex = self.c.get_last_forex_quote("AUD", "USD") expected = LastForexQuote( - last=Last(ask=0.69527, bid=0.6952, exchange=48, timestamp=1652193694000), + last=ForexQuote( + ask=0.69527, bid=0.6952, exchange=48, timestamp=1652193694000 + ), symbol="AUD/USD", ) @@ -351,7 +353,7 @@ def test_get_real_time_currency_conversion(self): converted=69.31, from_=None, initial_amount=100, - last=Last( + last=ForexQuote( ask=1.4436264, bid=1.4427932, exchange=48, timestamp=1652195426000 ), to="USD", diff --git a/test_rest/test_snapshots.py b/test_rest/test_snapshots.py index e882ac4d..f8f4023a 100644 --- a/test_rest/test_snapshots.py +++ b/test_rest/test_snapshots.py @@ -1,13 +1,13 @@ from polygon.rest.models import ( - Snapshot, + TickerSnapshot, OptionContractSnapshot, SnapshotTickerFullBook, Agg, - SnapshotMin, + MinuteSnapshot, OrderBookQuote, UnderlyingAsset, - OptionLastQuote, - OptionGreeks, + LastQuoteOptionContractSnapshot, + Greeks, OptionDetails, DayOptionContractSnapshot, ) @@ -18,32 +18,28 @@ class SnapshotsTest(BaseTest): def test_get_snapshot_all(self): snapshots = self.c.get_snapshot_all() expected = [ - Snapshot( - day=[ - Agg( - open=20.64, - high=20.64, - low=20.506, - close=20.506, - volume=37216, - vwap=20.616, - timestamp=None, - transactions=None, - ) - ], + TickerSnapshot( + day=Agg( + open=20.64, + high=20.64, + low=20.506, + close=20.506, + volume=37216, + vwap=20.616, + timestamp=None, + transactions=None, + ), last_quote=None, last_trade=None, - min=[ - SnapshotMin( - accumulated_volume=37216, - open=20.506, - high=20.506, - low=20.506, - close=20.506, - volume=5000, - vwap=20.5105, - ) - ], + min=MinuteSnapshot( + accumulated_volume=37216, + open=20.506, + high=20.506, + low=20.506, + close=20.506, + volume=5000, + vwap=20.5105, + ), prev_day=None, ticker="BCAT", todays_change=None, @@ -53,104 +49,30 @@ def test_get_snapshot_all(self): ] self.assertEqual(snapshots, expected) - def test_get_snapshot_direction(self): - snapshots = self.c.get_snapshot_direction("gainers") - expected = [ - Snapshot( - day=[ - Agg( - open=6.81, - high=6.99, - low=6.4, - close=6.42, - volume=115782, - vwap=6.656, - timestamp=None, - transactions=None, - ) - ], - last_quote=None, - last_trade=None, - min=[ - SnapshotMin( - accumulated_volume=115689, - open=6.49, - high=6.542, - low=6.42, - close=6.42, - volume=2671, - vwap=6.4604, - ) - ], - prev_day=None, - ticker="NVCN", - todays_change=None, - todays_change_percent=None, - updated=1651251360000000000, - ), - Snapshot( - day=[ - Agg( - open=4.31, - high=4.95, - low=4.21, - close=4.2107, - volume=453199, - vwap=4.4181, - timestamp=None, - transactions=None, - ) - ], - last_quote=None, - last_trade=None, - min=[ - SnapshotMin( - accumulated_volume=453189, - open=4.2107, - high=4.2107, - low=4.2107, - close=4.2107, - volume=1012, - vwap=4.2107, - ) - ], - prev_day=None, - ticker="BIOL", - todays_change=None, - todays_change_percent=None, - updated=1651251789345841015, - ), - ] - self.assertEqual(snapshots, expected) - def test_get_snapshot_ticker(self): snapshots = self.c.get_snapshot_ticker("AAPL") - expected = Snapshot( - day=[ - Agg( - open=161.84, - high=166.2, - low=159.8, - close=160.315, - volume=68840127, - vwap=162.7124, - timestamp=None, - transactions=None, - ) - ], + expected = TickerSnapshot( + day=Agg( + open=161.84, + high=166.2, + low=159.8, + close=160.315, + volume=68840127, + vwap=162.7124, + timestamp=None, + transactions=None, + ), last_quote=None, last_trade=None, - min=[ - SnapshotMin( - accumulated_volume=68834255, - open=160.71, - high=160.71, - low=160.3, - close=160.3, - volume=197226, - vwap=160.5259, - ) - ], + min=MinuteSnapshot( + accumulated_volume=68834255, + open=160.71, + high=160.71, + low=160.3, + close=160.3, + volume=197226, + vwap=160.5259, + ), prev_day=None, ticker="AAPL", todays_change=None, @@ -163,60 +85,50 @@ def test_get_snapshot_option(self): snapshots = self.c.get_snapshot_option("AAPL", "O:AAPL230616C00150000") expected = OptionContractSnapshot( break_even_price=179.075, - day=[ - DayOptionContractSnapshot( - change=-2.3999999999999986, - change_percent=-7.643312101910824, - close=29, - high=32.25, - last_updated=1651204800000000000, - low=29, - open=29.99, - previous_close=31.4, - volume=8, - vwap=30.7738, - ) - ], - details=[ - OptionDetails( - contract_type="call", - exercise_style="american", - expiration_date="2023-06-16", - shares_per_contract=100, - strike_price=150, - ticker="O:AAPL230616C00150000", - ) - ], - greeks=[ - OptionGreeks( - delta=0.6436614934293701, - gamma=0.0061735291012820675, - theta=-0.028227189324641973, - vega=0.6381159723175714, - ) - ], + day=DayOptionContractSnapshot( + change=-2.3999999999999986, + change_percent=-7.643312101910824, + close=29, + high=32.25, + last_updated=1651204800000000000, + low=29, + open=29.99, + previous_close=31.4, + volume=8, + vwap=30.7738, + ), + details=OptionDetails( + contract_type="call", + exercise_style="american", + expiration_date="2023-06-16", + shares_per_contract=100, + strike_price=150, + ticker="O:AAPL230616C00150000", + ), + greeks=Greeks( + delta=0.6436614934293701, + gamma=0.0061735291012820675, + theta=-0.028227189324641973, + vega=0.6381159723175714, + ), implied_volatility=0.3570277203465058, - last_quote=[ - OptionLastQuote( - ask=29.25, - ask_size=209, - bid=28.9, - bid_size=294, - last_updated=1651254260800059648, - midpoint=29.075, - timeframe="REAL-TIME", - ) - ], + last_quote=LastQuoteOptionContractSnapshot( + ask=29.25, + ask_size=209, + bid=28.9, + bid_size=294, + last_updated=1651254260800059648, + midpoint=29.075, + timeframe="REAL-TIME", + ), open_interest=8133, - underlying_asset=[ - UnderlyingAsset( - change_to_break_even=19.11439999999999, - last_updated=1651254263172073152, - price=159.9606, - ticker="AAPL", - timeframe="REAL-TIME", - ) - ], + underlying_asset=UnderlyingAsset( + change_to_break_even=19.11439999999999, + last_updated=1651254263172073152, + price=159.9606, + ticker="AAPL", + timeframe="REAL-TIME", + ), ) self.assertEqual(snapshots, expected) diff --git a/test_rest/test_tickers.py b/test_rest/test_tickers.py index 7e534c46..b965753e 100644 --- a/test_rest/test_tickers.py +++ b/test_rest/test_tickers.py @@ -140,14 +140,12 @@ def test_list_ticker_news(self): image_url="https://images.mktw.net/im-533637/social", keywords=None, published_utc="2022-04-28T17:08:00Z", - publisher=[ - Publisher( - favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", - homepage_url="https://www.marketwatch.com/", - logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", - name="MarketWatch", - ) - ], + publisher=Publisher( + favicon_url="https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico", + homepage_url="https://www.marketwatch.com/", + logo_url="https://s3.polygon.io/public/assets/news/logos/marketwatch.svg", + name="MarketWatch", + ), tickers=["MSFT", "TSN", "NFLX", "AMZN"], title="Theres a big hole in the Feds theory of inflation—incomes are falling at a record 10.9 rate", )