The docs for Handling Data include sample code like:
For example ibmBar = slice.Bars["IBM"]
When I try this I get the error message:
Runtime Error: TypeError : unindexable object at OnData in main.py:line 96
TypeError : unindexable object
My ondata code looks like this:
def OnData(self, slice):
#self.Debug('Begin OnData ' +' '+str(self.Time)+' '+str(slice.Bars.Count)+' '+str(self.curPositions))
if slice.Bars.Count == 0: return
#if self.changes == None: return
for tradeBar in slice.Bars.Values:
sym = tradeBar.Symbol.Value
self.Log('tradeBar Sym: '+ sym)
crmBar = slice.Bars["CRM"]
self.Log ('slice.count: '+str(slice.Bars.Count)+' crm: '+str(crmBar.Symbol.Value))
The universe is loaded by a custom list and the code properly logs the four symbols in the slice, including CRM, before failing at crmBar=slice.Bars['CRM'].
This is obviously test code, but related to my goal to evaluate the symbols in slice in the order they are loaded in the custom universe. I want to evaluate potential trades in that order because the symbols loaded first have a better profit potential than the other symbols - if the trade is triggered.
Thanks for some help, I've spent way too much time on this simple issue.