Java API Library websocket USER stream, no events are ever received

Hey,

I am having an issue with the library at binance-futures-connector-java

I am using the latest 3.0.1

I created a listen key from my API key. The listen key is correct and functional, I did a long chat with binance support, they verified it as well and I also checked the demo endpoint at Websocket Demo The mode endpoint works with the same listen key

My code is pretty much taken from the example at ListenUserStream.java

I am using the same library and similar code for the price book stream and it works fine.

Here is my test code that does not work with USER streams:

        UMFuturesClientImpl client = new UMFuturesClientImpl(tradeKey, tradeSecret, DefaultUrls.USDM_PROD_URL);
        UMWebsocketClientImpl websocketClient = new UMWebsocketClientImpl(DefaultUrls.USDM_WS_URL);

            String listenKey = client.userData().createListenKey();
            System.out.println("Listen key: " + listenKey);
            int Id = websocketClient.listenUserStream(listenKey, Scratch::receiveMessageJSON);
            Thread.sleep(15000);
            websocketClient.closeConnection(Id);

    private static void receiveMessageJSON(String data) {
        JSONObject obj = new JSONObject(data);
        System.out.println(obj);
    }

I run the code, I see the following printed on the console

20:00:40.204 [main] INFO c.b.c.f.client.utils.RequestHandler - POST removed
Listen key: {“listenKey”:“hidden”}
20:00:40.835 [main] INFO c.b.c.f.c.utils.WebSocketConnection - [Connection 1] Connecting to removed
20:00:42.216 [OkHttp removed…] INFO c.b.c.f.c.utils.WebSocketConnection - [Connection 1] Connected to Server

Then, I try something like opening a small position on ETHUSDT or doing a transfer from my futures account. No event comes, nothing is printed on the console, the method receiveMessageJSON is never called.

I had to remove the links from my post, because of new user restrictions

Hi there.

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.

Here is the exact code I used to achieve this:

package um_futures;
import com.binance.connector.client.impl.UMFuturesClientImpl;
import com.binance.connector.client.impl.UMWebsocketClientImpl;
import config.PrivateConfig;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Getting listenkey and establing a user data stream.
 */

public class UserDataStream {
    private static final Logger logger = LoggerFactory.getLogger(UserDataStream.class);
    public static void main(String[] args) {
        UMWebsocketClientImpl wsClient = new UMWebsocketClientImpl("wss://stream.binancefuture.com");
        UMFuturesClientImpl futuresClient = new UMFuturesClientImpl(PrivateConfig.TESTNET_API_KEY, PrivateConfig.TESTNET_SECRET_KEY, PrivateConfig.BASE_URL);

        JSONObject obj = new JSONObject(futuresClient.userData().createListenKey());
        String listenKey = obj.getString("listenKey");
        logger.info("listenKey:" + listenKey);

        wsClient.listenUserStream(listenKey, ((event) -> {
            logger.info(event);
        }));
    }
}
1 Like

Thanks a lot @jonte ! A question. Why are you using

"wss://stream.binancefuture.com"

and not the default wss://fstream.binance.com"

I noticed that the demo uses your version as well.

PS. I found where my problem is, I did not parse the listen key. Now, its working. Many thanks!

I still am very confused as to what the problem is at my end, any help will be appreciated.