forked from whittlem/pycryptobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-coinbasepro-webhooks-ticker.py
39 lines (32 loc) · 1.06 KB
/
script-coinbasepro-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
import os
import sys
import time
import signal
from models.exchange.coinbase_pro import WebSocketClient as CWebSocketClient
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 = CWebSocketClient(["ADA-GBP"], 60)
websocket.start()
message_count = 0
while True:
if websocket:
if (
message_count != websocket.message_count
and websocket.tickers is not None
):
cls()
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)