From ef5171fc2c622a8a2db923b1c3ab91f06ffb4523 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 10 Feb 2025 10:02:06 +0100 Subject: [PATCH] bugfixing --- app/cron_options_gex_dex.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/cron_options_gex_dex.py b/app/cron_options_gex_dex.py index 41bff35..0e6b5d5 100644 --- a/app/cron_options_gex_dex.py +++ b/app/cron_options_gex_dex.py @@ -35,7 +35,7 @@ index_symbols =["^SPX","^VIX"] con.close() etf_con.close() -total_symbols = index_symbols #stocks_symbols+etf_symbols+index_symbols +total_symbols = stocks_symbols+etf_symbols+index_symbols def save_json(data, symbol, directory_path): os.makedirs(directory_path, exist_ok=True) # Ensure the directory exists @@ -67,6 +67,7 @@ def get_contracts_from_directory(directory: str): def get_expiration_date(option_symbol): # Define regex pattern to match the symbol structure match = re.match(r"(\^?[A-Z]+)(\d{6})([CP])(\d+)", option_symbol) + if not match: raise ValueError(f"Invalid option_symbol format: {option_symbol}") @@ -74,6 +75,7 @@ def get_expiration_date(option_symbol): # Convert expiration to datetime date_expiration = datetime.strptime(expiration, "%y%m%d").date() + return date_expiration def aggregate_data_by_strike(symbol): @@ -90,7 +92,6 @@ def aggregate_data_by_strike(symbol): # Only consider contracts that haven't expired contract_list = [item for item in contract_list if get_expiration_date(item) >= today] - # Load historical price data with open(f"json/historical-price/max/{symbol}.json", "r") as file: price_list = orjson.loads(file.read()) @@ -119,6 +120,7 @@ def aggregate_data_by_strike(symbol): gamma = latest_entry.get("gamma", 0) or 0 delta = latest_entry.get("delta", 0) or 0 + # Find the matching spot price for the date matching_price = next((p for p in price_list if p.get("time") == date), None) spot_price = matching_price["close"] if matching_price else 0