Skip to content

Commit d85091f

Browse files
authored
Audited models for missing fields, removed unneeded arrays and enum imports, add Exceptions docs (#176)
1 parent f16a7e6 commit d85091f

18 files changed

+315
-452
lines changed

docs/source/Exceptions.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. _exceptions_header:
2+
3+
Exceptions
4+
==============================================================
5+
6+
==============================================================
7+
AuthError
8+
==============================================================
9+
.. autoclass:: polygon.websocket.__init__.AuthError
10+
:members:
11+
:undoc-members:
12+
13+
==============================================================
14+
NoResultsError
15+
==============================================================
16+
.. autoclass:: polygon.rest.base.NoResultsError
17+
:members:
18+
:undoc-members:

docs/source/Models.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ Last Quote
5151
==============================================================
5252
Snapshot Min
5353
==============================================================
54-
.. autoclass:: polygon.rest.models.SnapshotMin
54+
.. autoclass:: polygon.rest.models.MinuteSnapshot
5555

5656
==============================================================
5757
Snapshot
5858
==============================================================
59-
.. autoclass:: polygon.rest.models.Snapshot
59+
.. autoclass:: polygon.rest.models.TickerSnapshot
6060

6161
==============================================================
6262
Day Option Contract Snapshot
@@ -68,15 +68,10 @@ Option Details
6868
==============================================================
6969
.. autoclass:: polygon.rest.models.OptionDetails
7070

71-
==============================================================
72-
Option Last Quote
73-
==============================================================
74-
.. autoclass:: polygon.rest.models.OptionLastQuote
75-
7671
==============================================================
7772
Option Greeks
7873
==============================================================
79-
.. autoclass:: polygon.rest.models.OptionGreeks
74+
.. autoclass:: polygon.rest.models.Greeks
8075

8176
==============================================================
8277
Underlying Asset
@@ -106,7 +101,7 @@ Ticker
106101
==============================================================
107102
Address
108103
==============================================================
109-
.. autoclass:: polygon.rest.models.Address
104+
.. autoclass:: polygon.rest.models.CompanyAddress
110105

111106
==============================================================
112107
Branding

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This documentation is for the Python client only. For details about the response
1818
Models
1919
Enums
2020
WebSocket-Enums
21+
Exceptions
2122

2223
Indices and tables
2324
==================

polygon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .rest import RESTClient
2-
from .rest.base import NoResults
2+
from .rest.base import NoResultsError
33
from .websocket import WebSocketClient, AuthError

polygon/rest/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
pass
1515

1616

17-
class NoResults(Exception):
17+
class NoResultsError(Exception):
1818
pass
1919

2020

@@ -84,7 +84,7 @@ def _get(
8484

8585
if result_key:
8686
if result_key not in obj:
87-
raise NoResults(
87+
raise NoResultsError(
8888
f'Expected key "{result_key}" in response {obj}.'
8989
+ "Make sure you have sufficient permissions and your request parameters are valid."
9090
+ f"This is the url that returned no results: {resp.geturl()}"

polygon/rest/models/conditions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from typing import Optional
2-
from .common import AssetClass, DataType
1+
from typing import Optional, List
32
from dataclasses import dataclass
43

54

@@ -50,19 +49,19 @@ def from_dict(d):
5049
return UpdateRules(
5150
consolidated=None
5251
if "consolidated" not in d
53-
else [Consolidated.from_dict(d["consolidated"])],
52+
else Consolidated.from_dict(d["consolidated"]),
5453
market_center=None
5554
if "market_center" not in d
56-
else [MarketCenter.from_dict(d["market_center"])],
55+
else MarketCenter.from_dict(d["market_center"]),
5756
)
5857

5958

6059
@dataclass
6160
class Condition:
6261
"Condition contains data for a condition that Polygon.io uses."
6362
abbreviation: Optional[str] = None
64-
asset_class: Optional[AssetClass] = None
65-
data_types: Optional[DataType] = None
63+
asset_class: Optional[str] = None
64+
data_types: Optional[List[str]] = None
6665
description: Optional[str] = None
6766
exchange: Optional[int] = None
6867
id: Optional[int] = None
@@ -85,9 +84,9 @@ def from_dict(d):
8584
name=d.get("name", None),
8685
sip_mapping=None
8786
if "sip_mapping" not in d
88-
else [SipMapping.from_dict(d["sip_mapping"])],
87+
else SipMapping.from_dict(d["sip_mapping"]),
8988
type=d.get("type", None),
9089
update_rules=None
9190
if "update_rules" not in d
92-
else [UpdateRules.from_dict(d["update_rules"])],
91+
else UpdateRules.from_dict(d["update_rules"]),
9392
)

polygon/rest/models/dividends.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import Optional
2-
from .common import DividendType, Frequency
32
from dataclasses import dataclass
43

54

@@ -8,9 +7,9 @@ class Dividend:
87
"Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount."
98
cash_amount: Optional[float] = None
109
declaration_date: Optional[str] = None
11-
dividend_type: Optional[DividendType] = None
10+
dividend_type: Optional[str] = None
1211
ex_dividend_date: Optional[str] = None
13-
frequency: Optional[Frequency] = None
12+
frequency: Optional[int] = None
1413
pay_date: Optional[str] = None
1514
record_date: Optional[str] = None
1615
ticker: Optional[str] = None

polygon/rest/models/exchanges.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from typing import Optional
2-
from .common import AssetClass, Locale, ExchangeType
32
from dataclasses import dataclass
43

54

65
@dataclass
76
class Exchange:
87
"Exchange contains data for a condition that Polygon.io uses."
98
acronym: Optional[str] = None
10-
asset_class: Optional[AssetClass] = None
9+
asset_class: Optional[str] = None
1110
id: Optional[int] = None
12-
locale: Optional[Locale] = None
11+
locale: Optional[str] = None
1312
mic: Optional[str] = None
1413
name: Optional[str] = None
1514
operating_mic: Optional[str] = None
1615
participant_id: Optional[str] = None
17-
type: Optional[ExchangeType] = None
16+
type: Optional[str] = None
1817
url: Optional[str] = None
1918

2019
@staticmethod

polygon/rest/models/markets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def from_dict(d):
5656
after_hours=d.get("after_hours", None),
5757
currencies=None
5858
if "currencies" not in d
59-
else [MarketCurrencies.from_dict(d["currencies"])],
59+
else MarketCurrencies.from_dict(d["currencies"]),
6060
early_hours=d.get("early_hours", None),
6161
exchanges=None
6262
if "exchanges" not in d
63-
else [MarketExchanges.from_dict(d["exchanges"])],
63+
else MarketExchanges.from_dict(d["exchanges"]),
6464
market=d.get("market", None),
6565
server_time=d.get("server_time", None),
6666
)

polygon/rest/models/quotes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def from_dict(d):
6363

6464

6565
@dataclass
66-
class Last:
66+
class ForexQuote:
6767
"Contains data for a forex quote."
6868
ask: Optional[float] = None
6969
bid: Optional[float] = None
@@ -72,19 +72,19 @@ class Last:
7272

7373
@staticmethod
7474
def from_dict(d):
75-
return Last(**d)
75+
return ForexQuote(**d)
7676

7777

7878
@dataclass
7979
class LastForexQuote:
8080
"ForexLastQuote contains data for the last quote tick for a forex currency pair."
81-
last: Optional[Last] = None
81+
last: Optional[ForexQuote] = None
8282
symbol: Optional[str] = None
8383

8484
@staticmethod
8585
def from_dict(d):
8686
return LastForexQuote(
87-
last=None if "last" not in d else Last.from_dict(d["last"]),
87+
last=None if "last" not in d else ForexQuote.from_dict(d["last"]),
8888
symbol=d.get("symbol", None),
8989
)
9090

@@ -95,7 +95,7 @@ class RealTimeCurrencyConversion:
9595
converted: Optional[float] = None
9696
from_: Optional[str] = None
9797
initial_amount: Optional[float] = None
98-
last: Optional[Last] = None
98+
last: Optional[ForexQuote] = None
9999
to: Optional[str] = None
100100

101101
@staticmethod
@@ -104,6 +104,6 @@ def from_dict(d):
104104
converted=d.get("converted", None),
105105
from_=d.get("from_", None),
106106
initial_amount=d.get("initialAmount", None),
107-
last=None if "last" not in d else Last.from_dict(d["last"]),
107+
last=None if "last" not in d else ForexQuote.from_dict(d["last"]),
108108
to=d.get("to", None),
109109
)

0 commit comments

Comments
 (0)