-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws_ornek_thread.py
56 lines (40 loc) · 1.25 KB
/
ws_ornek_thread.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import time
import websocket
import json
import pprint
import rel
rel.safe_read()
# websocket.enableTrace(True)
adet = 0
start_time = time.time()
def on_close(ws, close_status_code, close_msg):
print(f"closed connection:{close_msg}")
def on_error(ws, error):
print(f"closed: {error}")
def on_open(ws):
print("opened connection")
def on_message(ws, message):
global adet
global start_time
adet = adet + 1
# json_message = json.loads(message)
# print("received message")
# pprint.pprint(json_message)
if adet > 300:
print(f"Toplam süre: {time.time() - start_time} saniye")
ws.close()
print("Bitti")
def main():
# socket = "wss://stream.binance.com:9443/ws/ftmusdt@ticker"
baseEndPoint = "wss://stream.binance.com:9443/ws/"
for event in ["ftmusdt@ticker", "btcusdt@trade"]:
streamAddress = f"{baseEndPoint}{event}"
ws = websocket.WebSocketApp(streamAddress,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever(dispatcher=rel)
rel.signal(2, rel.abort)
rel.dispatch()
main()