bugfixing

This commit is contained in:
MuslemRahimi 2025-01-31 23:45:45 +01:00
parent ea2ae8d168
commit c8146c9af4
2 changed files with 35 additions and 26 deletions

View File

@ -2560,7 +2560,7 @@ async def get_ipo_calendar(data:IPOData, api_key: str = Security(get_api_key)):
data = orjson.dumps(res) data = orjson.dumps(res)
compressed_data = gzip.compress(data) compressed_data = gzip.compress(data)
redis_client.set(cache_key, compressed_data) redis_client.set(cache_key, compressed_data)
redis_client.expire(cache_key, 3600 * 24) # Set cache expiration time to 1 day redis_client.expire(cache_key, 60*5) # Set cache expiration time to 1 day
return StreamingResponse( return StreamingResponse(
io.BytesIO(compressed_data), io.BytesIO(compressed_data),

View File

@ -1767,17 +1767,9 @@ async def get_ipo_calendar(con, symbols):
return datetime.date(year, month, 1) + datetime.timedelta(days=30) return datetime.date(year, month, 1) + datetime.timedelta(days=30)
start_date = datetime.date(2019, 1, 1) start_date = datetime.date(2019, 1, 1)
end_date = datetime.date.today() end_date = datetime.date.today()+timedelta(2)
urls = [] urls = []
combined_data = [] combined_data = []
query_quote = """
SELECT
quote
FROM
stocks
WHERE
symbol = ?
"""
query_open_price = """ query_open_price = """
SELECT open SELECT open
FROM "{ticker}" FROM "{ticker}"
@ -1803,6 +1795,7 @@ async def get_ipo_calendar(con, symbols):
# Move to next quarter # Move to next quarter
current_date = end_of_quarter + datetime.timedelta(days=1) current_date = end_of_quarter + datetime.timedelta(days=1)
#print(urls) #print(urls)
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
tasks = [session.get(url) for url in urls] tasks = [session.get(url) for url in urls]
@ -1811,25 +1804,43 @@ async def get_ipo_calendar(con, symbols):
for sublist in data: for sublist in data:
for item in sublist: for item in sublist:
if item not in combined_data and item['symbol'] in symbols and item['exchange'] in ['NASDAQ Global','NASDAQ Capital','NASDAQ Global Select','NYSE','NASDAQ','Nasdaq','Nyse','Amex']: try:
if item['priceRange'] != None: if (
item['priceRange'] = round(float(item['priceRange'].split('-')[0]),2) item not in combined_data
and not any(excluded in item['company'] for excluded in ['USD', 'Funds', 'Trust', 'ETF', 'Rupee'])
and any(item['exchange'].lower() == exchange for exchange in ['nasdaq global', 'nasdaq capital', 'nasdaq global select', 'nyse', 'nasdaq', 'amex'])
):
combined_data.append(item) if item['priceRange'] != None:
item['priceRange'] = round(float(item['priceRange'].split('-')[0]),2)
elif item['shares'] != None and item['marketCap'] != None:
item['priceRange'] = round(item['marketCap']/item['shares'],2)
combined_data.append(item)
except:
pass
res = [] res = []
for entry in combined_data: for entry in combined_data:
try: try:
symbol = entry['symbol'] symbol = entry['symbol']
with open(f"json/quote/{symbol}.json","r") as file: try:
quote_data = ujson.load(file) with open(f"json/quote/{symbol}.json","r") as file:
quote_data = ujson.load(file)
except:
quote_data = {'price': None, 'changesPercentage': None}
entry['currentPrice'] = quote_data.get('price',None) entry['currentPrice'] = quote_data.get('price',None)
df = pd.read_sql_query(query_open_price.format(ticker = entry['symbol']), con) try:
entry['ipoPrice'] = round(df['open'].iloc[0], 2) if df['open'].iloc[0] != 0 else None df = pd.read_sql_query(query_open_price.format(ticker = entry['symbol']), con)
entry['ipoPrice'] = round(df['open'].iloc[0], 2) if df['open'].iloc[0] else None
except Exception as e:
entry['ipoPrice'] = round(entry['priceRange'], 2) if entry['priceRange'] else None
if entry['ipoPrice'] != None and entry['currentPrice'] != None and entry['currentPrice'] != 0: if entry['ipoPrice'] != None:
entry['return'] = None if (entry['ipoPrice'] in (0, None) or entry['currentPrice'] in (0, None)) else round(((entry['currentPrice'] / entry['ipoPrice'] - 1) * 100), 2) try:
entry['return'] = None if (entry['ipoPrice'] in (0, None) or entry['currentPrice'] in (0, None)) else round(((entry['currentPrice'] / entry['ipoPrice'] - 1) * 100), 2)
except:
entry['return'] = None
res.append({ res.append({
"symbol": entry["symbol"], "symbol": entry["symbol"],
"name": entry["company"], "name": entry["company"],
@ -1842,7 +1853,6 @@ async def get_ipo_calendar(con, symbols):
pass pass
res_sorted = sorted(res, key=lambda x: x['ipoDate'], reverse=True) res_sorted = sorted(res, key=lambda x: x['ipoDate'], reverse=True)
return res_sorted return res_sorted
@ -1861,6 +1871,10 @@ async def save_json_files():
etf_symbols = [row[0] for row in etf_cursor.fetchall()] etf_symbols = [row[0] for row in etf_cursor.fetchall()]
data = await get_ipo_calendar(con, symbols)
with open(f"json/ipo-calendar/data.json", 'w') as file:
ujson.dump(data, file)
economic_list = await get_economic_calendar() economic_list = await get_economic_calendar()
if len(economic_list) > 0: if len(economic_list) > 0:
with open(f"json/economic-calendar/calendar.json", 'w') as file: with open(f"json/economic-calendar/calendar.json", 'w') as file:
@ -1870,9 +1884,6 @@ async def save_json_files():
with open(f"json/stock-screener/data.json", 'w') as file: with open(f"json/stock-screener/data.json", 'w') as file:
ujson.dump(stock_screener_data, file) ujson.dump(stock_screener_data, file)
data = await get_ipo_calendar(con, symbols)
with open(f"json/ipo-calendar/data.json", 'w') as file:
ujson.dump(data, file)
earnings_list = await get_earnings_calendar(con,symbols) earnings_list = await get_earnings_calendar(con,symbols)
with open(f"json/earnings-calendar/calendar.json", 'w') as file: with open(f"json/earnings-calendar/calendar.json", 'w') as file:
@ -1892,8 +1903,6 @@ async def save_json_files():
data = await etf_providers(etf_con, etf_symbols) data = await etf_providers(etf_con, etf_symbols)
with open(f"json/all-etf-providers/data.json", 'w') as file: with open(f"json/all-etf-providers/data.json", 'w') as file:
ujson.dump(data, file) ujson.dump(data, file)
con.close() con.close()