-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_websockets.py
More file actions
30 lines (23 loc) · 842 Bytes
/
Copy pathexample_websockets.py
File metadata and controls
30 lines (23 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Websocket example"""
from time import sleep
from eodhd import WebSocketClient
def main() -> None:
"""Main"""
websocket = WebSocketClient(
# Demo API key for testing purposes
api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX",
endpoint="crypto",
symbols=["BTC-USD"]
# api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX", endpoint="forex", symbols=["EURUSD"]
# api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX", endpoint="us", symbols=["AAPL"]
)
websocket.start()
message_count = 0
while True:
if websocket:
if message_count != websocket.message_count:
print(websocket.message)
message_count = websocket.message_count
sleep(0.25) # output every 1/4 second, websocket is realtime
if __name__ == "__main__":
main()