Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Jan 31, 2025
1 parent ea2ae8d commit c8146c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ async def get_ipo_calendar(data:IPOData, api_key: str = Security(get_api_key)):
data = orjson.dumps(res)
compressed_data = gzip.compress(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(
io.BytesIO(compressed_data),
Expand Down
61 changes: 35 additions & 26 deletions app/restart_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1767,17 +1767,9 @@ def get_end_of_quarter(year, quarter):
return datetime.date(year, month, 1) + datetime.timedelta(days=30)

start_date = datetime.date(2019, 1, 1)
end_date = datetime.date.today()
end_date = datetime.date.today()+timedelta(2)
urls = []
combined_data = []
query_quote = """
SELECT
quote
FROM
stocks
WHERE
symbol = ?
"""
query_open_price = """
SELECT open
FROM "{ticker}"
Expand All @@ -1803,6 +1795,7 @@ def get_end_of_quarter(year, quarter):
# Move to next quarter
current_date = end_of_quarter + datetime.timedelta(days=1)


#print(urls)
async with aiohttp.ClientSession() as session:
tasks = [session.get(url) for url in urls]
Expand All @@ -1811,25 +1804,43 @@ def get_end_of_quarter(year, quarter):

for sublist in data:
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']:
if item['priceRange'] != None:
item['priceRange'] = round(float(item['priceRange'].split('-')[0]),2)

combined_data.append(item)
try:
if (
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'])
):

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 = []
for entry in combined_data:
try:
symbol = entry['symbol']
with open(f"json/quote/{symbol}.json","r") as file:
quote_data = ujson.load(file)
try:
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)
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] != 0 else None
try:
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:
entry['return'] = None if (entry['ipoPrice'] in (0, None) or entry['currentPrice'] in (0, None)) else round(((entry['currentPrice'] / entry['ipoPrice'] - 1) * 100), 2)
if entry['ipoPrice'] != None:
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({
"symbol": entry["symbol"],
"name": entry["company"],
Expand All @@ -1842,7 +1853,6 @@ def get_end_of_quarter(year, quarter):
pass

res_sorted = sorted(res, key=lambda x: x['ipoDate'], reverse=True)

return res_sorted


Expand All @@ -1861,6 +1871,10 @@ async def save_json_files():
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()
if len(economic_list) > 0:
with open(f"json/economic-calendar/calendar.json", 'w') as file:
Expand All @@ -1870,9 +1884,6 @@ async def save_json_files():
with open(f"json/stock-screener/data.json", 'w') as 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)
with open(f"json/earnings-calendar/calendar.json", 'w') as file:
Expand All @@ -1892,8 +1903,6 @@ async def save_json_files():
data = await etf_providers(etf_con, etf_symbols)
with open(f"json/all-etf-providers/data.json", 'w') as file:
ujson.dump(data, file)




con.close()
Expand Down

0 comments on commit c8146c9

Please sign in to comment.