This API continuously scrapes and stores news articles from PR Newswire and Business Wire, as well as financial data from Yahoo Finance. The data is stored in a SQLite database and can be accessed via various endpoints. Prometheus metrics are integrated for monitoring API performance.
- Purpose
- Features
- Requirements
- Installation
- Usage
- API Endpoints
- Database Models
- Background Tasks
- Prometheus Metrics
- Health Check
- Contributing
- License
- Author
The purpose of this API is to provide a continuous stream of financial news and stock data by scraping reputable sources like PR Newswire, Business Wire, and Yahoo Finance. This helps investors, financial analysts, and developers who need up-to-date news and financial data for making informed decisions or integrating into their applications.
- Continuous Scraping: Fetches news from PR Newswire and Business Wire every 10 minutes.
- Financial Data: Fetches financial data from Yahoo Finance every 20 seconds.
- Database Storage: Stores scraped data in a SQLite database.
- API Endpoints: Provides endpoints to access news articles and financial data.
- Prometheus Metrics: Integrates Prometheus metrics for monitoring.
- Health Check: Provides a health check endpoint.
- Python 3.8+
- FastAPI
- SQLAlchemy
- Requests
- LXML
- Prometheus-client
- Psutil
- Uvicorn
-
Clone the repository:
git clone https://github.com/AstonWilliams/Finance-Api.git cd stock-news-api -
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # For Windows: .\.venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the API:
uvicorn app.main:app --reload
After starting the API, you can access it at http://127.0.0.1:8000.
- Get Latest News: Returns the latest news articles.
GET /news
- Get Financial Data: Returns financial data from Yahoo Finance.
GET /yahoofinance
id: Integer, primary keytitle: String, indexsource: String, indexpublished_date: DateTimecontent: Texthash: String, unique, index
id: Integer, primary keysymbol: String, indexname: String, indexchange: Stringchange_percent: Stringprice_intraday: Stringytd_return: Stringthree_mo_return: Stringone_year: Stringthree_year_return: Stringfive_year_return: Stringnet_expense_ratio: Stringgross_expense_ratio: Stringnet_assets: Stringfifty_day_avg: Stringtwo_hundred_day_avg: Stringhash: String, unique, indextimestamp: DateTime
The API uses background tasks to continuously fetch data.
- continuous_fetch: Fetches news from PR Newswire and Business Wire every 10 minutes.
- continuous_yahoo_finance_fetch: Fetches financial data from Yahoo Finance every 20 seconds.
Prometheus metrics are exposed at /metrics and /metrics_json.
request_count_total: Total number of requests.request_latency_seconds: Request latency in seconds.error_count_total: Total number of errors.
A health check endpoint is available at /health. It provides the following metrics:
status: Health status (healthyorunhealthy).request_count: Total number of requests.error_count: Total number of errors.error_rate: Error rate.average_latency_seconds: Average request latency.cpu_usage_percent: CPU usage percentage.memory_usage_percent: Memory usage percentage.
Contributions are welcome! Please fork the repository and create a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for more details.
- Name: A91060705
- Email: a91060705@gmail.com