Skip to content

Commit caab917

Browse files
authored
add better documentation around query param usage (#42)
1 parent ec93d27 commit caab917

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ if __name__ == '__main__':
6363

6464
```
6565

66+
### Query parameters for REST calls
67+
68+
Every function call under our RESTClient has the `query_params` kwargs. These kwargs are passed along and mapped 1:1
69+
as query parameters to the underling HTTP call. For more information on the different query parameters please reference
70+
our [API Docs](https://polygon.io/docs/).
71+
72+
#### Example with query parameters
73+
74+
```python
75+
import datetime
76+
77+
from polygon import RESTClient
78+
79+
80+
def ts_to_datetime(ts) -> str:
81+
return datetime.datetime.fromtimestamp(ts / 1000.0).strftime('%Y-%m-%d %H:%M')
82+
83+
84+
def main():
85+
key = "your api key"
86+
87+
# RESTClient can be used as a context manager to facilitate closing the underlying http session
88+
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
89+
with RESTClient(key) as client:
90+
from_ = "2019-01-01"
91+
to = "2019-02-01"
92+
resp = client.stocks_equities_aggregates("AAPL", 1, "minute", from_, to, unadjusted=False)
93+
94+
print(f"Minute aggregates for {resp.ticker} between {from_} and {to}.")
95+
96+
for result in resp.results:
97+
dt = ts_to_datetime(result["t"])
98+
print(f"{dt}\n\tO: {result['o']}\n\tH: {result['h']}\n\tL: {result['l']}\n\tC: {result['c']} ")
99+
100+
101+
if __name__ == '__main__':
102+
main()
103+
```
66104

67105
## Notes about the REST Client
68106

0 commit comments

Comments
 (0)