ticker_monitor_api / README.md
dromerosm's picture
Add initial setup for Stock Monitoring API with testing framework
a8f56ca
metadata
title: Ticker Monitor Api
emoji: πŸ“‰
colorFrom: purple
colorTo: pink
sdk: docker
pinned: false
license: mit
short_description: SP500 & NASDAQ ticker monitoring API

Stock Monitoring API πŸ“ˆ

A FastAPI-based REST API for monitoring S&P 500 and Nasdaq 100 stock tickers with real-time data updates.

Features

  • Stock Data Management: Query and update tickers for S&P 500 and Nasdaq 100 indices
  • Automatic Data Updates: Background tasks to fetch latest stock data from Yahoo Finance
  • RESTful API: Clean, documented endpoints with OpenAPI/Swagger integration
  • MySQL Integration: Persistent storage with async SQLAlchemy
  • Authentication: Secure API key-based authentication
  • Health Monitoring: Built-in health checks and version information

API Endpoints

Public Endpoints

  • GET / - Health check and system information
  • GET /tickers - List all available tickers with filtering options
  • GET /data/tickers/{ticker} - Get historical data for a specific ticker

Protected Endpoints (Require API Key)

  • POST /tickers/update - Update ticker list from Wikipedia sources
  • POST /tickers/update-async - Async ticker updates with task tracking
  • POST /data/download-all - Download latest stock data (bulk operation)
  • GET /tasks - List background tasks
  • GET /tasks/{task_id} - Get specific task status
  • DELETE /tasks/old - Clean up old completed tasks

Usage

Authentication

Protected endpoints require an API key in the Authorization header:

Authorization: Bearer your_api_key_here

Example Requests

# Get system health
curl https://your-space-name.hf.space/

# List S&P 500 tickers
curl "https://your-space-name.hf.space/tickers?is_sp500=true&limit=10"

# Get AAPL stock data (last 30 days)
curl "https://your-space-name.hf.space/data/tickers/AAPL?days=30"

# Update all stock data (requires API key)
curl -X POST "https://your-space-name.hf.space/data/download-all" \
  -H "Authorization: Bearer your_api_key"

Configuration

Set these environment variables in your Hugging Face Space:

  • MYSQL_USER - Database username
  • MYSQL_PASSWORD - Database password
  • MYSQL_HOST - Database host
  • MYSQL_PORT - Database port (default: 3306)
  • MYSQL_DB - Database name
  • API_KEY - Secure API key for protected endpoints

Technical Details

  • Framework: FastAPI with async/await support
  • Database: MySQL with SQLAlchemy async ORM
  • Data Sources: Wikipedia (ticker lists), Yahoo Finance (stock data)
  • Deployment: Docker container optimized for Hugging Face Spaces
  • Python: 3.12 with production-ready dependencies

API Documentation

Once deployed, visit /docs for interactive Swagger documentation or /redoc for alternative API docs.


Built for Hugging Face Spaces with ❀️