I'm working with tick data for /ES and simply trying to print out contract information, but having some issues:
1) LastPrice is sometimes 0.0.
2) I can't access other members of the Tick Class, such as Quantity or Suspicious, shown here: https://www.quantconnect.com/lean/documentation/topic24387.html
3. I thought that OnData should be called for each tick in the backtest, but it is only called once/day. Is that expected? Do I have to set the contract fresh everytime OnData is called or some other housekeeping to ensure it is called for each tick?
def OnData(self, data):
for chain in data.FutureChains.Values:
contracts = list(chain.Contracts.Values)
chain_contracts = list(contracts) #[contract for contract in chain]
chain_contracts = sorted(chain_contracts, key=lambda x: x.Expiry)
self.contract = chain_contracts[0] # this is ES19M20
if self.contract != None:
self.Debug("Using contract: {} ".format(self.contract.Symbol.Value))
self.Debug("OnData: " + str(self.Time))
self.Debug(f"Price: {self.contract.LastPrice}") # sometimes gives 0.0
self.Debug(f"QTY: {self.contract.Quantity}") # errors out
self.Debug(f"Type: {self.contract.TickType}") # errors out
self.Debug(f"Suspicious?: {self.contract.Suspicious}") # errors out
Thanks!