-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebsockets.py
More file actions
33 lines (30 loc) · 809 Bytes
/
websockets.py
File metadata and controls
33 lines (30 loc) · 809 Bytes
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
import time
import queue
import json
import requests
from hitbtc import HitBTC
# testing websocket logic using ETHBTC as an example
# c = HitBTC()
# c.start()
# time.sleep(5) # Give the socket some time to connect
# c.subscribe_ticker(symbol='ETHBTC') # Subscribe to ticker data for the pair ETHBTC
#
# while True:
# try:
# data = c.recv()
# print(data)
# except queue.Empty:
# continue
def websockets(uniqueMarkets):
c = HitBTC()
c.start()
time.sleep(2) # you need to give it 2 seconds to connect before requesting orderbooks
for markets in uniqueMarkets:
symbol = str(markets)
c.subscribe_book(symbol=str(symbol))
while True:
try:
data = c.recv()
except queue.Empty:
continue
print(data)