title: Binance WebSocket Order Book - depths change every time
body: <p>Below is a python script that subscribes order book information via Biance's Websocket API (<a href="https://binance-docs.github.io/apidocs/spot/en/#all-book-tickers-stream" rel="nofollow noreferrer">Documentation Here</a>).</p>
  <p>In both requests(<code>btcusdt@depth</code> and <code>btcusdt@depth@100ms</code>), each json payload is streamed with a varying depth.<br />
  Please shed light on what might be the cause of this? Am I doing something wrong? Or might they have certain criteria as to how many depths of an order book to fetch?</p>
  <pre><code>import json
  import websocket
  
  socket='wss://stream.binance.com:9443/ws'
  
  def on_open(self):
      print(&quot;opened&quot;)
      subscribe_message = {
          &quot;method&quot;: &quot;SUBSCRIBE&quot;,
          &quot;params&quot;:
          [
           &quot;btcusdt@depth@100ms&quot;
           ],
          &quot;id&quot;: 1
          }
  
      ws.send(json.dumps(subscribe_message))
  
  def on_message(self, message):
      print(&quot;received a message&quot;)
  
      ###### depths of bid/ask ######
      d = json.loads(message)
      for k, v in d.items():
          if k == &quot;b&quot;:
              print(f&quot;bid depth : {len(v)}&quot;)
          if k == &quot;a&quot;:
              print(f&quot;ask depth : {len(v)}&quot;)
  
  def on_close(self):
      print(&quot;closed connection&quot;)
  
  ws = websocket.WebSocketApp(socket,
                              on_open=on_open,
                              on_message=on_message,
                              on_close=on_close)
  
  ws.run_forever()
  </code></pre>
  <h3>btcusdt@depth@100ms</h3>
  <pre><code>opened
  received a message
  received a message
  bid depth : 3
  ask depth : 12
  received a message
  bid depth : 14
  ask depth : 12
  received a message
  bid depth : 17
  ask depth : 24
  received a message
  bid depth : 14
  ask depth : 16
  received a message
  bid depth : 3
  ask depth : 5
  received a message
  bid depth : 16
  ask depth : 6
  .
  .
  .
  
  </code></pre>
  <h3>btcusdt@depth</h3>
  <pre><code>opened
  received a message
  received a message
  bid depth : 135
  ask depth : 127
  received a message
  bid depth : 125
  ask depth : 135
  received a message
  bid depth : 95
  ask depth : 85
  received a message
  bid depth : 68
  ask depth : 88
  received a message
  bid depth : 119
  ask depth : 145
  received a message
  bid depth : 127
  ask depth : 145
  .
  .
  .
  </code></pre>