bugfixing

This commit is contained in:
MuslemRahimi 2024-06-20 12:23:42 +02:00
parent ea3ff079aa
commit c5c2ab2a68

View File

@ -17,15 +17,25 @@ api_key = os.getenv('NASDAQ_API_KEY')
today = datetime.now() today = datetime.now()
# Calculate the date six months ago # Calculate the date six months ago
six_months_ago = today - timedelta(days=6*30) # Rough estimate, can be refined six_months_ago = today - timedelta(days=6*30) # Rough estimate, can be refined
query_template = """
query_stock_template = """
SELECT SELECT
name, marketCap, netIncome, price, volume name, price, volume
FROM FROM
stocks stocks
WHERE WHERE
symbol = ? symbol = ?
""" """
query_etf_template = """
SELECT
name, price, volume
FROM
etfs
WHERE
symbol = ?
"""
async def save_json(symbol, data): async def save_json(symbol, data):
with open(f"json/retail-volume/companies/{symbol}.json", 'w') as file: with open(f"json/retail-volume/companies/{symbol}.json", 'w') as file:
@ -95,12 +105,13 @@ async def run():
try: try:
filtered_data = [item for item in transformed_data if symbol == item['symbol']] filtered_data = [item for item in transformed_data if symbol == item['symbol']]
res = filter_past_six_months(filtered_data) res = filter_past_six_months(filtered_data)
query_template = query_stocks_template if symbol in stocks_symbols else query_etf_template
connection = con if symbol in stocks_symbols else etf_con
#Compute strength of retail investors #Compute strength of retail investors
last_trade = res[-1]['traded'] last_trade = res[-1]['traded']
last_sentiment = int(res[-1]['sentiment']) last_sentiment = int(res[-1]['sentiment'])
last_date = res[-1]['date'] last_date = res[-1]['date']
data = pd.read_sql_query(query_template, con, params=(symbol,)) data = pd.read_sql_query(query_template, connection, params=(symbol,))
price = float(data['price'].iloc[0]) price = float(data['price'].iloc[0])
retail_volume = int(last_trade/price) retail_volume = int(last_trade/price)
total_volume = int(data['volume'].iloc[0]) total_volume = int(data['volume'].iloc[0])