Skip to content
18 changes: 18 additions & 0 deletions docs/source/Exceptions.rst
Original file line number Diff line number Diff line change
@@ -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:
13 changes: 4 additions & 9 deletions docs/source/Models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -106,7 +101,7 @@ Ticker
==============================================================
Address
==============================================================
.. autoclass:: polygon.rest.models.Address
.. autoclass:: polygon.rest.models.CompanyAddress

==============================================================
Branding
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
==================
Expand Down
2 changes: 1 addition & 1 deletion polygon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .rest import RESTClient
from .rest.base import NoResults
from .rest.base import NoResultsError
from .websocket import WebSocketClient, AuthError
4 changes: 2 additions & 2 deletions polygon/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
pass


class NoResults(Exception):
class NoResultsError(Exception):
pass


Expand Down Expand Up @@ -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()}"
Expand Down
15 changes: 7 additions & 8 deletions polygon/rest/models/conditions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Optional
from .common import AssetClass, DataType
from typing import Optional, List
from dataclasses import dataclass


Expand Down Expand Up @@ -50,19 +49,19 @@ 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"]),
)


@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[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
Expand All @@ -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"]),
)
5 changes: 2 additions & 3 deletions polygon/rest/models/dividends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Optional
from .common import DividendType, Frequency
from dataclasses import dataclass


Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions polygon/rest/models/exchanges.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from typing import Optional
from .common 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
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
Expand Down
4 changes: 2 additions & 2 deletions polygon/rest/models/markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
12 changes: 6 additions & 6 deletions polygon/rest/models/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
)

Expand All @@ -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
Expand All @@ -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),
)
42 changes: 21 additions & 21 deletions polygon/rest/models/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@dataclass
class SnapshotMin:
class MinuteSnapshot:
"Most recent minute bar."
accumulated_volume: Optional[float] = None
open: Optional[float] = None
Expand All @@ -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),
Expand All @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -121,7 +121,7 @@ class OptionGreeks:

@staticmethod
def from_dict(d):
return OptionGreeks(**d)
return Greeks(**d)


@dataclass
Expand All @@ -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

Expand All @@ -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"]),
)


Expand Down
Loading