INNER CODE UNIT · Python
daysToexp
ldt9/PyOptionTrader · models/futures/short_strangle.py:519
daysToexp = (self.nearestDTE - datetime.date.today()).days
# get the market price of the combo order
combobars = self.ib.reqHistoricalData(
contract=self.strangle,
endDateTime='',
durationStr='60 s',
barSizeSetting='1 secs',
whatToShow='TRADES',
useRTH=True,
formatDate=1)
combo = util.df(combobars)
curr_price = round(np.nanmean(combo['close']), 2)
print(f"{self.get_timestamp()} Strangle Price: ", curr_price)
# if the difference between self.nearestDTE and today is less than 21 days
if daysToexp <= 21:
print(f"{self.get_timestamp()} Closing Open Strangle Position...")