From 1f779d5e20d7bb9bf7a4f1f1f678c35b4018df14 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 27 Dec 2024 09:45:59 +0100 Subject: [PATCH] bugfixing --- app/cron_dark_pool_flow.py | 15 +++++++++++---- app/primary_cron_job.py | 15 ++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/cron_dark_pool_flow.py b/app/cron_dark_pool_flow.py index 66518fd..96cb6c9 100644 --- a/app/cron_dark_pool_flow.py +++ b/app/cron_dark_pool_flow.py @@ -41,7 +41,7 @@ def get_quote_data(symbol): def save_to_daily_file(data, directory): try: - # Create a set to track unique entries based on a combination of 'ticker' and 'date' + # Create a set to track unique entries based on a combination of 'ticker' and 'trackingID' seen = set() unique_data = [] @@ -54,10 +54,13 @@ def save_to_daily_file(data, directory): # Sort the data by date latest_data = sorted(unique_data, key=lambda x: datetime.fromisoformat(x['date'].replace('Z', '+00:00')), reverse=True) + # Use the date from the first element of sorted data + if latest_data: + first_date = datetime.fromisoformat(latest_data[0]['date'].replace('Z', '+00:00')).strftime('%Y-%m-%d') + else: + first_date = datetime.now().strftime('%Y-%m-%d') # Fallback in case data is empty - # Get today's date - today = datetime.now().strftime('%Y-%m-%d') - json_file_path = os.path.join(directory, f"{today}.json") + json_file_path = os.path.join(directory, f"{first_date}.json") # Ensure the directory exists os.makedirs(directory, exist_ok=True) @@ -72,6 +75,7 @@ def save_to_daily_file(data, directory): + def get_data(): try: response = requests.get(url, headers=headers, params=querystring) @@ -90,6 +94,9 @@ def main(): # Fetch new data from the API data = get_data() + + print(data[0]) + res = [] for item in data: symbol = item['ticker'] diff --git a/app/primary_cron_job.py b/app/primary_cron_job.py index 0edd384..671ffa5 100755 --- a/app/primary_cron_job.py +++ b/app/primary_cron_job.py @@ -6,7 +6,7 @@ import subprocess import threading # Import threading module for parallel execution #import logging # Import logging module #from logging.handlers import RotatingFileHandler - +from pytz import timezone from dotenv import load_dotenv import os @@ -17,6 +17,7 @@ job_status = { 'options_flow_job': {'running': False}, } +ny_tz = timezone('America/New_York') # Setup logging ''' @@ -58,13 +59,17 @@ def run_command(command): ''' def run_dark_pool_flow(): - week = datetime.today().weekday() - if week <= 4: + now = datetime.now(ny_tz) + week = now.weekday() + hour = now.hour + if week <= 4 and 8 <= hour < 20: run_command(["python3", "cron_dark_pool_flow.py"]) def run_fda_calendar(): - week = datetime.today().weekday() - if week <= 4: + now = datetime.now(ny_tz) + week = now.weekday() + hour = now.hour + if week <= 4 and 8 <= hour < 20: run_command(["python3", "cron_fda_calendar.py"]) def run_cron_insider_trading():