I’m just wondering if anyone understands why this websocket thread is deadlocked. Everything works propely on it’s own, but after websocket_thread is started the main thread won’t continue. Thanks.
auth.py
import time, hmac, hashlib
API_KEY = ''
SECRET = ''
timestamp = str(int(time.time()))
# for websocket
def sign_message(message):
message = hmac.new(SECRET.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
return message
create_websocket.py
import json, websocket
from threading import Thread
from auth import *
import time
def create_websocket(market):
channel = 'ticker'
subscribe_msg = {
'type': 'subscribe',
'product_ids': [
market
],
'channel': 'ticker',
'api_key': API_KEY,
'timestamp': timestamp,
'signature': sign_message(timestamp + channel + market)
}
subscribe_msg = json.dumps(subscribe_msg)
ws = websocket.create_connection('wss://advanced-trade-ws.coinbase.com')
ws.send(subscribe_msg)
while True:
message = json.loads(ws.recv())
if 'tickers' in message['events'][0]:
current_price = message['events'][0]['tickers'][0]['price']
print(current_price)
websocket_thread = Thread(target=create_websocket('BTC-USDT'))
websocket_thread.start()
# main thread
for i in range(100):
print(i)
time.sleep(1)