update for holiday

This commit is contained in:
MuslemRahimi 2024-11-28 12:44:32 +01:00
parent a3fa23b027
commit dbf367783e

View File

@ -5,16 +5,41 @@ import sqlite3
from datetime import datetime, timedelta, time from datetime import datetime, timedelta, time
import pytz import pytz
import pandas as pd import pandas as pd
from GetStartEndDate import GetStartEndDate from GetStartEndDate import GetStartEndDate
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
load_dotenv() load_dotenv()
api_key = os.getenv('FMP_API_KEY') api_key = os.getenv('FMP_API_KEY')
def check_market_hours():
holidays = [
"2024-01-01", "2024-01-15", "2024-02-19", "2024-03-29",
"2024-05-27", "2024-06-19", "2024-07-04", "2024-09-02",
"2024-11-28", "2024-12-25"
]
# Get the current date and time in ET (Eastern Time)
et_timezone = pytz.timezone('America/New_York')
current_time = datetime.now(et_timezone)
current_date_str = current_time.strftime('%Y-%m-%d')
current_hour = current_time.hour
current_minute = current_time.minute
current_day = current_time.weekday() # Monday is 0, Sunday is 6
# Check if the current date is a holiday or weekend
is_weekend = current_day >= 5 # Saturday (5) or Sunday (6)
is_holiday = current_date_str in holidays
# Determine the market status
if is_weekend or is_holiday:
return False #"Market is closed."
elif 9 <= current_hour < 16 or (current_hour == 17 and current_minute == 0):
return True #"Market hours."
else:
return False #"Market is closed."
async def save_price_data(symbol, data): async def save_price_data(symbol, data):
with open(f"json/one-day-price/{symbol}.json", 'w') as file: with open(f"json/one-day-price/{symbol}.json", 'w') as file:
@ -117,13 +142,9 @@ async def run():
etf_con.close() etf_con.close()
crypto_con.close() crypto_con.close()
new_york_tz = pytz.timezone('America/New_York')
current_time_ny = datetime.now(new_york_tz)
market_open = (current_time_ny.hour == 9 and current_time_ny.minute >= 30) or \
(current_time_ny.hour > 9 and current_time_ny.hour < 17) or \
(current_time_ny.hour == 17 and current_time_ny.minute == 0)
total_symbols = stocks_symbols + etf_symbols + crypto_symbols total_symbols = stocks_symbols + etf_symbols + crypto_symbols
market_open = check_market_hours()
if market_open: if market_open:
chunk_size = 1000 chunk_size = 1000