A FastAPI-based market sentiment analysis tool that provides real-time stock momentum analysis and news sentiment evaluation using AI.
- Real-time Stock Analysis: Get price momentum scores based on recent trading data
- News Sentiment Analysis: AI-powered sentiment classification (bullish, neutral, bearish)
- Caching System: Efficient TTL-based caching for improved performance
- RESTful API: Clean and well-documented API endpoints
- CORS Support: Ready for frontend integration
- Python 3.8+
- Node.js 16+
- API Keys for:
- Alpha Vantage (stock data)
- MediaStack (news data)
- Google Gemini AI (sentiment analysis)
-
Clone the repository
git clone https://github.com/rockingyash1717/TICKER.git cd TICKER -
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Environment Configuration Create a
.envfile in the root directory:ALPHA_KEY=your_alpha_vantage_api_key MEDIASTACK_KEY=your_mediastack_api_key GEMINI_API_KEY=your_gemini_api_key
-
Run the backend server
uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Navigate to frontend directory
cd frontend -
Install dependencies
npm install
-
Start development server
npm start
The frontend will be available at http://localhost:3000 and will automatically proxy API requests to the backend at http://localhost:8000.
fastapi
uvicorn
pandas
yfinance
httpx
cachetools
google-generativeai
python-dotenv{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"axios": "^1.4.0"
},
"devDependencies": {
"@vitejs/plugin-react": "^4.0.3",
"vite": "^4.4.5"
}
}Get market sentiment analysis for a stock ticker.
Parameters:
ticker(required): Stock ticker symbol (e.g., "AAPL", "GOOGL")
Response:
{
"ticker": "AAPL",
"as_of": "2024-01-15",
"momentum": {
"returns": [0.0123, -0.0045, 0.0067, 0.0089, -0.0012],
"score": 0.0222
},
"news": [
{
"title": "Apple Reports Strong Q4 Earnings",
"description": "Apple Inc. reported better-than-expected earnings...",
"url": "https://example.com/news/apple-earnings"
}
],
"pulse": "bullish",
"llm_explanation": "Strong momentum score of 0.0222 combined with positive earnings news suggests bullish sentiment."
}curl "http://localhost:8000/api/v1/market-pulse?ticker=AAPL"import requests
response = requests.get("http://localhost:8000/api/v1/market-pulse?ticker=AAPL")
data = response.json()
print(f"Sentiment: {data['pulse']}")import axios from 'axios';
const fetchMarketPulse = async (ticker) => {
try {
const response = await axios.get(`/api/v1/market-pulse?ticker=${ticker}`);
return response.data;
} catch (error) {
console.error('Error fetching market pulse:', error);
}
};- Price Momentum: Calculates 5-day return momentum using Alpha Vantage daily price data
- News Collection: Fetches recent news headlines using MediaStack API
- Sentiment Analysis: Uses Google Gemini AI to analyze combined momentum and news data
- Caching: Results are cached for 10 minutes to reduce API calls and improve performance
- Responsive Design: Mobile-friendly interface built with modern React
- Real-time Updates: Live market sentiment tracking
- Interactive Charts: Visual representation of momentum and sentiment
- Search Functionality: Easy ticker symbol lookup
- Dark/Light Mode: User preference theme switching
TICKER/
βββ main.py # FastAPI backend application
βββ getname.py # Company name extraction utility
βββ requirements.txt # Python dependencies
βββ .env # Environment variables
βββ README.md # This file
βββ frontend/
βββ src/
β βββ components/
β βββ pages/
β βββ utils/
β βββ App.jsx
βββ package.json
βββ vite.config.js
βββ index.html
- Visit Alpha Vantage
- Sign up for a free API key
- Add to
.envfile asALPHA_KEY
- Visit MediaStack
- Create account and get API key
- Add to
.envfile asMEDIASTACK_KEY
- Visit Google AI Studio
- Generate API key
- Add to
.envfile asGEMINI_API_KEY
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- API rate limits may apply based on your subscription tier
- News data availability depends on MediaStack coverage
- Sentiment analysis accuracy may vary based on news quality
For support, please open an issue on GitHub or contact the maintainers.
- Initial release with basic sentiment analysis
- FastAPI backend with caching
- Vite React frontend integration
- Support for major stock tickers
Made with β€οΈ by rockingyash1717