Skip to content

Commit 69cf5dc

Browse files
use filter_dates
1 parent 2c79c66 commit 69cf5dc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

automation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def compute_recommendation(ticker):
124124
if option_chain:
125125
try:
126126
exp_dates = sorted(option_chain.keys())
127-
today = datetime.today().date()
128-
# only consider expiries strictly after today (no 0DTE)
129-
exp_dates_filtered = [d for d in exp_dates if (datetime.strptime(d, "%Y-%m-%d").date() - today).days > 0]
130-
if len(exp_dates_filtered) < 2:
131-
raise Exception("Not enough option data from Alpaca.")
127+
# apply 45-day window and drop 0DTE using filter_dates()
128+
try:
129+
exp_dates_filtered = filter_dates(exp_dates)
130+
except ValueError:
131+
return "Error: Not enough option data."
132132
underlying_price = None
133133
try:
134134
from alpaca.data.historical import StockHistoricalDataClient

0 commit comments

Comments
 (0)