Skip to content

Commit 8c32fc5

Browse files
next day
1 parent 47fd52a commit 8c32fc5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

automation.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
from dotenv import load_dotenv
2020
import argparse
21-
from alpaca_integration import get_alpaca_option_chain
21+
from alpaca_integration import get_alpaca_option_chain, init_alpaca_client
2222
from alpaca.data.historical.option import OptionHistoricalDataClient
2323
from alpaca.data.requests import OptionLatestQuoteRequest, OptionSnapshotRequest
2424

@@ -264,7 +264,17 @@ def compute_recommendation(ticker):
264264

265265

266266
def 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)}"

0 commit comments

Comments
 (0)