-
Notifications
You must be signed in to change notification settings - Fork 743
/
Copy pathscript-kucoin-webhooks-ticker.py
50 lines (38 loc) · 1.42 KB
/
script-kucoin-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
42
43
44
45
46
47
48
49
50
import os
import sys
import time
import signal
sys.path.insert(0, ".")
from models.exchange.kucoin import WebSocketClient as KWebSocketClient # noqa: E402
from models.exchange.Granularity import Granularity # noqa: E402
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 = KWebSocketClient(["BTC-USD"], Granularity.ONE_MINUTE)
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.time_elapsed} seconds")
print("\nMessageCount =", "%i \n" % websocket.message_count)
print("Ticker:")
print(websocket.tickers)
print("")
print("Candles:")
print(websocket.candles)
print("")
message_count = websocket.message_count
time.sleep(1) # output every 1 second, 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)