A FastAPI-based financial data service that provides comprehensive stock market information through RESTful APIs. The service uses Yahoo Finance (yfinance) as the primary data source to retrieve real-time stock information, prices, news, financial statements, and other related data.
This service serves as the data provider for the financial-agents project, supplying all the financial data needed for AI-powered financial analysis and trading agents.
This service provides a unified API interface for accessing various types of financial data for stock tickers. It includes built-in caching mechanisms to improve performance and reduce external API calls, along with proper error handling and response formatting.
- Ticker Information: Company details, sector, industry, market cap, etc.
- Stock Prices: Historical price data with various time intervals
- News: Recent news articles related to specific tickers
- Financial Statements: Income statements, balance sheets, and cash flow statements
- Insider Data: Insider transactions, holdings, and purchases
- Financial Metrics: Key financial ratios and calculated metrics
- Ticker Lookup: Search functionality for finding ticker symbols
All API endpoints require authorization via the 'Authorization: Bearer ' header. The default token is 'secret-token' but can be overridden with the API_TOKEN environment variable.
GET /api/v1/ticker/info- Get ticker informationGET /api/v1/ticker/prices- Get historical ticker pricesGET /api/v1/ticker/news- Get recent news for a tickerGET /api/v1/ticker/income_stmt- Get income statement dataGET /api/v1/ticker/balance_sheet- Get balance sheet dataGET /api/v1/ticker/cash_flow- Get cash flow dataGET /api/v1/ticker/insider_transactions- Get insider transactionsGET /api/v1/ticker/insider_roster_holders- Get insider roster holdersGET /api/v1/ticker/insider_purchases- Get insider purchasesGET /api/v1/ticker/financial_metrics- Get financial metricsGET /api/v1/ticker/financial_items- Get specific financial itemsGET /api/v1/ticker/lookup- Lookup ticker symbols
GET /api/v1/test- Simple test endpoint
All endpoints require a Bearer token in the Authorization header:
Authorization: Bearer secret-token
The token can be customized using the API_TOKEN environment variable.
financial-data/
├── main.py # FastAPI application and routing
├── src/
│ ├── api/ # Business logic for data fetching
│ ├── common/ # Utility functions and helpers
│ └── models/ # Pydantic data models
├── CLAUDE.md # Claude Code instructions
└── README.md # This file
- API requests are received by FastAPI endpoints in
main.py - Endpoints call functions in
src/api/ticker.pyto fetch data - Data is retrieved from Yahoo Finance using the
yfinancelibrary - Raw data is processed, transformed, and converted to Pydantic models
- Responses are formatted using the
BaseResponsewrapper with consistent structure
- Response Handling: All API responses follow a consistent format using
BaseResponsemodel with code, data, and message fields - Data Conversion: Utilities to convert between camelCase and snake_case naming conventions
- Caching: Built-in caching mechanism using decorators to improve performance and reduce API calls
- Error Handling: Centralized exception handling for consistent error responses
- Data Models: Comprehensive Pydantic models for all financial data types
- Ticker info: 24-hour cache
- Prices: 1-hour cache
- News: 1-hour cache
- Financial statements: 24-hour cache
- Insider data: 24-hour cache
- Financial metrics: 1-hour cache
- Ticker lookup: 1-hour cache
- Python 3.12+
uvpackage manager
-
Create and activate virtual environment:
source .venv/bin/activate -
Install dependencies using
uv:uv sync
Development mode:
source .venv/bin/activate
fastapi dev main.pyProduction mode:
uvicorn main:app --host 0.0.0.0 --port 8000API_TOKEN: Custom authorization token (default: "secret-token")
{
"mcpServers": {
"finance-data": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://127.0.0.1:8000/mcp", "--header", "Authorization:Bearer secret-token"]
}
}
}