Skip to content

Commit ae65a0d

Browse files
committed
chore: api
1 parent 2e757e8 commit ae65a0d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""API package for QuantResearchStarter backend."""
2+
3+
__all__ = [
4+
"main",
5+
"db",
6+
"models",
7+
"schemas",
8+
"auth",
9+
"routers",
10+
"tasks",
11+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""FastAPI application entrypoint for backend API."""
2+
from fastapi import FastAPI, APIRouter
3+
from fastapi.middleware.cors import CORSMiddleware
4+
import os
5+
import asyncio
6+
7+
from .routers import auth as auth_router, backtest as backtest_router
8+
from .utils.ws_manager import redis_listener_loop
9+
10+
app = FastAPI(title="QuantResearch API")
11+
12+
app.add_middleware(
13+
CORSMiddleware,
14+
allow_origins=[os.getenv("CORS_ORIGINS", "*")],
15+
allow_credentials=True,
16+
allow_methods=["*"],
17+
allow_headers=["*"],
18+
)
19+
20+
21+
@app.on_event("startup")
22+
async def startup_event():
23+
# Start background redis subscription for websocket broadcasting
24+
loop = asyncio.get_event_loop()
25+
loop.create_task(redis_listener_loop())
26+
27+
28+
@app.on_event("shutdown")
29+
async def shutdown_event():
30+
# Nothing special for now
31+
pass
32+
33+
34+
app.include_router(auth_router.router)
35+
app.include_router(backtest_router.router)
36+
app.include_router(assets_router.router)
37+
38+
# Health / readiness
39+
router = APIRouter(prefix="/api")
40+
41+
42+
@router.get("/health")
43+
async def health():
44+
return {"status": "ok"}
45+
46+
47+
app.include_router(router)

0 commit comments

Comments
 (0)