forked from whittlem/pycryptobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script-binance-webhooks-ticker.py
41 lines (34 loc) · 1.19 KB
/
script-binance-webhooks-ticker.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
import os
import sys
import time
import signal
from models.exchange.binance import WebSocketClient as BWebSocketClient
def cls():
os.system("cls" if os.name == "nt" else "clear")
def signal_handler(signum, frame):
if signum == 2:
print(" -> not finished yet!")
return
try:
websocket = BWebSocketClient(["BTCUSDT"], "1m")
websocket.start()
message_count = 0
while True:
if websocket:
if (
message_count != websocket.message_count
and websocket.tickers is not None
):
cls()
print(f"Start time: {websocket.getStartTime()}")
print(f"Time elapsed: {websocket.getTimeElapsed()} seconds")
print("\nMessageCount =", "%i \n" % websocket.message_count)
print(websocket.tickers)
message_count = websocket.message_count
time.sleep(5) # output every 5 seconds, websocket is realtime
# catches a keyboard break of app, exits gracefully
except KeyboardInterrupt:
signal.signal(signal.SIGINT, signal_handler)
print("\nPlease wait while threads complete gracefully.")
websocket.close()
sys.exit(0)