title: Re-using Queued Data in Python
body: <p>I have a data stream that adds price information to a queue where it is consumed while processing an order.  Could someone advise on how I could save the last price streamed and only send to the queue IF the price were (for instance) higher than the last, or vice versa?</p>
  
  <p>Here is my code, thanks in advance for any help!</p>
  
  <pre><code>def stream_to_queue(self):
          response = self.connect_to_stream()
          if response.status_code != 200:
              return
          for line in response.iter_lines(1):
              if line:
                  try:
                      msg = json.loads(line)
                  except Exception as e:
                      print "Caught exception when converting message into json\n" + str(e)
                      return
                  if msg.has_key("instrument") or msg.has_key("tick"):
                      print msg["tick"]
                      instrument = msg["tick"]["instrument"]
                      time = msg["tick"]["time"]
                      bid = msg["tick"]["bid"]
                      ask = msg["tick"]["ask"]
                      stop = msg["tick"]["ask"]
                      tev = TickEvent(instrument, time, bid, ask)
                      self.events_queue.put(tev)
  </code></pre>