title: How To Subscribe To Websocket API Channel Using Python?
body: <p>I'm trying to subscribe to the Bitfinex.com websocket API public channel <code>BTCUSD</code>.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>from websocket import create_connection
  ws = create_connection("wss://api2.bitfinex.com:3000/ws")
  ws.connect("wss://api2.bitfinex.com:3000/ws")
  ws.send("LTCBTC")
  while True:
  
      result = ws.recv()
      print ("Received '%s'" % result)
  
  ws.close()
  </code></pre>
  
  <p>I believe <code>ws.send("BTCUSD")</code> is what subscribes to the public channel?  I get a message back I think is confirming the subscription <code>({"event":"info","version":1}</code>, but I don't get the stream of data afterward.  What am I missing?  </p>
  
  <p>Update:  Here's the code that finally worked.</p>
  
  <pre><code>import json
  
  from websocket import create_connection
  ws = create_connection("wss://api2.bitfinex.com:3000/ws")
  #ws.connect("wss://api2.bitfinex.com:3000/ws")
  ws.send(json.dumps({
      "event": "subscribe",
      "channel": "book",
      "pair": "BTCUSD",
      "prec": "P0"
  }))
  
  
  while True:
      result = ws.recv()
      result = json.loads(result)
      print ("Received '%s'" % result)
  
  ws.close()
  </code></pre>