I’ve been trying to use python binance websocket api with the code below:
import websocket
SOCKET = "wss://stream.binance.com:9443/ws/btcusdt@trade"
def on_open(ws):
print('opened connection')
def on_close(ws):
print('close connection')
def on_message(ws, message):
print('received message')
print(message)
def on_error(ws, message):
print('error detected')
print(message)
websocket.enableTrace(True)
ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message, on_error=on_error)
ws.run_forever()
Error message as below:
error detected
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
error detected
on_close() takes 1 positional argument but 3 were given
This question might be a bit stupid (?) because this is my first time trying to use the API. I have searched around the web with no results. Do I have to create an API key first? (I didn’t.)
Any help is appreciated.
2