I'm working on learning how to trade options and starting with this example from the datasets:

I can't get the actual code to work. Nothing seems to trade. Step debugging is not helping me either…but I believe this is the issue:

if self.contract and not self.portfolio[self.contract.symbol].invested and chain:

Specifically the:

self.portfolio[self.contract.symbol].invested 

Any help is appreciated…