I’m trying to connect to the user data streams of futures, I’m receiving the listenKey correctly, I create a new connection with webSocket to receive the events, when I start the program I receive that the connection with websocket was opened but soon after opening it is closed and the return of closeEvent it is an error 1006, could someone help me, follow the code below, thanks. Learning node plis help.
As I couldn’t use User Date Stream, I connected with the basic endpoint and made a GET call, my return was a 404 error, I went after errors and couldn’t find them, I looked for questions here in the community and found a possible answer, I’m in a country where derivatives are restricted, could this be the problem with these errors? I’m in Brazil, it’s not allowed to trade futures here. thanks for helping me.
Besides the error code “404”, it also comes with an error message which provides more information about the error, you need to get that to understand the context. Otherwise, it’s not enough information.
Thanks for your help, I performed several tests in postman and with that I discovered that the error was not in the keys or url, but the version of axios that I was using, when I installed axios, apparently it installed version 1.0.0, when i checked this i installed axios@latest and it updated to the latest version and the error is gone thanks for your help
Hi @Ruan_Souza_de_Lima - if you’re using typescript you might find it easier to use an SDK for your connectivity challenges. Websockets can be a bit fussy, especially since you should ideally also have safety mechanisms in place to handle issues (heartbeats, automatic reconnects & resubscribes, listen key keep alive & refresh workflows, etc). Here’s one that handles all this for you and will hopefully save you from a lot of pain: binance/ws-userdata.ts at master · tiagosiebler/binance · GitHub
Hello, thanks for your answer, my problem was a simple lack of attention and I got the solution just by putting the axios version in its most updated version, I understand that the skd would be easier, but I wanted to make a robot from 0, to test my programming and improve my learning.
@Ruan_Souza_de_Lima makes sense! I’m the same. If you want to try out the ping/pong behaviour yourself, add listeners for onping and onping (the same way you have onopen etc).
If the websocket sends you a pong, you should reply with a pong: ws.pong(). You will also need to implement:
keep alive cycles for the listen key (expires every hour by default unless you call the keep alive endpoint)
handlers if the ws dies and/or the listen key expires
If you’d like to see how I’m handling this in production environments, you can follow some of the logic from here:
Or if you’d like to follow the workflow from connecting a user data stream, it starts here: