title: How to connect to User Data Stream Binance?
body: <p>I need to listen to User Data Stream, whenever there's an Order Event - order execution, cancelation, and so on - I'd like to be able to listen to those events and create notifications.</p>
  <p>So I got my &quot;listenKey&quot; and I'm not sure if it was done the right way but I executed this code and it gave me something like listenKey.</p>
  <p>Code to get listenKey:</p>
  <pre><code>def get_listen_key_by_REST(binance_api_key):
      url = 'https://api.binance.com/api/v1/userDataStream'
      response = requests.post(url, headers={'X-MBX-APIKEY': binance_api_key}) 
      json = response.json()
      return json['listenKey']
  
  print(get_listen_key_by_REST(API_KEY))
  </code></pre>
  <p>And the code to listen to User Data Stream - which doesn't work, I get no json response.</p>
  <pre><code>socket = f&quot;wss://fstream-auth.binance.com/ws/btcusdt@markPrice?listenKey=&lt;listenKeyhere&gt;&quot;
  
  def on_message(ws, message):
      json_message = json.loads(message)
      print(json_message)
  
  def on_close(ws):
      print(f&quot;Connection Closed&quot;)
      # restart()
  
  def on_error(ws, error):
      print(f&quot;Error&quot;)
      print(error)
  
  ws = websocket.WebSocketApp(socket, on_message=on_message, on_close=on_close, on_error=on_error)
  </code></pre>
  <p>I have read the docs to no avail. I'd appreciate it if someone could point me in the right direction.</p>