Skip to content

FastAPI service that analyzes market data and provides trade opportunity insights for specific sectors in India.

Notifications You must be signed in to change notification settings

Paras1793/Fast-API_service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ Trade Opportunities API πŸ“Œ Overview

This project implements a FastAPI service that analyzes market data for a given sector in India and generates a Markdown report of trade opportunities using Google Gemini AI.

It was built as part of the Trade Opportunities API Developer Task.

βš™οΈ Features

βœ… FastAPI backend with async support

βœ… Single endpoint: GET /analyze/{sector}

βœ… Collects recent market data from DuckDuckGo-Search

βœ… Uses Google Gemini API to analyze and generate structured Markdown reports

βœ… Built-in rate limiting (5 requests per minute per IP)

βœ… Clean error handling (502 for data issues, 503 for AI issues)

βœ… Returns Markdown report wrapped in JSON

πŸ“‚ Project Structure trade_api/ │── main.py # FastAPI app (endpoint + rate limiting + data fetch) │── requirements.txt # Dependencies │── README.md # This file

πŸš€ Setup & Run

  1. Clone & Install git clone cd trade_api pip install -r requirements.txt

  2. Set Gemini API Key

You need a Google Gemini API key (from Google AI Studio or Google Cloud). Set it as an environment variable:

export GEMINI_API_KEY="your_api_key_here"

(Windows PowerShell)

$env:GEMINI_API_KEY="your_api_key_here"

  1. Run FastAPI uvicorn main:app --reload --host 127.0.0.1 --port 8000

πŸ“‘ API Usage Endpoint GET /analyze/{sector}

Example Request GET http://127.0.0.1:8000/analyze/pharmaceuticals

Example Response { "report": "# Market Analysis β€” Pharmaceuticals\n\n- Key Trends...\n- Opportunities...\n- Risks...\n- Future Outlook...\n\nGenerated by AI" }

πŸ”’ Security

Open access (no authentication required).

Rate limiting: 5 requests/minute per IP to prevent abuse.

⚠️ Error Handling

502 β†’ Market data fetch failed

503 β†’ AI service unavailable

βœ… Success Criteria

API accepts sector names (e.g., pharmaceuticals, technology, agriculture)

Returns structured Markdown report containing trade opportunities

Implements rate limiting and proper error handling

Clean, well-organized code with separation of concerns

πŸ“ Notes

The data collection currently uses DuckDuckGo API for simplicity. In a production system, this can be replaced with a more robust data source (e.g., NewsAPI, scraping, financial APIs).

Gemini model used: gemini-2.5-flash (fast & lightweight).

✨ You’re all set! Run the server, test in Postman, and save the returned Markdown as .md files for reports.

About

FastAPI service that analyzes market data and provides trade opportunity insights for specific sectors in India.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages