Hello.
I am in the following situation:
I am currently using GitHub - binance/binance-futures-connector-java. I want to know how to track the progress of a trade, such as knowing when a limit order has been executed.
Currently, I am using Query Order to determine when an order has been executed. However, after 90-120 minutes, I receive a connection reset error. I want to mention that I execute Query Order every time I receive an event through klineStream, which may be why I am losing the connection after a large volume of queries.
From what I have read, there is another way to track the progress of a trade using Binance API Documentation. Although I have tried to use this method, I am not receiving any events.
I would like an example in Java to understand how it works. This is how I tried to use the second method but without any results:
websocketClient.listenUserStream(connectionService.getListenKey(), (event) → {
System.out.println("Event: " + event);
});
Currently, I am using wss://stream.binancefuture.com. I am still in the development phase, but I don’t think that could be the issue with listenUserStream.
Hi @SilentUp94 - I tested it for myself using the Binance Futures Java Connector. Please refer to my attached screenshot. I created a listenKey on Futures Testnet and then connected to the User Stream and proceeded to make a couple of BTCUSDT orders on the Futures Testnet. All this activity appears in the websocket stream.
Hi, I found the problem. Because sometimes I am an idiot, I forgot that I need to extract the “listenkey” from the JSON, even if the JSON has only one parameter. Thank you very much for your help and I apologize for the time consumed. Now everything is working. You are the best!!
As you’ve identified, you can use the UserData Websocket Stream because it definitely sounds like you’re calling Query Order far too often.
Also you mentioned you’re using wss://stream.binancefuture.com which is the Testnet Websocket URL. That’s fine but please make sure that you’re making the trades on the Testnet and that when generating the listenKey you made sure to set the BASE_URL to the Testnet URL as well (https://testnet.binancefuture.com)
You need a listenKey which you can generate with the below snippet.
I had already done everything as described above, but it still doesn’t work, I’m not receiving any events. I have tried different combinations and still not receiving any events. I tried opening a trade and then opening the stream, and vice versa. To me, it seems like there’s something wrong with listenUserStream. Can someone who is using this stream confirm that it works?