add new list

This commit is contained in:
MuslemRahimi 2025-02-08 00:50:41 +01:00
parent d36f24e065
commit c9cf6a2aac
2 changed files with 60 additions and 13 deletions

View File

@ -810,6 +810,52 @@ async def get_most_shorted_stocks():
file.write(orjson.dumps(res_list)) file.write(orjson.dumps(res_list))
async def get_most_buybacks():
with sqlite3.connect('stocks.db') as con:
cursor = con.cursor()
cursor.execute("PRAGMA journal_mode = wal")
cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%' AND symbol NOT LIKE '%-%'")
symbols = [row[0] for row in cursor.fetchall()]
res_list = []
for symbol in symbols:
try:
stock_buybacks = stock_screener_data_dict[symbol].get('commonStockRepurchased',None)
country = stock_screener_data_dict[symbol].get('country',None)
if country == 'United States' and stock_buybacks < -1E6:
quote_data = await get_quote_data(symbol)
# Assign price and volume, and check if they meet the penny stock criteria
if quote_data:
price = round(quote_data.get('price',None), 2)
changesPercentage = round(quote_data.get('changesPercentage'), 2)
marketCap = quote_data.get('marketCap')
name = quote_data.get('name')
if abs(stock_buybacks/marketCap) < 1:
res_list.append({
'symbol': symbol,
'name': name,
'price': price,
'changesPercentage': changesPercentage,
'marketCap': marketCap,
'commonStockRepurchased': stock_buybacks
})
except:
pass
if res_list:
# Sort by market cap in descending order
res_list = sorted(res_list, key=lambda x: x['commonStockRepurchased'])[:100]
# Assign rank to each stock
for rank, item in enumerate(res_list, start=1):
item['rank'] = rank
# Write the filtered and ranked penny stocks to a JSON file
with open("json/stocks-list/list/most-buybacks.json", 'wb') as file:
file.write(orjson.dumps(res_list))
async def get_highest_oi_change(): async def get_highest_oi_change():
with sqlite3.connect('stocks.db') as con: with sqlite3.connect('stocks.db') as con:
cursor = con.cursor() cursor = con.cursor()
@ -1020,8 +1066,8 @@ async def etf_bitcoin_list():
'price': price, 'price': price,
'changesPercentage': changesPercentage 'changesPercentage': changesPercentage
}) })
except Exception as e: except:
print(f"Error processing symbol {symbol}: {e}") pass
if res_list: if res_list:
res_list = sorted(res_list, key=lambda x: x['totalAssets'], reverse=True) res_list = sorted(res_list, key=lambda x: x['totalAssets'], reverse=True)
@ -1031,8 +1077,8 @@ async def etf_bitcoin_list():
with open("json/etf-bitcoin-list/data.json", 'wb') as file: with open("json/etf-bitcoin-list/data.json", 'wb') as file:
file.write(orjson.dumps(res_list)) file.write(orjson.dumps(res_list))
except Exception as e: except:
print(f"Database error: {e}") pass
async def get_all_reits_list(cursor): async def get_all_reits_list(cursor):
base_query = """ base_query = """
@ -1185,8 +1231,8 @@ async def get_all_stock_tickers():
res_list.append(item) res_list.append(item)
except Exception as e: except:
print(f"Error processing symbol {symbol}: {e}") pass
if res_list: if res_list:
res_list = sorted(res_list, key=lambda x: x['symbol'], reverse=False) res_list = sorted(res_list, key=lambda x: x['symbol'], reverse=False)
@ -1194,8 +1240,8 @@ async def get_all_stock_tickers():
with open("json/stocks-list/list/all-stock-tickers.json", 'wb') as file: with open("json/stocks-list/list/all-stock-tickers.json", 'wb') as file:
file.write(orjson.dumps(res_list)) file.write(orjson.dumps(res_list))
except Exception as e: except:
print(f"Database error: {e}") pass
async def get_all_etf_tickers(): async def get_all_etf_tickers():
try: try:
@ -1235,8 +1281,8 @@ async def get_all_etf_tickers():
res_list.append(item) res_list.append(item)
except Exception as e: except:
print(f"Error processing symbol {symbol}: {e}") pass
if res_list: if res_list:
res_list = sorted(res_list, key=lambda x: x['symbol'], reverse=False) res_list = sorted(res_list, key=lambda x: x['symbol'], reverse=False)
@ -1244,8 +1290,8 @@ async def get_all_etf_tickers():
with open("json/stocks-list/list/all-etf-tickers.json", 'wb') as file: with open("json/stocks-list/list/all-etf-tickers.json", 'wb') as file:
file.write(orjson.dumps(res_list)) file.write(orjson.dumps(res_list))
except Exception as e: except:
print(f"Database error: {e}") pass
async def run(): async def run():
@ -1285,6 +1331,7 @@ async def run():
get_highest_option_premium(), get_highest_option_premium(),
get_etf_holding(), get_etf_holding(),
get_etf_provider(), get_etf_provider(),
get_most_buybacks(),
) )

View File

@ -4172,7 +4172,7 @@ async def get_statistics(data: FilterStockList, api_key: str = Security(get_api_
category_type = 'sector' category_type = 'sector'
elif filter_list == 'reits': elif filter_list == 'reits':
category_type = 'industry' category_type = 'industry'
elif filter_list in ['online-gambling','metaverse','sports-betting','virtual-reality','online-dating','pharmaceutical-stocks','gaming-stocks','augmented-reality','electric-vehicles','car-company-stocks','esports','clean-energy','mobile-games','social-media-stocks','ai-stocks','highest-option-premium','highest-option-iv-rank','highest-open-interest','highest-open-interest-change','most-shorted-stocks','most-ftd-shares','highest-income-tax','most-employees','highest-revenue','top-rated-dividend-stocks','penny-stocks','overbought-stocks','oversold-stocks','faang','magnificent-seven','ca','cn','de','gb','il','in','jp','nyse','nasdaq','amex','dowjones','sp500','nasdaq100','all-etf-tickers','all-stock-tickers']: elif filter_list in ['most-buybacks','online-gambling','metaverse','sports-betting','virtual-reality','online-dating','pharmaceutical-stocks','gaming-stocks','augmented-reality','electric-vehicles','car-company-stocks','esports','clean-energy','mobile-games','social-media-stocks','ai-stocks','highest-option-premium','highest-option-iv-rank','highest-open-interest','highest-open-interest-change','most-shorted-stocks','most-ftd-shares','highest-income-tax','most-employees','highest-revenue','top-rated-dividend-stocks','penny-stocks','overbought-stocks','oversold-stocks','faang','magnificent-seven','ca','cn','de','gb','il','in','jp','nyse','nasdaq','amex','dowjones','sp500','nasdaq100','all-etf-tickers','all-stock-tickers']:
category_type = 'stocks-list' category_type = 'stocks-list'
elif filter_list in ['dividend-kings','dividend-aristocrats']: elif filter_list in ['dividend-kings','dividend-aristocrats']:
category_type = 'dividends' category_type = 'dividends'