diff --git a/app/api/v1/routes/news.py b/app/api/v1/routes/news.py new file mode 100644 index 0000000..17fca13 --- /dev/null +++ b/app/api/v1/routes/news.py @@ -0,0 +1,35 @@ +from fastapi import APIRouter, Depends +import requests +from app.core.config import settings +from app.core.websocket import start_finnhub_websocket + +router = APIRouter() + +@router.get("/search") +async def lookup(query: str, exchange: str | None = None): + """ + API to search for a stock symbol. + """ + params = { + "token": settings.FINNHUB_API_KEY, + "q": query + } + + if exchange: + params["exchange"] = exchange + + response = requests.get("https://finnhub.io/api/v1/search", params=params) + return response.json() + +@router.get("/marketnews") +async def market_news(): + """ + API to get latest market news. + """ + params = { + "token": settings.FINNHUB_API_KEY, + "category": "general" + } + + response = requests.get("https://finnhub.io/api/v1/news", params=params) + return response.json() \ No newline at end of file diff --git a/app/main.py b/app/main.py index 7121252..f9b2c76 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,7 @@ from fastapi import FastAPI from app.core.config import settings from app.api.v1.routes import stock +from app.api.v1.routes import news from app.ws.routes import trades app = FastAPI() @@ -9,6 +10,7 @@ app = FastAPI() @app.on_event("startup") async def startup_event(): app.include_router(stock.router, prefix="/api/v1") + app.include_router(news.router, prefix="/api/v1") app.include_router(trades.router, prefix="/ws") pass