A lightweight Python microservice that provides stock market data via REST API, powered by yfinance.
- π ISIN Search: Search for financial instruments by ISIN code
- π‘οΈ Robust Lookup: Automatic fallback to multiple exchanges and alternative sources (justETF) for accurate results
- β‘ Redis Caching: High-performance metadata caching to reduce external API calls and latency
- π Circuit Breaker: Resilient web scraping with automatic lockout on 403 errors to protect IP reputation
- π° Real-time Quotes: Get current stock prices for any symbol
- π¦ Batch Operations: Search multiple ISINs or get multiple quotes in parallel
- π Global Coverage: Supports US, UK, EU, Asian markets
- π Fast: Built with FastAPI for high performance
- π³ Docker Ready: Production-ready containerization with Redis support
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
GET |
/api/v1/search/{isin} |
Search instrument by ISIN |
POST |
/api/v1/search/batch |
Search multiple instruments by ISIN |
GET |
/api/v1/quote/{symbol} |
Get current quote for symbol |
POST |
/api/v1/quote/batch |
Get quotes for multiple symbols |
GET |
/docs |
OpenAPI documentation |
Search by ISIN:
curl http://localhost:8000/api/v1/search/US0378331005Response:
{
"isin": "US0378331005",
"symbol": "AAPL",
"name": "Apple Inc.",
"type": "stock",
"currency": "USD",
"exchange": "NASDAQ"
}Get Quote:
curl http://localhost:8000/api/v1/quote/AAPLResponse:
{
"symbol": "AAPL",
"price": "195.5000",
"currency": "USD",
"time": "2024-12-24T15:00:00+00:00"
}Batch Search by ISIN:
curl -X POST http://localhost:8000/api/v1/search/batch \
-H "Content-Type: application/json" \
-d '{"isins": ["US0378331005", "DE0007164600", "INVALID123"]}'Response:
{
"results": [
{
"isin": "US0378331005",
"symbol": "AAPL",
"name": "Apple Inc.",
"type": "stock",
"currency": "USD",
"exchange": "NASDAQ"
},
{
"isin": "DE0007164600",
"symbol": "SAP",
"name": "SAP SE",
"type": "stock",
"currency": "EUR",
"exchange": "XETRA"
}
],
"errors": [
{
"isin": "INVALID123",
"error": "No instrument found for ISIN"
}
]
}Batch Get Quotes:
curl -X POST http://localhost:8000/api/v1/quote/batch \
-H "Content-Type: application/json" \
-d '{"symbols": ["AAPL", "SAP", "INVALID"]}'Response:
{
"results": [
{
"symbol": "AAPL",
"price": "193.4200",
"currency": "USD",
"time": "2025-12-26T10:30:00Z"
},
{
"symbol": "SAP",
"price": "142.5000",
"currency": "EUR",
"time": "2025-12-26T10:30:00Z"
}
],
"errors": [
{
"symbol": "INVALID",
"error": "No quote data available"
}
]
}docker compose up --buildThe service will be available at http://localhost:8000
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Run the service:
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000Environment variables (see .env.example):
| Variable | Description | Default |
|---|---|---|
PORT |
Service port | 8000 |
HOST |
Service host | 0.0.0.0 |
LOG_LEVEL |
Logging level | INFO |
DEBUG |
Enable debug mode | false |
REDIS_HOST |
Redis host for caching | localhost |
REDIS_PORT |
Redis port | 6379 |
REDIS_DB |
Redis database number | 0 |
Run standard tests:
pytest tests/ -vRun integration tests (requires internet):
pytest tests/ -v -m integrationThese tests build a real Docker container of the application and perform HTTP requests against it, simulating a real production environment:
pytest tests/test_container_integration.py -v -m containerNote: Requires Docker to be running.
To verify your code before creating a Pull Request, you can run the same checks performed by the GitHub Actions CI (linting, security, types, tests):
Windows (PowerShell):
.\verify.ps1Linux/macOS (Bash):
chmod +x verify.sh
./verify.shExample K8s deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: market-data-service
spec:
replicas: 2
selector:
matchLabels:
app: market-data-service
template:
metadata:
labels:
app: market-data-service
spec:
containers:
- name: market-data-service
image: ghcr.io/your-username/market-data-service:latest
ports:
- containerPort: 8000
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 10
periodSeconds: 30
resources:
limits:
memory: "256Mi"
cpu: "500m"
requests:
memory: "128Mi"
cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
name: market-data-service
spec:
selector:
app: market-data-service
ports:
- port: 8000
targetPort: 8000
type: ClusterIPTo use this service with your Go StockTracker application:
- Deploy this service to your K3s cluster
- Configure the StockTracker to use this as the market data provider
- The Go client will call:
GET /api/v1/search/{isin}forSearchByISINGET /api/v1/quote/{symbol}forGetQuote
MIT