Skip to content

Commit 8f27b15

Browse files
clickingbuttonsclickingbuttons
authored andcommitted
update readme
1 parent 56b4a04 commit 8f27b15

File tree

2 files changed

+18
-91
lines changed

2 files changed

+18
-91
lines changed

README.md

Lines changed: 17 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
[![Build Status](https://drone.polygon.io/api/badges/polygon-io/client-python/status.svg)](https://drone.polygon.io/polygon-io/client-python)
1+
[![Build Status](https://github.com/polygon-io/client-python/actions/workflows/test/badge.svg)]()
22
[![PyPI version](https://badge.fury.io/py/polygon-api-client.svg)](https://badge.fury.io/py/polygon-api-client)
3+
[![Docs](https://readthedocs.org/projects/polygon-api-client/badge/?version=latest)](https://polygon-api-client.readthedocs.io/en/latest/)
34

45
# Polygon Python Client - WebSocket & RESTful APIs
56

@@ -11,105 +12,30 @@ For a basic product overview, check out our [setup and use documentation](https:
1112

1213
### Install
1314

14-
`pip install polygon-api-client`
15-
16-
`polygon-api-client` supports python version >= 3.6
17-
18-
## Simple WebSocket Demo
19-
```python
20-
import time
21-
22-
from polygon import WebSocketClient, STOCKS_CLUSTER
23-
24-
25-
def my_custom_process_message(message):
26-
print("this is my custom message processing", message)
27-
28-
29-
def my_custom_error_handler(ws, error):
30-
print("this is my custom error handler", error)
31-
15+
Requires python version >= 3.7
3216

33-
def my_custom_close_handler(ws):
34-
print("this is my custom close handler")
35-
36-
37-
def main():
38-
key = 'your api key'
39-
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_custom_process_message)
40-
my_client.run_async()
41-
42-
my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA")
43-
time.sleep(1)
44-
45-
my_client.close_connection()
46-
47-
48-
if __name__ == "__main__":
49-
main()
50-
```
17+
`pip install polygon-api-client`
5118

52-
## Simple REST Demo
19+
## REST Demos
20+
### Getting aggs
5321
```python
5422
from polygon import RESTClient
5523

56-
57-
def main():
58-
key = "your api key"
59-
60-
# RESTClient can be used as a context manager to facilitate closing the underlying http session
61-
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
62-
with RESTClient(key) as client:
63-
resp = client.stocks_equities_daily_open_close("AAPL", "2021-06-11")
64-
print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")
65-
66-
67-
if __name__ == '__main__':
68-
main()
69-
24+
client = RESTClient() # Uses POLYGON_API_KEY env var. Can optionally supply your key as first parameter.
25+
aggs = client.get_aggs("AAPL", 1, "day", "2005-04-01", "2005-04-04")
7026
```
7127

72-
### Query parameters for REST calls
73-
74-
Every function call under our RESTClient has the `query_params` kwargs. These kwargs are passed along and mapped 1:1
75-
as query parameters to the underling HTTP call. For more information on the different query parameters please reference
76-
our [API Docs](https://polygon.io/docs/).
77-
78-
#### Example with query parameters
79-
28+
### Getting trades
8029
```python
81-
import datetime
82-
8330
from polygon import RESTClient
31+
from polygon.rest.models import Sort
8432

33+
client = RESTClient() # Uses POLYGON_API_KEY env var. Can optionally supply your key as first parameter.
8534

86-
def ts_to_datetime(ts) -> str:
87-
return datetime.datetime.fromtimestamp(ts / 1000.0).strftime('%Y-%m-%d %H:%M')
88-
89-
90-
def main():
91-
key = "your api key"
92-
93-
# RESTClient can be used as a context manager to facilitate closing the underlying http session
94-
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
95-
with RESTClient(key) as client:
96-
from_ = "2021-01-01"
97-
to = "2021-02-01"
98-
resp = client.stocks_equities_aggregates("AAPL", 1, "minute", from_, to, unadjusted=False)
99-
100-
print(f"Minute aggregates for {resp.ticker} between {from_} and {to}.")
101-
102-
for result in resp.results:
103-
dt = ts_to_datetime(result["t"])
104-
print(f"{dt}\n\tO: {result['o']}\n\tH: {result['h']}\n\tL: {result['l']}\n\tC: {result['c']} ")
105-
106-
107-
if __name__ == '__main__':
108-
main()
109-
```
110-
111-
## Notes about the REST Client
112-
113-
We use swagger as our API spec and we used this swagger to generate most of the code that defines the REST client.
114-
We made this decision due to the size of our API, many endpoints and object definitions, and to accommodate future changes.
35+
trades = []
36+
for t in client.list_trades("AAA", timestamp="2022-04-20", limit=5, sort=Sort.ASC):
37+
trades.append(t)
38+
```
11539

40+
### Getting raw response
41+
To handle the raw [urllib3 response](https://urllib3.readthedocs.io/en/stable/reference/urllib3.response.html?highlight=response#response) yourself, pass `raw=True`.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ types-urllib3 = "^1.26.13"
3131
httpretty = "^1.1.4"
3232
Sphinx = "^4.5.0"
3333
sphinx-rtd-theme = "^1.0.0"
34+
# keep this in sync with docs/requirements.txt for readthedocs.org
3435
sphinx-autodoc-typehints = "^1.18.1"
3536

3637
[build-system]

0 commit comments

Comments
 (0)