SPOT orderbook with websocket

In the spot websocket API, I requested the depth of multiple symbols, but the symbol names are not included in the response message. How can I distinguish them?

codes here:

orderbook_request = {
‘method’: ‘SUBSCRIBE’,
‘params’: [
f’{symbol.lower()}@depth20’ for symbol in self.symbol_list[:50]
],
‘id’: 2
}

ws.send(json.dumps(orderbook_request))

You can use so called “combined streams”:

  • Connect to wss://stream.binance.com/stream instead of /ws
  • The events now include the stream name which can be used to disambiguate depth updates to different symbols.
{"stream":"btcusdt@depth5","data":{"lastUpdateId":55528760712,"bids":[["96301.58000000","4.62620000"],["96301.57000000","0.58500000"],["96301.00000000","0.23046000"],["96300.99000000","0.20849000"],["96300.75000000","0.12000000"]],"asks":[["96301.59000000","0.19879000"],["96302.37000000","0.00006000"],["96302.38000000","0.00943000"],["96302.39000000","0.08282000"],["96302.62000000","0.00026000"]]}}
{"stream":"ethusdt@depth5","data":{"lastUpdateId":39771665562,"bids":[["3628.87000000","30.55030000"],["3628.86000000","6.67620000"],["3628.81000000","10.07710000"],["3628.80000000","3.43000000"],["3628.61000000","1.20570000"]],"asks":[["3628.88000000","11.68240000"],["3628.89000000","0.00230000"],["3628.90000000","0.00290000"],["3628.97000000","0.00520000"],["3628.98000000","0.41660000"]]}}

OK! Thank you very much!
That works! :slight_smile: