0

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.

asked Aug 14, 2024 at 9:33
2
  • WinErrro 10060 is a Timeout error. This would mean that your script is not able to connect to that port. Possible reasons: 1) service port you specified is incorrect. 2) firewall is blocking that port. Commented Aug 14, 2024 at 9:40
  • also, the on_close() function seems to be called with 3 arguments on_close(wsapp, close_status_code, close_msg) according to the documentation, but you defined the function to only take 1 argument. You should modify your function definition to accept the other 2 parameters. Commented Aug 14, 2024 at 10:03

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.