Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Newbie: using data.history to get price, want to put ticker symbol of currently referenced stock in log

I want to see what my code is doing while I teach myself...
I am trying to simply print the ticker symbol in the log. Any help is appreciated. I keep spinning my wheels.

def initialize(context):

context.securities = [sid(39840), sid(27817)]

def handle_data(context, data):

price_history = data.history(context.securities, "price", bar_count=2, frequency="1d")  
for stock in context.securities:  
    prev_bar = price_history[stock][-2]  
    curr_bar = price_history[stock][-1]  

    log.info({tickersymbolhere} + " prev: " + str(prev_bar))  
    log.info({tickersymbolhere} + " curr: " + str(curr_bar))  
1 response

The securities are 'equity objects'. One of the properties is 'symbol'. Look here for some of the other properties and methods https://www.quantopian.com/help#api-sidinfo. So you can access the symbol as simply as 'stock.symbol'.

 log.info("{} prev: {}".format(stock.symbol, prev_bar))  
 log.info("{} curr: {}".format(stock.symbol, curr_bar))

You may not want to do that in the 'handle data' method. That get's executed every minute and the logs will fill up fast.