Skip to content

Commit

Permalink
update iv cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Aug 2, 2024
1 parent 8d03ab6 commit e577eb7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/cron_implied_volatility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

from dotenv import load_dotenv
import os

keys_to_keep = {'date','stockpx', 'iv60', 'iv90', '252dclshv','60dorhv'}

load_dotenv()
api_key = os.getenv('NASDAQ_API_KEY')


# Get today's date
today = datetime.today()
# Calculate the date six months ago
dates = [today - timedelta(days=i) for i in range(365)] #six months ago
# Calculate the date 12 months ago
dates = [today - timedelta(days=i) for i in range(365)]
date_str = ','.join(date.strftime('%Y-%m-%d') for date in dates)

async def save_json(symbol, data):
Expand Down Expand Up @@ -77,6 +80,8 @@ async def run():
# Assuming the number of columns matches the length of each element in `data`
filtered_data.append({columns[i]["name"]: element[i] for i in range(len(columns))})

filtered_data = [{k: v for k, v in item.items() if k in keys_to_keep} for item in filtered_data]

try:
sorted_data = sorted(filtered_data, key=lambda x: datetime.strptime(x['date'], '%Y-%m-%d'))
if len(sorted_data) > 0:
Expand Down

0 comments on commit e577eb7

Please sign in to comment.