1515import json
1616from redis import asyncio as aioredis
1717# Custom imports
18- from topStocks import get_top_stocks
18+ from topStocks import get_top_stocks , get_stock
1919from ask import groq_chat
2020from stockNews import fetch_news
2121from agents import multi_ai
@@ -79,11 +79,11 @@ async def read_top_stocks(cache: RedisBackend = Depends(get_cache)):
7979 return json .loads (cached_result )
8080
8181 top_stocks = ['AAPL' , 'MSFT' , 'AMZN' , 'GOOGL' ]
82- stock = " " .join (top_stocks )
83- stock_info = get_top_stocks (stock )
82+ stocks = " " .join (top_stocks )
83+ stocks_info = get_top_stocks (stocks )
8484
85- await cache .set (cache_key , json .dumps (stock_info ), 10 )
86- return stock_info
85+ await cache .set (cache_key , json .dumps (stocks_info ), 10 )
86+ return stocks_info
8787
8888@app .get ("/stock-news" )
8989async def stock_news (cache : RedisBackend = Depends (get_cache )):
@@ -95,6 +95,15 @@ async def stock_news(cache: RedisBackend = Depends(get_cache)):
9595 await cache .set (cache_key , json .dumps (news_stack ), 300 )
9696 return news_stack
9797
98+ @app .get ("stocks/{name}" )
99+ async def read_stock (name : str , cache : RedisBackend = Depends (get_cache )):
100+ cache_key = "stock"
101+ cached_result = await cache .get (cache_key )
102+ if cached_result :
103+ return json .loads (cached_result )
104+ stock_info = get_stock (name )
105+ await cache .set (cache_key , json .dumps (stock_info ), 10 )
106+
98107
99108@app .get ("health/" ) # Changed to GET since it's retrieving status
100109async def health_check ():
0 commit comments