Spot testnet - user data stream SBE support in version 2.1

Hi,

In the latest SBE codec (id=“2”, version=“1”). It suggest that user data stream events are available in the SBE format. But I am not able to find any documentation regarding how to consume the SBE user data stream.

Currently I am connecting through API websocket using (https://testnet.binance.vision/ws-api/v3?responseFormat=sbe&sbeSchemaId=2&sbeSchemaVersion=1) and consuming SBE response.

I have tried the following to consume user-stream with SBE format but no luck.

Approach 1.

  • Get the ListenKey by calling (“userDataStream.start”).
  • And then connect to below ( “wss://stream.testnet.binance.vision:9443/ws/{ListenKey}?responseFormat=sbe&sbeSchemaId=2&sbeSchemaVersion=1”)
    This is failing as it complaints wrong URL.

Approach 2.

  • Get the ListenKey by sending (“userDataStream.start”)
  • Subscribe user data stream by sending (“userDataStream.subscribe”).
    No error and it can receive the “UserDataStreamSubscribeResponse”. But not able to receive any user stream event after some position update.

Approach 3. (Same as Approach 2, just skipped the “userDataStream.start”)

  • Subscribe user data stream by sending (“userDataStream.subscribe”).
    No error and it can receive the “UserDataStreamSubscribeResponse”. But not able to receive any user stream event after some position update.

Could you suggest how can we consume the user-data event in a SBE session?

Thanks,
Keith Liu

User Data Streams are available in SBE format, but only on WebSocket API directly: wss://ws-api.testnet.binance.vision/ws-api/v3

WebSocket Streams and listen keys do not support SBE right now.

You need to use userDataStream.subscribe method (approach 3):

  1. Open a connection to wss://testnet.binance.vision/ws-api/v3?responseFormat=sbe&sbeSchemaId=2&sbeSchemaVersion=1, requesting SBE format.
  2. Send session.logon message to log using your Ed25519 API key and signature.
  3. Send userDataStream.subscribe message to subscribe to the user data stream.

You should then receive the new messages from spot_2_1.xml now: first UserDataStreamSubscribeResponse to confirm that you’re subscribed, followed by ExecutionReportEvent and OutboundAccountPositionEvent when your orders are updated.

Note that user data stream events will be sent to the WebSocket API session (the same one you use for userDataStream.subscribe). You need to keep the receive loop running after subscription, so that you receive the events when they come.

1 Like

Hi,

Tested approach 3, it is working thanks. One more quick question if we are using userDataStream.subscribe and getting user data from the same websocket connection. Do we still need to send “userDataStream.ping” to keep alive the user data stream?

Thanks,
Keith Liu

No, you don’t. The user data stream is active while the WebSocket connection is active, you only need to keep it connected (there are WebSocket-level ping frames for that). However, you do not need to send any requests like userDataStream.ping.