title: ibpy: extract API responses for multiple contracts
body: <p>I am interested in using ibpy with Interactive Brokers API to get real time tick data for a given universe of 100 stocks.  The code below, from examples on the web works for one stock.  Can someone tell me how i can do this for 100 stocks at the same time? </p>
  
  <p>Python script:</p>
  
  <pre><code>from ib.opt import ibConnection, message
  from ib.ext.Contract import Contract
  from time import sleep
  
  def my_callback_handler(msg):
      inside_mkt_bid = ''
      inside_mkt_ask = ''
  
      if msg.field == 1:
          inside_mkt_bid = msg.price
          print 'bid', inside_mkt_bid
      elif msg.field == 2:
          inside_mkt_ask = msg.price
          print 'ask', inside_mkt_ask
  
  
  tws = ibConnection()
  tws.register(my_callback_handler, message.tickSize, message.tickPrice)
  tws.connect()
  
  c = Contract()
  c.m_symbol = "DATA"
  c.m_secType = "STK"
  c.m_exchange = "SMART"
  c.m_currency = "USD"
  
  tws.reqMktData(1,c,"",False)
  sleep(25)
  
  print 'All done'
  
  tws.disconnect()
  </code></pre>
  
  <p>Command line output:</p>
  
  <pre><code>    Server Version: 76
      TWS Time at connection:20150508 13:42:02 EST
      bid 111.42
      ask 111.5
      bid 111.43
      bid 111.44
      bid 111.42
      bid 111.38
      bid 111.32
      ask 111.44
      All done
  </code></pre>