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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,44 @@ if __name__ == '__main__':

```

### Query parameters for REST calls

Every function call under our RESTClient has the `query_params` kwargs. These kwargs are passed along and mapped 1:1
as query parameters to the underling HTTP call. For more information on the different query parameters please reference
our [API Docs](https://polygon.io/docs/).

#### Example with query parameters

```python
import datetime

from polygon import RESTClient


def ts_to_datetime(ts) -> str:
return datetime.datetime.fromtimestamp(ts / 1000.0).strftime('%Y-%m-%d %H:%M')


def main():
key = "your api key"

# RESTClient can be used as a context manager to facilitate closing the underlying http session
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
with RESTClient(key) as client:
from_ = "2019-01-01"
to = "2019-02-01"
resp = client.stocks_equities_aggregates("AAPL", 1, "minute", from_, to, unadjusted=False)

print(f"Minute aggregates for {resp.ticker} between {from_} and {to}.")

for result in resp.results:
dt = ts_to_datetime(result["t"])
print(f"{dt}\n\tO: {result['o']}\n\tH: {result['h']}\n\tL: {result['l']}\n\tC: {result['c']} ")


if __name__ == '__main__':
main()
```

## Notes about the REST Client

Expand Down