User Data Streams: How to differentiate outboundAccountPosition, balanceUpdate and executionReport when multiple listenKeys are subscribed?

Hi Binance

I’m referring to https://binance-docs.github.io/apidocs/spot/en/#user-data-streams.

I understand multiple listenKeys of Spot accounts can be subscribed to the base websocket endpoint.

How do I differentiate outboundAccountPosition, balanceUpdate and executionReport related to which listenKey (ie. account) as API documentation does not include the UserID?

Best regards
Ling

Use this URL - /stream?streams=// and the stream name would show in every message

Thanks MJW for the reply.

I intend to subscribe listenKeys as follows:
{“method”: “SUBSCRIBE”,“params”:[“listenKey”],“id”: 1}

Are you saying relevant listenKey appear as follows?
{
“e”: “outboundAccountPosition”, //Event type
“listenKey”: “xyz”
}

Thank you.

This is another right way - called dynamical subscription

I tried with two listenkeys as per the dynamical subscription, but I don’t receive any stream name in executionReport or outboundAccountPosition.

Here is the real executionReport received:
{“e”:“executionReport”,“E”:1617713110866,“s”:“BTCUSDT”,“c”:“f3e3c3b2-8997-465b-aacf-53064bb919e0”,“S”:“BUY”,“o”:“LIMIT”,“f”:“GTC”,“q”:“0.00050000”,“p”:“40000.00000000”,“P”:“0.00000000”,“F”:“0.00000000”,“g”:-1,“C”:"",“x”:“NEW”,“X”:“NEW”,“r”:“NONE”,“i”:5459855136,“l”:“0.00000000”,“z”:“0.00000000”,“L”:“0.00000000”,“n”:“0”,“N”:null,“T”:1617713110865,“t”:-1,“I”:11648105689,“w”:true,“m”:false,“M”:false,“O”:1617713110865,“Z”:“0.00000000”,“Y”:“0.00000000”,“Q”:“0.00000000”}

Here is the real outboundAccountPosition received:
{“e”:“outboundAccountPosition”,“E”:1617713110866,“u”:1617713110865,“B”:[{“a”:“BTC”,“f”:“0.00000056”,“l”:“0.00000000”},{“a”:“BNB”,“f”:“0.00075875”,“l”:“0.00000000”},{“a”:“USDT”,“f”:“edited.edited”,“l”:“20.00000000”}]}

Thank you.

Try to subscribe as:

wss://stream.binance.com:9443/stream?streams=<listenKey_a>/<listenKey_b>/<listenKey_c>

Then the received websocket update will be:

{"stream": "listenKey_b", "data":{ "e": "outboundAccountPosition"...}}
{"stream": "listenKey_a", "data": {"e": "balanceUpdate"...}}
  1. Thank you aisling, “stream?streams=<listenKey_a>/<listenKey_b>/<listenKey_c>” method works and I get stream names as you mentioned.

  2. I understand, a single websocket connection can listen to a maximum of 1024 streams. Does that means I can provide maximum of 1024 listenKeys to the parameter “stream?streams=” without violating any length issues?

  3. However, the disadvantage of the Combined streams method is, listenKeys required to be known at the time of websocket creation (eg. UTC midnight). Any new trader come after the UTC midnight, has to wait maximum one day (until after next UTC midnight), to start his first trade!

Therefore, can we request to include the stream name to the outboundAccountPosition, balanceUpdate and executionReport when subscribe via the dynamical subscription method (ie. {“method”: “SUBSCRIBE”,“params”:[“listenKey”],“id”: 1})?

So that returned JSONs are of following format:
{
“e”: “outboundAccountPosition”, //Event type
“stream”: “listenKey_x”,

}

Apparently, adding a new key/value to JSON does not break the API, or does not break any users’ application. Does Binance see any disadvantage to our this proposal?

Note, Binance may omit the stream name for JSONs returned for single listenKey subscription using /ws/“listenKey”.

Thank you.

1 Like