forked from whittlem/pycryptobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script-binance-webhooks-historical.py
44 lines (37 loc) · 1.08 KB
/
script-binance-webhooks-historical.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
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 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("\nMessageCount =", "%i \n" % websocket.message_count)
print(websocket.candles)
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, handler)
print("\nPlease wait while threads complete gracefully.")
websocket.close()
sys.exit(0)