testing / main.py
jarvisx17's picture
Update main.py
ef8e1a4
raw
history blame
1.51 kB
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import FastAPI, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pycatchs.levels import eqt
app = FastAPI()
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.post('/process_stock_details')
# async def process_stock_details(request: Request):
# data = await request.json()
# processed_data = {
# 'symbol': data['symbol'],
# 'date': data['date'],
# 'share': data['share']
# }
# return processed_data
@app.get('/data')
async def get_data(ticker: str, date: str, qty: int):
try:
response = await eqt(ticker, date, qty)
return response
except:
return {"Timeout" : "Error"}
# @app.post('/data')
# async def post_data(request: Request):
# data = await request.json()
# ticker = data.get('ticker')
# date = data.get('date')
# share_qty = data.get('qty')
# response = data_manager.get_equity_data(ticker, date, share_qty)
# return response
# if __name__ == "__main__":
# import uvicorn
# uvicorn.run(app, host="0.0.0.0", port=8000)