A simple FastAPI wrapper around the yfinance library for retrieving stock market data. Containerized for easy deployment with Docker.
- Docker (to build and run the container)
From the root of this project directory, run:
docker build -t yf-api .Start the container and map the API port (8000) to your host:
docker run --rm -p 8000:8000 yf-apiThe API will be available at http://localhost:8000.
- Endpoint:
GET /info/{ticker} - Description: Retrieves stock information for a given ticker.
- Response: JSON object with stock info.
- Error Responses:
- 404 if ticker not found.
- 500 for server errors.
- Endpoint:
GET /history/{ticker} - Query Parameters:
period(optional, default: "1mo"): Data period (e.g., 1d, 5d, 1mo, 3mo, etc.)interval(optional, default: "1d"): Data interval (e.g., 1m, 5m, 1d, 1wk, etc.)start(optional): Start date (YYYY-MM-DD)end(optional): End date (YYYY-MM-DD)format(optional, default: "json"): Output format, either "json" or "csv"
- Response: JSON array or CSV file of historical data.
- Error Responses:
- 400 for invalid format.
- 404 if no data found.
- 500 for server errors.
- Endpoint:
GET /calendar/{ticker} - Description: Retrieves upcoming event calendar (earnings, dividends, etc.) for a ticker.
- Response: JSON object with calendar data.
- Error Responses:
- 404 if no calendar data found.
- 500 for server errors.
- Endpoint:
GET /balance-sheet/{ticker} - Description: Retrieves the balance sheet for a ticker.
- Response: JSON object with balance sheet data.
- Error Responses:
- 404 if no data found.
- 500 for server errors.
- Endpoint:
GET /quarterly-income-statement/{ticker} - Description: Retrieves quarterly income statement for a ticker.
- Response: JSON object with income statement data.
- Error Responses:
- 404 if no data found.
- 500 for server errors.
Convert a local file:
curl -X GET http://localhost:8000/info/AAPLGet stock history in JSON:
curl -X GET "http://localhost:8000/history/AAPL?period=1mo&interval=1d&format=json"Get stock history in CSV:
curl -X GET "http://localhost:8000/history/AAPL?period=1mo&interval=1d&format=csv" -o AAPL_history.csvGet stock calendar:
curl -X GET http://localhost:8000/calendar/AAPLGet balance sheet:
curl -X GET http://localhost:8000/balance-sheet/AAPLGet quarterly income statement:
curl -X GET http://localhost:8000/quarterly-income-statement/AAPL