Skip to content

Commit 13f9e57

Browse files
authored
update readme to look like the example files and vice versa (#48)
1 parent fd5384c commit 13f9e57

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,34 @@ For a basic product overview, check out our [setup and use documentation](https:
1919
```python
2020
import time
2121

22-
2322
from polygon import WebSocketClient, STOCKS_CLUSTER
2423

2524

26-
def my_customer_process_message(message):
25+
def my_custom_process_message(message):
2726
print("this is my custom message processing", message)
2827

2928

29+
def my_custom_error_handler(ws, error):
30+
print("this is my custom error handler", error)
31+
32+
33+
def my_custom_close_handler(ws):
34+
print("this is my custom close handler")
35+
36+
3037
def main():
3138
key = 'your api key'
32-
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_customer_process_message)
39+
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_custom_process_message)
3340
my_client.run_async()
3441

3542
my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA")
36-
time.sleep(2)
43+
time.sleep(1)
3744

3845
my_client.close_connection()
3946

4047

4148
if __name__ == "__main__":
4249
main()
43-
4450
```
4551

4652
## Simple REST Demo

rest-example.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
import datetime
2+
13
from polygon import RESTClient
24

35

6+
def ts_to_datetime(ts) -> str:
7+
return datetime.datetime.fromtimestamp(ts / 1000.0).strftime('%Y-%m-%d %H:%M')
8+
9+
410
def main():
511
key = "your api key"
612

713
# RESTClient can be used as a context manager to facilitate closing the underlying http session
814
# https://requests.readthedocs.io/en/master/user/advanced/#session-objects
915
with RESTClient(key) as client:
10-
resp = client.stocks_equities_daily_open_close("AAPL", "2018-03-02")
11-
print(f"On: {resp.from_} Apple opened at {resp.open} and closed at {resp.close}")
16+
from_ = "2019-01-01"
17+
to = "2019-02-01"
18+
resp = client.stocks_equities_aggregates("AAPL", 1, "minute", from_, to, unadjusted=False)
19+
20+
print(f"Minute aggregates for {resp.ticker} between {from_} and {to}.")
21+
22+
for result in resp.results:
23+
dt = ts_to_datetime(result["t"])
24+
print(f"{dt}\n\tO: {result['o']}\n\tH: {result['h']}\n\tL: {result['l']}\n\tC: {result['c']} ")
1225

1326

1427
if __name__ == '__main__':
15-
main()
28+
main()

0 commit comments

Comments
 (0)