From caab917e9e1ca329008ffaeae2f6d52f18c495c8 Mon Sep 17 00:00:00 2001 From: Ricky Barillas <8647805+jbonzo@users.noreply.github.com> Date: Fri, 6 Nov 2020 10:35:38 -0500 Subject: [PATCH] add better documentation around query param usage (#42) --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index f9a993d4..599693d1 100644 --- a/README.md +++ b/README.md @@ -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