This is a Flask-based Financial Analysis API that allows users to:
- Extract stock ticker symbols from natural language queries.
- Fetch financial data for a stock using Yahoo Finance.
- Analyze stock data using AI-driven financial analysis.
/flask_financial_api
│── /app
│ │── /api
│ │ │── __init__.py
│ │ │── routes.py
│ │── /models
│ │ │── __init__.py
│ │ │── stock.py
│ │── /services
│ │ │── __init__.py
│ │ │── symbol_extractor.py
│ │ │── data_fetcher.py
│ │ │── stock_analysis.py
│ │── /utils
│ │ │── __init__.py
│ │ │── logger.py
│ │── /config
│ │ │── __init__.py
│ │ │── settings.py
│ │── /middleware
│ │ │── __init__.py
│ │ │── error_handler.py
│ │── __init__.py
│ │── extensions.py
│── /migrations
│── /tests
│ │── __init__.py
│ │── test_routes.py
│── /instance
│── .env
│── requirements.txt
│── gunicorn_config.py
│── wsgi.py
│── README.md
- Python 3.12+
- Anaconda (if using Conda environments)
git clone https://github.com/yourusername/flask_financial_api.git
cd flask_financial_api
conda create -n financial_api_env python=3.12
conda activate financial_api_env
Or using venv
:
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
pip install -r requirements.txt
flask db init
flask db migrate -m "Initial migration"
flask db upgrade
flask run
By default, the API runs at: http://127.0.0.1:5000
For public access:
flask run --host=0.0.0.0 --port=5000
POST /api/extract-symbol
{
"query": "symbol for microsoft"
}
{
"symbol":"The stock ticker symbol for Microsoft is:\n\nMSFT"
}
POST /api/fetch-financials
{
"ticker": "AAPL"
}
{
"file":"MSFT.json",
"message":"Financial data successfully saved at MSFT.json"
}
POST /api/analyze-stock
{
"file_path": "AAPL.json",
"query": "Analyze this stock"
}
{
"analysis": "The stock shows strong profitability....... I would recommend that the trader hold the stock..."
}
pytest tests/
Expected output:
================================================= 3 passed in 13.74s ==================================================
pip install waitress
waitress-serve --listen=0.0.0.0:5000 wsgi:app
|
This project is open-source and available under the MIT License.
- Fork the repository
- Create a new branch (
git checkout -b feature-branch
) - Commit your changes (
git commit -m 'Add new feature'
) - Push to the branch (
git push origin feature-branch
) - Create a pull request 🚀