binance / binance-websocket-examples

Example code in Nodejs that demonstrate how to subscribe to Binance Websocket server.
MIT License
154 stars 52 forks source link

Subscribe to several user streams with one websocket connection #4

Closed KonstantinLitvin closed 3 years ago

KonstantinLitvin commented 3 years ago

When I subscribe to several user data streams (get listenkey for each account data stream for futures) and get message from one of the stream I can't find out which data stream send me that update message (there's no field like account id... ). Do you have any ideas?

{
  "e": "ACCOUNT_UPDATE",                // Event Type
  "E": 1564745798939,                   // Event Time
  "T": 1564745798938 ,                  // Transaction
  "a":                                  // Update Data
    {
      "m":"ORDER",                      // Event reason type
      "B":[                             // Balances
        {
          "a":"USDT",                   // Asset
          "wb":"122624.12345678",       // Wallet Balance
          "cw":"100.12345678"           // Cross Wallet Balance
        },
        {
          "a":"BNB",           
          "wb":"1.00000000",
          "cw":"0.00000000"         
        }
      ], 
2pd commented 3 years ago

Change to combined mode by replace the url to

wss://stream.binance.com:9443/stream?streams=<listen_key_1>/<listen_key_2>/<listen_key_3>

Then the listen key will be returned in the message, that can be used to identify different users.

2pd commented 3 years ago

Details from doc, https://github.com/2pd/binance-spot-api-docs/blob/master/web-socket-streams.md

KonstantinLitvin commented 3 years ago

Thanks!