Skip to content

Commit 3c1570c

Browse files
authored
Update readme (#365)
* options param added to get_summaries * deleted unused imports * README update
1 parent 075a73e commit 3c1570c

File tree

1 file changed

+99
-7
lines changed

1 file changed

+99
-7
lines changed

README.md

+99-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,111 @@ Python client for the [Polygon.io API](https://polygon.io).
77

88
## Install
99

10-
`pip install polygon-api-client`
11-
10+
```
11+
pip install polygon-api-client
12+
```
1213
Requires Python >= 3.8.
1314

1415
## Getting started
1516
See the [Getting Started](https://polygon-api-client.readthedocs.io/en/latest/Getting-Started.html)
16-
section in our docs or view the [examples](./examples) directory.
17-
18-
#### Launchpad Usage
19-
20-
Users of the Launchpad product will need to pass in certain headers in order to make API requests.
17+
section in our docs or view the [examples](./examples) directory for additional examples.
18+
## REST API Client
19+
Import the RESTClient.
20+
```python
21+
from polygon import RESTClient
22+
```
23+
Create a new client with your [API key](https://polygon.io/dashboard/api-keys)
24+
```python
25+
client = RESTClient(api_key="<API_KEY>")
26+
```
27+
### Using the Client
28+
Request data using client methods.
29+
```python
30+
ticker = "AAPL"
31+
32+
# List Aggregates (Bars)
33+
bars = client.get_aggs(ticker=ticker, multiplier=1, timespan="day", from_="2023-01-09", to="2023-01-10")
34+
for bar in bars:
35+
print(bar)
36+
37+
# Get Last Trade
38+
trade = client.get_last_trade(ticker=ticker)
39+
print(trade)
40+
41+
# List Trades
42+
trades = client.list_trades(ticker=ticker, timestamp="2022-01-04")
43+
for trade in trades:
44+
print(trade)
45+
46+
# Get Last Quote
47+
quote = client.get_last_quote(ticker=ticker)
48+
print(quote)
49+
50+
# List Quotes
51+
quotes = client.list_quotes(ticker=ticker, timestamp="2022-01-04")
52+
for quote in quotes:
53+
print(quote)
54+
```
55+
Note: For parameter argument examples check out our docs. All required arguments are annotated with red asterisks " * " and argument examples are set.
56+
Check out an example for Aggregates(client.get_aggs) [here](https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__range__multiplier___timespan___from___to)
57+
58+
## Launchpad
59+
Users of the Launchpad product will need to pass in certain headers in order to make API requests using the RequestOptionBuilder.
2160
Example can be found [here](./examples/launchpad).
2261

62+
Import classes
63+
```python
64+
from polygon import RESTClient
65+
from polygon.rest.models.request import RequestOptionBuilder
66+
```
67+
### Using the client
68+
Create client and set options
69+
```python
70+
# create client
71+
c = RESTClient(api_key="API_KEY")
72+
73+
# create request options
74+
options = RequestOptionBuilder().edge_headers(
75+
edge_id="YOUR_EDGE_ID", # required
76+
edge_ip_address="IP_ADDRESS", # required
77+
)
78+
```
79+
Request data using client methods.
80+
```python
81+
# get response
82+
res = c.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04", options=options)
83+
84+
# do something with response
85+
```
86+
Checkout Launchpad readme for more details on RequestOptionBuilder [here](./examples/launchpad)
87+
88+
## WebSocket Client
89+
90+
Import classes
91+
```python
92+
from polygon import WebSocketClient
93+
from polygon.websocket.models import WebSocketMessage
94+
from typing import List
95+
```
96+
### Using the client
97+
Create a new client with your [API key](https://polygon.io/dashboard/api-keys) and subscription options.
98+
```python
99+
# Note: Multiple subscriptions can be added to the array
100+
# For example, if you want to subscribe to AAPL and META,
101+
# you can do so by adding "T.META" to the subscriptions array. ["T.AAPL", "T.META"]
102+
# If you want to subscribe to all tickers, place an asterisk in place of the symbol. ["T.*"]
103+
ws = WebSocketClient(api_key=<API_KEY>, subscriptions=["T.AAPL"])
104+
```
105+
Create a handler function and run the WebSocket.
106+
```python
107+
def handle_msg(msg: List[WebSocketMessage]):
108+
for m in msg:
109+
print(m)
110+
111+
ws.run(handle_msg=handle_msg)
112+
```
113+
Check out more detailed examples [here](https://github.com/polygon-io/client-python/tree/master/examples/websocket).
114+
23115
## Contributing
24116

25117
If you found a bug or have an idea for a new feature, please first discuss it with us by

0 commit comments

Comments
 (0)