HaseeebA/stockPriceFetcher

Haseeb Asad

0

Backend Engineer

Stock Price Getter API

Overview

The Stock Price Getter API is a Flask-based service that fetches current stock prices for specified tickers using the Yahoo Finance API (yfinance library). This API can be deployed on cloud platforms such as Google Cloud Run and can be utilized in various side projects requiring real-time stock price data.

Features

Fetches real-time stock prices.
Caches stock prices to minimize redundant API calls.
Supports a retry mechanism for failed fetch attempts.
API key authentication for secure access.

Prerequisites

Docker
A Docker Hub account
Google Cloud account (if deploying to Google Cloud Run)

Setup

Clone the Repository

git clone <repository-url> cd <repository-directory>

Build and Push Docker Image

docker build -t stock-price-getter . docker tag stock-price-getter <your-dockerhub-username>/stock_price_getter:latest docker push <your-dockerhub-username>/stock_price_getter:latest

Deploy to Google Cloud Run

Ensure you have the Google Cloud SDK installed and configured.
Deploy the container:
gcloud run deploy --image <your-dockerhub-username>/stock_price_getter:latest --platform managed

Usage

API Endpoint

POST /prices

Headers

Content-Type: application/json
X-API-Key: your-api-key

Request Body

{ "tickers": ["AAPL", "GOOGL", "MSFT"] }

Response

{ "AAPL": {"price": 150.25, "source": "cache"}, "GOOGL": {"price": 2750.80, "source": "yfinance"}, "MSFT": {"price": 300.10, "source": "yfinance"} }

Configuration

Update the api_keys.json file with your desired API keys.
Modify the caching duration in app.py if needed.

Error Handling

Invalid API key: Returns a 401 Unauthorized error.
Missing or invalid request body: Returns a 400 Bad Request error.
Failed to fetch stock price: Returns an error message in the response for the specific ticker.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.
Like this project
0

Stock Price Fetcher is a robust and scalable API service designed to fetch real-time stock prices for various tickers. - GitHub - HaseeebA/stockPriceFetcher: …

Likes

0

Views

0

Tags

Backend Engineer

Haseeb Asad

Web Developer | Debugging Expert | Flutterflow Developer

Cryptocurrency Price Fetcher API
Cryptocurrency Price Fetcher API
HaseeebA/SecureTeams
HaseeebA/SecureTeams