Getting user data from Websocket

Hey guys,

I have issues getting user event data from the API. I tried the examples in the com.binance.client.examples library

public class SubscribeUserData {

public static void main(String[] args) {

    RequestOptions options = new RequestOptions();
    SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY,
            options);

    // Start user data stream
    String listenKey = syncRequestClient.startUserDataStream();
    System.out.println("listenKey: " + listenKey);

    // Keep user data stream
    syncRequestClient.keepUserDataStream(listenKey);


    // Close user data stream
    //syncRequestClient.closeUserDataStream(listenKey);

    SubscriptionClient client = SubscriptionClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY);

    client.subscribeUserDataEvent(listenKey, ((event) -> {
        //event.getEventType();
        System.out.println(event.getEventType());
    }), null);

}

}

and also

public class UserDataStreamExample {

public static void main(String args) {
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance("", “”);
BinanceApiRestClient client = factory.newRestClient();

// First, we obtain a listenKey which is required to interact with the user data stream
String listenKey = client.startUserDataStream();

// Then, we open a new web socket client, and provide a callback that is called on every update
BinanceApiWebSocketClient webSocketClient = factory.newWebSocketClient();

// Listen for changes in the account
webSocketClient.onUserDataUpdateEvent(listenKey, response -> {
  System.out.println(response.getEventType());
  if (response.getEventType() == UserDataUpdateEventType.ACCOUNT_UPDATE) {
    AccountUpdateEvent accountUpdateEvent = response.getAccountUpdateEvent();
    // Print new balances of every available asset
    System.out.println(accountUpdateEvent.getBalances());
  } else {
    OrderTradeUpdateEvent orderTradeUpdateEvent = response.getOrderTradeUpdateEvent();
    // Print details about an order/trade
    System.out.println(orderTradeUpdateEvent);

    // Print original quantity
    System.out.println(orderTradeUpdateEvent.getOriginalQuantity());

    // Or price
    System.out.println(orderTradeUpdateEvent.getPrice());
  }
});
System.out.println("Waiting for events...");

// We can keep alive the user data stream
// client.keepAliveUserDataStream(listenKey);

// Or we can invalidate it, whenever it is no longer needed
// client.closeUserDataStream(listenKey);

}
}

None of these deliver any event data when I do something in the binacne account, like opening positions.

Any ideas what could be wrong here?

Many thanks :slight_smile:

Hi. This might be a programming issue which is not supposed to discuss here. But please also share more info about your case, such as if there is any error message shown to you, and the library name or link (since the package name you provided in not unique).

这个如何简答的