update file
This commit is contained in:
parent
e97cf5788d
commit
db5704b841
@ -5,8 +5,8 @@ import asyncio
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from benzinga import financial_data
|
from benzinga import financial_data
|
||||||
import time
|
from tqdm import tqdm
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
api_key = os.getenv('BENZINGA_API_KEY')
|
api_key = os.getenv('BENZINGA_API_KEY')
|
||||||
@ -59,7 +59,6 @@ def options_bubble_data(chunk):
|
|||||||
if item['ticker'] in ['BRK.A', 'BRK.B']:
|
if item['ticker'] in ['BRK.A', 'BRK.B']:
|
||||||
item['ticker'] = f"BRK-{item['ticker'][-1]}"
|
item['ticker'] = f"BRK-{item['ticker'][-1]}"
|
||||||
|
|
||||||
|
|
||||||
#Save raw data for each ticker for options page stack bar chart
|
#Save raw data for each ticker for options page stack bar chart
|
||||||
for ticker in chunk:
|
for ticker in chunk:
|
||||||
ticker_filtered_data = [entry for entry in res_filtered if entry['ticker'] == ticker]
|
ticker_filtered_data = [entry for entry in res_filtered if entry['ticker'] == ticker]
|
||||||
@ -92,7 +91,6 @@ def options_bubble_data(chunk):
|
|||||||
|
|
||||||
filtered_data = [item for item in res_filtered if start_date <= datetime.strptime(item['date'], '%Y-%m-%d').date() <= end_date]
|
filtered_data = [item for item in res_filtered if start_date <= datetime.strptime(item['date'], '%Y-%m-%d').date() <= end_date]
|
||||||
|
|
||||||
|
|
||||||
ticker_filtered_data = [entry for entry in filtered_data if entry['ticker'] == ticker]
|
ticker_filtered_data = [entry for entry in filtered_data if entry['ticker'] == ticker]
|
||||||
put_volume, call_volume = calculate_put_call_volumes(ticker_filtered_data)
|
put_volume, call_volume = calculate_put_call_volumes(ticker_filtered_data)
|
||||||
avg_dte = calculate_avg_dte(ticker_filtered_data)
|
avg_dte = calculate_avg_dte(ticker_filtered_data)
|
||||||
@ -105,35 +103,43 @@ def options_bubble_data(chunk):
|
|||||||
with open(f"json/options-bubble/{ticker}.json", 'w') as file:
|
with open(f"json/options-bubble/{ticker}.json", 'w') as file:
|
||||||
ujson.dump(bubble_data, file)
|
ujson.dump(bubble_data, file)
|
||||||
|
|
||||||
|
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
print(ve)
|
print(ve)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
try:
|
|
||||||
stock_con = sqlite3.connect('stocks.db')
|
|
||||||
stock_cursor = stock_con.cursor()
|
|
||||||
stock_cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%'")
|
|
||||||
stock_symbols = [row[0] for row in stock_cursor.fetchall()]
|
|
||||||
|
|
||||||
etf_con = sqlite3.connect('etf.db')
|
async def main():
|
||||||
etf_cursor = etf_con.cursor()
|
try:
|
||||||
etf_cursor.execute("SELECT DISTINCT symbol FROM etfs")
|
stock_con = sqlite3.connect('stocks.db')
|
||||||
etf_symbols = [row[0] for row in etf_cursor.fetchall()]
|
stock_cursor = stock_con.cursor()
|
||||||
|
stock_cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE marketCap >= 500E6 AND symbol NOT LIKE '%.%'")
|
||||||
|
stock_symbols = [row[0] for row in stock_cursor.fetchall()]
|
||||||
|
|
||||||
stock_con.close()
|
etf_con = sqlite3.connect('etf.db')
|
||||||
etf_con.close()
|
etf_cursor = etf_con.cursor()
|
||||||
|
etf_cursor.execute("SELECT DISTINCT symbol FROM etfs WHERE totalAssets >= 10E9")
|
||||||
|
etf_symbols = [row[0] for row in etf_cursor.fetchall()]
|
||||||
|
|
||||||
total_symbols = stock_symbols + etf_symbols
|
stock_con.close()
|
||||||
total_symbols = [item.replace("BRK-B", "BRK.B") for item in total_symbols]
|
etf_con.close()
|
||||||
|
|
||||||
chunk_size = len(total_symbols) // 40 # Divide the list into N chunks
|
total_symbols = stock_symbols + etf_symbols
|
||||||
chunks = [total_symbols[i:i + chunk_size] for i in range(0, len(total_symbols), chunk_size)]
|
total_symbols = [item.replace("BRK-B", "BRK.B") for item in total_symbols]
|
||||||
|
|
||||||
for chunk in chunks:
|
print(len(total_symbols))
|
||||||
options_bubble_data(chunk)
|
|
||||||
|
|
||||||
except Exception as e:
|
chunk_size = len(total_symbols) // 100 # Divide the list into N chunks
|
||||||
print(e)
|
chunks = [total_symbols[i:i + chunk_size] for i in range(0, len(total_symbols), chunk_size)]
|
||||||
|
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
with ThreadPoolExecutor(max_workers=2) as executor:
|
||||||
|
tasks = [loop.run_in_executor(executor, options_bubble_data, chunk) for chunk in chunks]
|
||||||
|
for f in tqdm(asyncio.as_completed(tasks), total=len(tasks)):
|
||||||
|
await f
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user