This project provides a FastAPI-based backend to fetch stock-related information such as historical prices, recent news, prediction results, and XAI-based explanations. The backend is containerized using Docker and uses MySQL (RDS-ready) as its primary database.
GET /search
Autocomplete search for stock tickers and company names.
Query Parameters
keyword(optional): partial match for ticker or name
GET /search?keyword=apple-
Returns historical chart data and recent news
-
Query Parameters:
tickerhorizon(1, 7, or 30)
GET /stock-info/basic?ticker=AAPL&horizon=7-
Returns predicted price data
-
Query Parameters:
tickerhorizon(1, 7, or 30)
GET /stock-info/pred?ticker=AAPL&horizon=7-
Returns explanation (XAI tokens and scores)
-
Query Parameters:
tickerhorizon(1, 7, or 30)
GET /stock-info/exp?ticker=AAPL&horizon=7backend/
├── app/
│ ├── main.py # FastAPI app entrypoint
│ ├── crud/ # Logic layer: DB access for chart, prediction, news, explanation
│ ├── routers/
│ │ ├── stock.py # /stock-info/* endpoints
│ │ └── search.py # /search endpoint
│ ├── schemas.py # Pydantic schemas
│ └── __init__.py
├── db/
│ ├── models/ # SQLAlchemy models: Ticker, ChartData, Prediction, News, Explanation
│ ├── session.py # MySQL engine and session maker
│ └── init_db.py # DB seeding or migration logic
├── requirements.txt
├── Dockerfile
└── docker-compose.yml# External API for model inference (via ngrok or your own gateway)
NGROK_API_URL="https://<your-ngrok-or-api-url>.ngrok-free.app/"
# MySQL Database URL (RDS or local)
DATABASE_URL="mysql+pymysql://<username>:<password>@<host>:<port>/<database>"python -m venv venv
source venv/bin/activate # macOS/Linux
# or venv\Scripts\activate # Windowspip install -r requirements.txtuvicorn app.main:app --host 0.0.0.0 --port 8000Visit:
- Swagger: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
To build and run the backend with Docker Compose:
docker compose up -d --buildMake sure your .env file is created at the root level with proper MySQL and external inference settings.
# External API for model inference (via ngrok or your own gateway)
NGROK_API_URL="https://<your-ngrok-or-api-url>.ngrok-free.app/"
# MySQL Database URL (RDS or local)
DATABASE_URL="mysql+pymysql://<username>:<password>@<host>:<port>/<database>"
Jihun Kim |