def trade(events, strategy, portfolio, execution, heartbeat):
 while True:
  try:
   event = events.get(False)
  except queue.Empty:
   pass
  else:
   if (event is not None):
    if (event.type == 'TICK'):
     logger.info('Received new tick event: %s', event)
     strategy.calculate_signals(event)
     portfolio.update_portfolio(event)
    elif (event.type == 'SIGNAL'):
     logger.info('Received new signal event: %s', event)
     portfolio.execute_signal(event)
    elif (event.type == 'ORDER'):
     logger.info('Received new order event: %s', event)
     execution.execute_order(event)
  time.sleep(heartbeat)

def trade ( events , strategy , portfolio , execution , heartbeat ) : while True : try : event = events . get ( False ) except queue . Empty : pass else : if ( event is not None ) : if ( event . type == 'TICK' ) : logger . info ( 'Received new tick event: %s' , event ) strategy . calculate_signals ( event ) portfolio . update_portfolio ( event ) elif ( event . type == 'SIGNAL' ) : logger . info ( 'Received new signal event: %s' , event ) portfolio . execute_signal ( event ) elif ( event . type == 'ORDER' ) : logger . info ( 'Received new order event: %s' , event ) execution . execute_order ( event ) time . sleep ( heartbeat )
carries out an infinite while loop that polls the events queue and directs each event to either the strategy component of the execution handler .