File size: 2,369 Bytes
a8cf3d1 4799cc5 a8cf3d1 705f945 a8cf3d1 c0c8bed a8cf3d1 d4426e3 c0c8bed a8cf3d1 c0c8bed a8cf3d1 c0c8bed a8cf3d1 c0c8bed 5bb19c3 4f329ab 5bb19c3 024dd50 5bb19c3 4f329ab 5bb19c3 4f329ab 5bb19c3 024dd50 5bb19c3 024dd50 5bb19c3 4f329ab a8cf3d1 4f329ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import FastAPI, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from utils import StockDataFetcher
app = FastAPI(swagger_ui_parameters={"syntaxHighlight.theme": "obsidian"})
fetcher = StockDataFetcher()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def read_root(request: Request):
return templates.TemplateResponse("hello.html", {"request": request})
@app.get('/ltp')
async def get_data(ticker: str):
try:
response = fetcher.fetch_latest_price(ticker)
return {'ltp' :response}
except:
return {"Timeout" : "Error"}
@app.get('/historical')
async def get_stocks_data(ticker: str, intervals: int, days: int):
try:
response = fetcher.fetch_stock_data(ticker, 15, 10).to_dict(orient="records")
return {"data" : response}
except:
return {"Timeout" : "Error"}
@app.get('/chain')
async def get_stocks_data(ticker: str):
try:
response, exp = fetcher.fetch_option_chain(ticker).to_dict(orient="records")
return {"data" : response}
except:
return {"Timeout" : "Error"}
@app.get('/search')
async def get_stocks_data(ticker: str):
try:
response = fetcher.search_entity(ticker)
return {"data" : response}
except:
return {"Timeout" : "Error"}
# @app.get('/news')
# async def get_stocks_data(ticker: str, page: int, size: int):
# try:
# response = fetcher.fetch_stock_news(ticker, page=page, size=size).to_dict(orient="records")
# return {"data" : response}
# except:
# return {"Timeout" : "Error"}
# @app.get('/all')
# async def get_stocks_data():
# try:
# response = fetcher.fetch_all_stock().to_dict(orient="records")
# return {"data" : response}
# except:
# return {"Timeout" : "Error"}
@app.get('/signal')
async def get_stocks_data(index: str):
try:
response = fetcher.realtime_signal(index).tail(1).to_dict(orient="records")[0]
return {"data" : response}
except:
return {"Timeout" : "Error"} |