bugfixing: add only symbols that exist in db
This commit is contained in:
parent
35739930d1
commit
316e2c15c0
@ -9,10 +9,28 @@ import time
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
headers = {"accept": "application/json"}
|
headers = {"accept": "application/json"}
|
||||||
|
|
||||||
|
|
||||||
|
con = sqlite3.connect('stocks.db')
|
||||||
|
etf_con = sqlite3.connect('etf.db')
|
||||||
|
|
||||||
|
cursor = con.cursor()
|
||||||
|
cursor.execute("PRAGMA journal_mode = wal")
|
||||||
|
cursor.execute("SELECT DISTINCT symbol FROM stocks")
|
||||||
|
stock_symbols = [row[0] for row in cursor.fetchall()]
|
||||||
|
|
||||||
|
etf_cursor = etf_con.cursor()
|
||||||
|
etf_cursor.execute("PRAGMA journal_mode = wal")
|
||||||
|
etf_cursor.execute("SELECT DISTINCT symbol FROM etfs")
|
||||||
|
etf_symbols = [row[0] for row in etf_cursor.fetchall()]
|
||||||
|
|
||||||
|
total_symbols = stock_symbols+etf_symbols
|
||||||
|
|
||||||
|
con.close()
|
||||||
|
etf_con.close()
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
benzinga_api_key = os.getenv('BENZINGA_API_KEY')
|
benzinga_api_key = os.getenv('BENZINGA_API_KEY')
|
||||||
@ -51,11 +69,14 @@ async def run():
|
|||||||
try:
|
try:
|
||||||
with open(f"json/options-flow/feed/data.json", 'r') as file:
|
with open(f"json/options-flow/feed/data.json", 'r') as file:
|
||||||
options_flow = ujson.load(file)
|
options_flow = ujson.load(file)
|
||||||
|
|
||||||
|
# Filter the options_flow to include only items with ticker in total_symbol
|
||||||
|
options_flow = [item for item in options_flow if item['ticker'] in total_symbols]
|
||||||
|
|
||||||
options_flow = sorted(options_flow, key=lambda x: x['cost_basis'], reverse=True)
|
options_flow = sorted(options_flow, key=lambda x: x['cost_basis'], reverse=True)
|
||||||
options_flow = [{key: item[key] for key in ['cost_basis', 'ticker','assetType', 'date_expiration', 'put_call', 'sentiment', 'strike_price']} for item in options_flow[0:4]]
|
options_flow = [{key: item[key] for key in ['cost_basis', 'ticker','assetType', 'date_expiration', 'put_call', 'sentiment', 'strike_price']} for item in options_flow[0:4]]
|
||||||
except:
|
except:
|
||||||
options_flow = []
|
options_flow = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"json/wiim/rss-feed/data.json", 'r') as file:
|
with open(f"json/wiim/rss-feed/data.json", 'r') as file:
|
||||||
wiim_feed = ujson.load(file)[0:5]
|
wiim_feed = ujson.load(file)[0:5]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user