This is a simplified Flask data API that provides financial data using yfinance. The architecture has been streamlined to remove unnecessary complexity while maintaining all core functionality.
Contains static methods for data fetching:
get_stock(ticker)- Returns stock data as Dictget_crypto(symbol)- Returns crypto data as Dictget_mutual_fund(symbol)- Returns mutual fund data as Dictget_stock_history(ticker, period)- Returns historical datasearch_assets(query)- Search functionality_format_news(items)- Internal helper for news formatting
Simple Flask routes defined in the same file:
GET /stocks/<symbol>→ callsStockService.get_stock()GET /crypto/<symbol>→ callsStockService.get_crypto()GET /mutual-funds/<symbol>→ callsStockService.get_mutual_fund()GET /history/<symbol>?period=1MO→ callsStockService.get_stock_history()GET /search?q=query→ callsStockService.search_assets()
In app.py:
from services.stock_service import api_bp
app.register_blueprint(api_bp, url_prefix='/api/v1')Base URL: http://localhost:5000/api
| Method | Endpoint | Description |
|---|---|---|
| GET | /stocks/<symbol> |
Get stock details |
| GET | /crypto/<symbol> |
Get crypto details |
| GET | /mutual-funds/<symbol> |
Get mutual fund details |
| GET | /history/<symbol>?period=1MO |
Get historical data |
| GET | /search?q=query |
Search assets |
# Get Apple stock
curl http://localhost:5000/api/stocks/AAPL
# Get Bitcoin data
curl http://localhost:5000/api/crypto/BTC
# Get history
curl http://localhost:5000/api/history/AAPL?period=6MO
# Search
curl http://localhost:5000/api/search?q=microsoftAll responses return JSON:
Success (200):
{
"tickerSymbol": "AAPL",
"name": "Apple Inc.",
"currentPrice": 175.50,
...
}Error (404/500):
{
"error": "Stock not found"
}python app.py