Update main.py
Browse files
main.py
CHANGED
@@ -2,9 +2,13 @@ from fastapi.responses import HTMLResponse
|
|
2 |
from fastapi.templating import Jinja2Templates
|
3 |
from fastapi import FastAPI, Request, HTTPException
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
5 |
|
6 |
app = FastAPI(swagger_ui_parameters={"syntaxHighlight.theme": "obsidian"})
|
7 |
|
|
|
|
|
8 |
origins = ["*"]
|
9 |
|
10 |
app.add_middleware(
|
@@ -22,18 +26,18 @@ async def read_root(request: Request):
|
|
22 |
return templates.TemplateResponse("hello.html", {"request": request})
|
23 |
|
24 |
|
25 |
-
@app.get('/
|
26 |
-
async def get_data(ticker: str
|
27 |
try:
|
28 |
-
response =
|
29 |
-
return response
|
30 |
except:
|
31 |
return {"Timeout" : "Error"}
|
32 |
|
33 |
-
@app.get('/
|
34 |
-
async def get_stocks_data():
|
35 |
try:
|
36 |
-
response = "
|
37 |
return response
|
38 |
except:
|
39 |
-
return {"
|
|
|
2 |
from fastapi.templating import Jinja2Templates
|
3 |
from fastapi import FastAPI, Request, HTTPException
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
+
from utils import fetcher
|
6 |
+
|
7 |
|
8 |
app = FastAPI(swagger_ui_parameters={"syntaxHighlight.theme": "obsidian"})
|
9 |
|
10 |
+
fetcher = StockDataFetcher()
|
11 |
+
|
12 |
origins = ["*"]
|
13 |
|
14 |
app.add_middleware(
|
|
|
26 |
return templates.TemplateResponse("hello.html", {"request": request})
|
27 |
|
28 |
|
29 |
+
@app.get('/ltp')
|
30 |
+
async def get_data(ticker: str):
|
31 |
try:
|
32 |
+
response = fetcher.fetch_latest_price(ticker)
|
33 |
+
return {'ltp' :response}
|
34 |
except:
|
35 |
return {"Timeout" : "Error"}
|
36 |
|
37 |
+
@app.get('/historical')
|
38 |
+
async def get_stocks_data(ticker: str, intervals: int, days: int):
|
39 |
try:
|
40 |
+
response = fetcher.fetch_stock_data(ticker, 15, 10).to_dict(orient="records")
|
41 |
return response
|
42 |
except:
|
43 |
+
return {"data" : response}
|