Skip to content

Commit

Permalink
add better documentation around query param usage (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbonzo authored Nov 6, 2020
1 parent ec93d27 commit caab917
Showing 1 changed file with 38 additions and 0 deletions.
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

0 comments on commit caab917

Please sign in to comment.