COTexplorer/app/api/main.py
Greg 37f8eac932 Initial commit: CFTC COT Explorer
FastAPI application that ingests CFTC Commitments of Traders data into SQLite
and exposes it via a REST API with analytics endpoints (screener, percentile rank,
concentration). Includes CLI for historical and weekly data ingestion, Docker setup,
and a frontend.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 11:23:00 +01:00

39 lines
1.1 KiB
Python

from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from pathlib import Path
from app.api.routes import commodities, positions, analytics, reports
app = FastAPI(
title="CFTC COT Explorer",
description="Explore CFTC Commitments of Traders positioning data",
version="1.0.0",
)
app.include_router(commodities.router)
app.include_router(positions.router)
app.include_router(analytics.router)
app.include_router(reports.router)
FRONTEND_DIR = Path(__file__).parent.parent.parent / "frontend"
if FRONTEND_DIR.exists():
app.mount("/static", StaticFiles(directory=str(FRONTEND_DIR)), name="static")
@app.get("/", include_in_schema=False)
async def root():
index = FRONTEND_DIR / "index.html"
if index.exists():
return FileResponse(str(index))
return {"message": "CFTC COT Explorer API", "docs": "/docs"}
@app.get("/health", include_in_schema=False)
async def health():
from app.db import get_db
with get_db() as conn:
count = conn.execute("SELECT COUNT(*) FROM reports").fetchone()[0]
return {"status": "ok", "reports": count}