bugfixing

This commit is contained in:
MuslemRahimi 2024-12-27 09:45:59 +01:00
parent 774cec78cf
commit 1f779d5e20
2 changed files with 21 additions and 9 deletions

View File

@ -41,7 +41,7 @@ def get_quote_data(symbol):
def save_to_daily_file(data, directory): def save_to_daily_file(data, directory):
try: 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() seen = set()
unique_data = [] unique_data = []
@ -54,10 +54,13 @@ def save_to_daily_file(data, directory):
# Sort the data by date # Sort the data by date
latest_data = sorted(unique_data, key=lambda x: datetime.fromisoformat(x['date'].replace('Z', '+00:00')), reverse=True) 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 json_file_path = os.path.join(directory, f"{first_date}.json")
today = datetime.now().strftime('%Y-%m-%d')
json_file_path = os.path.join(directory, f"{today}.json")
# Ensure the directory exists # Ensure the directory exists
os.makedirs(directory, exist_ok=True) os.makedirs(directory, exist_ok=True)
@ -72,6 +75,7 @@ def save_to_daily_file(data, directory):
def get_data(): def get_data():
try: try:
response = requests.get(url, headers=headers, params=querystring) response = requests.get(url, headers=headers, params=querystring)
@ -90,6 +94,9 @@ def main():
# Fetch new data from the API # Fetch new data from the API
data = get_data() data = get_data()
print(data[0])
res = [] res = []
for item in data: for item in data:
symbol = item['ticker'] symbol = item['ticker']

View File

@ -6,7 +6,7 @@ import subprocess
import threading # Import threading module for parallel execution import threading # Import threading module for parallel execution
#import logging # Import logging module #import logging # Import logging module
#from logging.handlers import RotatingFileHandler #from logging.handlers import RotatingFileHandler
from pytz import timezone
from dotenv import load_dotenv from dotenv import load_dotenv
import os import os
@ -17,6 +17,7 @@ job_status = {
'options_flow_job': {'running': False}, 'options_flow_job': {'running': False},
} }
ny_tz = timezone('America/New_York')
# Setup logging # Setup logging
''' '''
@ -58,13 +59,17 @@ def run_command(command):
''' '''
def run_dark_pool_flow(): def run_dark_pool_flow():
week = datetime.today().weekday() now = datetime.now(ny_tz)
if week <= 4: week = now.weekday()
hour = now.hour
if week <= 4 and 8 <= hour < 20:
run_command(["python3", "cron_dark_pool_flow.py"]) run_command(["python3", "cron_dark_pool_flow.py"])
def run_fda_calendar(): def run_fda_calendar():
week = datetime.today().weekday() now = datetime.now(ny_tz)
if week <= 4: week = now.weekday()
hour = now.hour
if week <= 4 and 8 <= hour < 20:
run_command(["python3", "cron_fda_calendar.py"]) run_command(["python3", "cron_fda_calendar.py"])
def run_cron_insider_trading(): def run_cron_insider_trading():