File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1818import os
1919from dotenv import load_dotenv
2020import argparse
21- from alpaca_integration import get_alpaca_option_chain
21+ from alpaca_integration import get_alpaca_option_chain , init_alpaca_client
2222from alpaca .data .historical .option import OptionHistoricalDataClient
2323from alpaca .data .requests import OptionLatestQuoteRequest , OptionSnapshotRequest
2424
@@ -264,7 +264,17 @@ def compute_recommendation(ticker):
264264
265265
266266def get_tomorrows_earnings ():
267- tomorrow = (datetime .now () + timedelta (days = 1 )).strftime ('%Y-%m-%d' )
267+ # Determine next open market day using Alpaca clock; fallback to next calendar day
268+ client = init_alpaca_client ()
269+ if client :
270+ try :
271+ clock = client .get_clock ()
272+ next_open_date = clock .next_open .date ()
273+ except Exception :
274+ next_open_date = (datetime .now () + timedelta (days = 1 )).date ()
275+ else :
276+ next_open_date = (datetime .now () + timedelta (days = 1 )).date ()
277+ tomorrow = next_open_date .strftime ('%Y-%m-%d' )
268278 base_url = "https://www.dolthub.com/api/v1alpha1/post-no-preference/earnings/master"
269279 query = f"SELECT * FROM `earnings_calendar` where date = '{ tomorrow } ' ORDER BY `act_symbol` ASC, `date` ASC LIMIT 1000;"
270280 url = f"{ base_url } ?q={ urllib .parse .quote (query )} "
You can’t perform that action at this time.
0 commit comments