Skip to content

Commit 53c87c9

Browse files
author
clickingbuttons
authored
address most of caleb feedback (#169)
* address most of caleb feedback * beta * fix financials models and test * backlink for aggs
1 parent e4d80e8 commit 53c87c9

File tree

8 files changed

+250
-275
lines changed

8 files changed

+250
-275
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Python client for the [Polygon.io API](https://polygon.io).
77

88
## Install
99

10-
`pip install polygon-api-client`
10+
`pip install polygon-api-client~=1.0.0b`
1111

1212
Requires Python >= 3.7.
1313

docs/source/Aggs.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Aggs
66
===========
77
Get aggs
88
===========
9+
10+
- `Stock aggs`_
11+
- `Options aggs`_
12+
- `Forex aggs`_
13+
- `Crypto aggs`_
14+
915
.. automethod:: polygon.RESTClient.get_aggs
1016

1117
============================
@@ -23,3 +29,7 @@ Get previous close agg
2329
============================
2430
.. automethod:: polygon.RESTClient.get_previous_close_agg
2531

32+
.. _Stock aggs: https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__range__multiplier___timespan___from___to
33+
.. _Options aggs: https://polygon.io/docs/options/get_v2_aggs_ticker__optionsticker__range__multiplier___timespan___from___to
34+
.. _Forex aggs: https://polygon.io/docs/forex/get_v2_aggs_ticker__forexticker__range__multiplier___timespan___from___to
35+
.. _Crypto aggs: https://polygon.io/docs/crypto/get_v2_aggs_ticker__cryptoticker__range__multiplier___timespan___from___to

docs/source/Getting-Started.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Requirements:
88

99
.. code-block:: shell
1010
11-
pip install polygon-api-client
11+
pip install polygon-api-client~=1.0.0b
1212
1313
HTTP client usage
1414
-----------------
@@ -45,7 +45,7 @@ For endpoints that have a set of parameters you can use the provided :doc:`enums
4545
4646
client.list_trades(..., sort=Sort.ASC)
4747
48-
To handle the raw `urllib3 response <https://urllib3.readthedocs.io/en/stable/reference/urllib3.response.html?highlight=response#response) yourself, pass `raw=True>`_ yourself pass :code:`raw=True`:
48+
To handle the raw `urllib3 response <https://urllib3.readthedocs.io/en/stable/reference/urllib3.response.html?highlight=response#response>`_ yourself pass :code:`raw=True`:
4949

5050
.. literalinclude:: ../../examples/rest/raw-get.py
5151

@@ -76,7 +76,7 @@ yourself (including unsubscribing and subscribing) you can use asyncio and the
7676

7777
.. literalinclude:: ../../examples/websocket/async.py
7878

79-
To handle raw messages yourself pass `raw=True`:
79+
To handle raw string or byte messages yourself pass :code:`raw=True`:
8080

8181
.. literalinclude:: ../../examples/websocket/raw.py
8282

polygon/rest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ConditionsClient,
1111
ExchangesClient,
1212
)
13-
from .vx import VXClient
13+
from .vX import VXClient
1414
from typing import Optional
1515
import os
1616

@@ -50,7 +50,7 @@ def __init__(
5050
base=base,
5151
verbose=verbose,
5252
)
53-
self.vx = VXClient(
53+
self.vX = VXClient(
5454
api_key=api_key,
5555
connect_timeout=connect_timeout,
5656
read_timeout=read_timeout,

polygon/rest/models/financials.py

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DataPoint:
99
label: Optional[str] = None
1010
order: Optional[int] = None
1111
unit: Optional[str] = None
12-
value: Optional[int] = None
12+
value: Optional[float] = None
1313
xpath: Optional[str] = None
1414

1515
@staticmethod
@@ -24,7 +24,7 @@ class ExchangeGainsLosses:
2424
label: Optional[str] = None
2525
order: Optional[int] = None
2626
unit: Optional[str] = None
27-
value: Optional[int] = None
27+
value: Optional[float] = None
2828
xpath: Optional[str] = None
2929

3030
@staticmethod
@@ -39,7 +39,7 @@ class NetCashFlow:
3939
label: Optional[str] = None
4040
order: Optional[int] = None
4141
unit: Optional[str] = None
42-
value: Optional[int] = None
42+
value: Optional[float] = None
4343
xpath: Optional[str] = None
4444

4545
@staticmethod
@@ -54,7 +54,7 @@ class NetCashFlowFromFinancingActivities:
5454
label: Optional[str] = None
5555
order: Optional[int] = None
5656
unit: Optional[str] = None
57-
value: Optional[int] = None
57+
value: Optional[float] = None
5858
xpath: Optional[str] = None
5959

6060
@staticmethod
@@ -76,17 +76,15 @@ def from_dict(d):
7676
return CashFlowStatement(
7777
exchange_gains_losses=None
7878
if "exchange_gains_losses" not in d
79-
else [ExchangeGainsLosses.from_dict(d["exchange_gains_losses"])],
79+
else ExchangeGainsLosses.from_dict(d["exchange_gains_losses"]),
8080
net_cash_flow=None
8181
if "net_cash_flow" not in d
82-
else [NetCashFlow.from_dict(d["net_cash_flow"])],
82+
else NetCashFlow.from_dict(d["net_cash_flow"]),
8383
net_cash_flow_from_financing_activities=None
8484
if "net_cash_flow_from_financing_activities" not in d
85-
else [
86-
NetCashFlowFromFinancingActivities.from_dict(
87-
d["net_cash_flow_from_financing_activities"]
88-
)
89-
],
85+
else NetCashFlowFromFinancingActivities.from_dict(
86+
d["net_cash_flow_from_financing_activities"]
87+
),
9088
)
9189

9290

@@ -97,7 +95,7 @@ class ComprehensiveIncomeLoss:
9795
label: Optional[str] = None
9896
order: Optional[int] = None
9997
unit: Optional[str] = None
100-
value: Optional[int] = None
98+
value: Optional[float] = None
10199
xpath: Optional[str] = None
102100

103101
@staticmethod
@@ -112,7 +110,7 @@ class ComprehensiveIncomeLossAttributableToParent:
112110
label: Optional[str] = None
113111
order: Optional[int] = None
114112
unit: Optional[str] = None
115-
value: Optional[int] = None
113+
value: Optional[float] = None
116114
xpath: Optional[str] = None
117115

118116
@staticmethod
@@ -127,7 +125,7 @@ class OtherComprehensiveIncomeLoss:
127125
label: Optional[str] = None
128126
order: Optional[int] = None
129127
unit: Optional[str] = None
130-
value: Optional[int] = None
128+
value: Optional[float] = None
131129
xpath: Optional[str] = None
132130

133131
@staticmethod
@@ -149,21 +147,17 @@ def from_dict(d):
149147
return ComprehensiveIncome(
150148
comprehensive_income_loss=None
151149
if "comprehensive_income_loss" not in d
152-
else [ComprehensiveIncomeLoss.from_dict(d["comprehensive_income_loss"])],
150+
else ComprehensiveIncomeLoss.from_dict(d["comprehensive_income_loss"]),
153151
comprehensive_income_loss_attributable_to_parent=None
154152
if "comprehensive_income_loss_attributable_to_parent" not in d
155-
else [
156-
ComprehensiveIncomeLossAttributableToParent.from_dict(
157-
d["comprehensive_income_loss_attributable_to_parent"]
158-
)
159-
],
153+
else ComprehensiveIncomeLossAttributableToParent.from_dict(
154+
d["comprehensive_income_loss_attributable_to_parent"]
155+
),
160156
other_comprehensive_income_loss=None
161157
if "other_comprehensive_income_loss" not in d
162-
else [
163-
OtherComprehensiveIncomeLoss.from_dict(
164-
d["other_comprehensive_income_loss"]
165-
)
166-
],
158+
else OtherComprehensiveIncomeLoss.from_dict(
159+
d["other_comprehensive_income_loss"]
160+
),
167161
)
168162

169163

@@ -174,7 +168,7 @@ class BasicEarningsPerShare:
174168
label: Optional[str] = None
175169
order: Optional[int] = None
176170
unit: Optional[str] = None
177-
value: Optional[int] = None
171+
value: Optional[float] = None
178172
xpath: Optional[str] = None
179173

180174
@staticmethod
@@ -189,7 +183,7 @@ class CostOfRevenue:
189183
label: Optional[str] = None
190184
order: Optional[int] = None
191185
unit: Optional[str] = None
192-
value: Optional[int] = None
186+
value: Optional[float] = None
193187
xpath: Optional[str] = None
194188

195189
@staticmethod
@@ -204,7 +198,7 @@ class GrossProfit:
204198
label: Optional[str] = None
205199
order: Optional[int] = None
206200
unit: Optional[str] = None
207-
value: Optional[int] = None
201+
value: Optional[float] = None
208202
xpath: Optional[str] = None
209203

210204
@staticmethod
@@ -219,7 +213,7 @@ class OperatingExpenses:
219213
label: Optional[str] = None
220214
order: Optional[int] = None
221215
unit: Optional[str] = None
222-
value: Optional[int] = None
216+
value: Optional[float] = None
223217
xpath: Optional[str] = None
224218

225219
@staticmethod
@@ -234,7 +228,7 @@ class Revenues:
234228
label: Optional[str] = None
235229
order: Optional[int] = None
236230
unit: Optional[str] = None
237-
value: Optional[int] = None
231+
value: Optional[float] = None
238232
xpath: Optional[str] = None
239233

240234
@staticmethod
@@ -256,19 +250,17 @@ def from_dict(d):
256250
return IncomeStatement(
257251
basic_earnings_per_share=None
258252
if "basic_earnings_per_share" not in d
259-
else [BasicEarningsPerShare.from_dict(d["basic_earnings_per_share"])],
253+
else BasicEarningsPerShare.from_dict(d["basic_earnings_per_share"]),
260254
cost_of_revenue=None
261255
if "cost_of_revenue" not in d
262-
else [CostOfRevenue.from_dict(d["cost_of_revenue"])],
256+
else CostOfRevenue.from_dict(d["cost_of_revenue"]),
263257
gross_profit=None
264258
if "gross_profit" not in d
265-
else [GrossProfit.from_dict(d["gross_profit"])],
259+
else GrossProfit.from_dict(d["gross_profit"]),
266260
operating_expenses=None
267261
if "operating_expenses" not in d
268-
else [OperatingExpenses.from_dict(d["operating_expenses"])],
269-
revenues=None
270-
if "revenues" not in d
271-
else [Revenues.from_dict(d["revenues"])],
262+
else OperatingExpenses.from_dict(d["operating_expenses"]),
263+
revenues=None if "revenues" not in d else Revenues.from_dict(d["revenues"]),
272264
)
273265

274266

@@ -288,13 +280,13 @@ def from_dict(d):
288280
else {k: DataPoint.from_dict(v) for (k, v) in d["balance_sheet"].items()},
289281
cash_flow_statement=None
290282
if "cash_flow_statement" not in d
291-
else [CashFlowStatement.from_dict(d["cash_flow_statement"])],
283+
else CashFlowStatement.from_dict(d["cash_flow_statement"]),
292284
comprehensive_income=None
293285
if "comprehensive_income" not in d
294-
else [ComprehensiveIncome.from_dict(d["comprehensive_income"])],
286+
else ComprehensiveIncome.from_dict(d["comprehensive_income"]),
295287
income_statement=None
296288
if "income_statement" not in d
297-
else [IncomeStatement.from_dict(d["income_statement"])],
289+
else IncomeStatement.from_dict(d["income_statement"]),
298290
)
299291

300292

@@ -321,7 +313,7 @@ def from_dict(d):
321313
filing_date=d.get("filing_date", None),
322314
financials=None
323315
if "financials" not in d
324-
else [Financials.from_dict(d["financials"])],
316+
else Financials.from_dict(d["financials"]),
325317
fiscal_period=d.get("fiscal_period", None),
326318
fiscal_year=d.get("fiscal_year", None),
327319
source_filing_file_url=d.get("source_filing_file_url", None),
File renamed without changes.

polygon/websocket/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(
2424
market: Union[str, Market] = Market.Stocks,
2525
raw: bool = False,
2626
verbose: bool = False,
27-
subscriptions: List[str] = [],
27+
subscriptions: Optional[List[str]] = None,
2828
max_reconnects: Optional[int] = 5,
2929
secure: bool = True,
3030
**kwargs,
@@ -33,8 +33,8 @@ def __init__(
3333
Initialize a Polygon WebSocketClient.
3434
3535
:param api_key: Your API keYour API key.
36-
:param feed: The feed to subscribe to (default RealTime)
37-
:param raw: The market to subscribe to (default Stocks)
36+
:param feed: The feed to subscribe to.
37+
:param raw: Whether to pass raw Union[str, bytes] to user callback.
3838
:param verbose: Whether to print client and server status messages.
3939
:param subscriptions: List of subscription parameters.
4040
:param max_reconnects: How many times to reconnect on network outage before ending .connect event loop.
@@ -59,6 +59,8 @@ def __init__(
5959
self.subs: Set[str] = set()
6060
self.max_reconnects = max_reconnects
6161
self.websocket: Optional[WebSocketClientProtocol] = None
62+
if subscriptions is None:
63+
subscriptions = []
6264
self.scheduled_subs = set(subscriptions)
6365
self.schedule_resub = True
6466

0 commit comments

Comments
 (0)