Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 99 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,111 @@ Python client for the [Polygon.io API](https://polygon.io).

## Install

`pip install polygon-api-client`

```
pip install polygon-api-client
```
Requires Python >= 3.8.

## Getting started
See the [Getting Started](https://polygon-api-client.readthedocs.io/en/latest/Getting-Started.html)
section in our docs or view the [examples](./examples) directory.

#### Launchpad Usage

Users of the Launchpad product will need to pass in certain headers in order to make API requests.
section in our docs or view the [examples](./examples) directory for additional examples.
## REST API Client
Import the RESTClient.
```python
from polygon import RESTClient
```
Create a new client with your [API key](https://polygon.io/dashboard/api-keys)
```python
client = RESTClient(api_key="<API_KEY>")
```
### Using the Client
Request data using client methods.
```python
ticker = "AAPL"

# List Aggregates (Bars)
bars = client.get_aggs(ticker=ticker, multiplier=1, timespan="day", from_="2023-01-09", to="2023-01-10")
for bar in bars:
print(bar)

# Get Last Trade
trade = client.get_last_trade(ticker=ticker)
print(trade)

# List Trades
trades = client.list_trades(ticker=ticker, timestamp="2022-01-04")
for trade in trades:
print(trade)

# Get Last Quote
quote = client.get_last_quote(ticker=ticker)
print(quote)

# List Quotes
quotes = client.list_quotes(ticker=ticker, timestamp="2022-01-04")
for quote in quotes:
print(quote)
```
Note: For parameter argument examples check out our docs. All required arguments are annotated with red asterisks " * " and argument examples are set.
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)

## Launchpad
Users of the Launchpad product will need to pass in certain headers in order to make API requests using the RequestOptionBuilder.
Example can be found [here](./examples/launchpad).

Import classes
```python
from polygon import RESTClient
from polygon.rest.models.request import RequestOptionBuilder
```
### Using the client
Create client and set options
```python
# create client
c = RESTClient(api_key="API_KEY")

# create request options
options = RequestOptionBuilder().edge_headers(
edge_id="YOUR_EDGE_ID", # required
edge_ip_address="IP_ADDRESS", # required
)
```
Request data using client methods.
```python
# get response
res = c.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04", options=options)

# do something with response
```
Checkout Launchpad readme for more details on RequestOptionBuilder [here](./examples/launchpad)

## WebSocket Client

Import classes
```python
from polygon import WebSocketClient
from polygon.websocket.models import WebSocketMessage
from typing import List
```
### Using the client
Create a new client with your [API key](https://polygon.io/dashboard/api-keys) and subscription options.
```python
# Note: Multiple subscriptions can be added to the array
# For example, if you want to subscribe to AAPL and META,
# you can do so by adding "T.META" to the subscriptions array. ["T.AAPL", "T.META"]
# If you want to subscribe to all tickers, place an asterisk in place of the symbol. ["T.*"]
ws = WebSocketClient(api_key=<API_KEY>, subscriptions=["T.AAPL"])
```
Create a handler function and run the WebSocket.
```python
def handle_msg(msg: List[WebSocketMessage]):
for m in msg:
print(m)

ws.run(handle_msg=handle_msg)
```
Check out more detailed examples [here](https://github.com/polygon-io/client-python/tree/master/examples/websocket).

## Contributing

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