FastAPI backend for the Market Map application.
- Python 3.9+
- MongoDB database (local or cloud)
- Environment variables configured
cd backend
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On WindowsIf you haven't already installed dependencies:
pip install -r requirements.txtCreate a .env file in the backend directory with the following variables:
# MongoDB Configuration
MONGODB_URI=your_mongodb_connection_string
DB_NAME=marketmap
COLLECTION_NAME=indices
NEWS_COLLECTION_NAME=financial_news
# OpenAI API (for embeddings - optional but recommended)
OPENAI_API_KEY=your_openai_api_key
# Google GenAI (for news search)
# Make sure you have GOOGLE_API_KEY set in your environment or .envuvicorn app.main:app --reload --host 0.0.0.0 --port 8000python -m app.mainpython -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Once running, the API will be available at http://localhost:8000
- API Docs: http://localhost:8000/docs (Swagger UI)
- Alternative Docs: http://localhost:8000/redoc (ReDoc)
- Root: http://localhost:8000/
GET /api/indices/status- Get all indices with market dataGET /api/indices/{symbol}- Get specific index detailsGET /api/indices/{symbol}/news- Get news for a specific indexGET /api/indices/with-news- Get all indices that have newsPOST /api/news/fetch- Trigger news fetchingGET /api/news/latest- Get latest news articles
The --reload flag enables automatic reloading when code changes are detected.
Test the API endpoints:
# Test root endpoint
curl http://localhost:8000/
# Test indices status
curl http://localhost:8000/api/indices/status
# Test news fetching
curl -X POST http://localhost:8000/api/news/fetch?max_results=10If port 8000 is already in use, change it:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8001- Check your
MONGODB_URIis correct - Ensure MongoDB is running (if local)
- Check network connectivity (if cloud)
- Verify credentials are correct
If you get import errors:
pip install -r requirements.txtMake sure:
.envfile exists in thebackenddirectorypython-dotenvis installed- You're running from the correct directory
For production, use gunicorn with uvicorn workers:
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000