Skip to content

Commit 3b1fa80

Browse files
committed
fix websocket
1 parent fc2ca87 commit 3b1fa80

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

eodhd/websocketclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
raise ValueError("API key is invalid")
2828

2929
# Validate endpoint
30-
if endpoint not in ["us", "us_quote", "forex", "crypto"]:
30+
if endpoint not in ["us", "us-quote", "forex", "crypto"]:
3131
raise ValueError("Endpoint is invalid")
3232

3333
# Validate symbol list

example_websockets.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
"""Websocket example"""
22

3-
from time import sleep
3+
import time
44
from eodhd import WebSocketClient
55

6-
7-
def main() -> None:
8-
"""Main"""
9-
10-
websocket = WebSocketClient(
11-
# Demo API key for testing purposes
6+
client = WebSocketClient(
127
api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX",
138
endpoint="crypto",
14-
symbols=["BTC-USD"]
15-
# api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX", endpoint="forex", symbols=["EURUSD"]
16-
# api_key="OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX", endpoint="us", symbols=["AAPL"]
17-
)
18-
websocket.start()
19-
20-
message_count = 0
21-
while True:
22-
if websocket:
23-
if message_count != websocket.message_count:
24-
print(websocket.message)
25-
message_count = websocket.message_count
26-
sleep(0.25) # output every 1/4 second, websocket is realtime
27-
9+
symbols=["BTC-USD"],
10+
display_stream=False,
11+
display_candle_1m=True,
12+
display_candle_5m=False,
13+
display_candle_1h=False,
14+
)
15+
client.start()
2816

29-
if __name__ == "__main__":
30-
main()
17+
try:
18+
while client.running:
19+
res = client.get_data()
20+
print(res)
21+
time.sleep(1)
22+
except KeyboardInterrupt:
23+
print("\nStopping due to user request.")
24+
client.stop()

0 commit comments

Comments
 (0)