Core backend service for AI-driven trading pilot product. This service provides user authentication, authorization, and acts as a gateway to other microservices (FinDatahub and NewsHub).
- 🔐 User Authentication: Registration, login, password reset, Google OAuth
- 🔑 JWT Token Management: Access and refresh tokens with secure validation
- 🌐 Microservice Gateway: Proxy to FinDatahub and NewsHub services
- 🗄️ PostgreSQL Database: SQLAlchemy + Alembic for data persistence
- 📊 Financial Data: Real-time prices, historical data, KLine charts
- 📰 News Integration: Financial news with filtering and search
- 🏥 Health Monitoring: Comprehensive health checks
- 🐳 Docker Support: Full containerization with docker-compose
- 📝 API Documentation: Auto-generated with FastAPI
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Frontend │ │ TradingPilot│ │ PostgreSQL │
│ (React/Vue) │───▶│ Core │───▶│ Database │
└─────────────────┘ └──────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ FinDatahub │◀───│ NewsHub │ │ Real-time │
│ (MT5 Data) │ │ (News) │ │ Processing │
└─────────────────┘ └──────────────┘ └─────────────────┘
- Python 3.10+
- PostgreSQL 13+
- Docker and Docker Compose (optional)
# Clone the repository
git clone <repository-url>
cd TradingPilotCore
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration
# Run database migrations
alembic upgrade head
# Start the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000# Start all services
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop services
docker-compose downPOST /api/v1/auth/register # Register new user
POST /api/v1/auth/login # User login
POST /api/v1/auth/refresh # Refresh access token
POST /api/v1/auth/logout # Logout user
POST /api/v1/auth/password-reset-request # Request password reset
POST /api/v1/auth/password-reset # Reset password
POST /api/v1/auth/google # Google OAuth login
GET /api/v1/auth/me # Get current user profile
PUT /api/v1/auth/me # Update user profileGET /api/v1/financial/symbols # Get available symbols
GET /api/v1/financial/symbols/{symbol}/info # Get symbol information
GET /api/v1/financial/prices/{symbol} # Get real-time price
POST /api/v1/financial/prices/multiple # Get multiple prices
POST /api/v1/financial/historical # Get historical data
POST /api/v1/financial/klines # Get KLine data
GET /api/v1/financial/account # Get account info
GET /api/v1/financial/positions # Get open positions
GET /api/v1/financial/orders # Get pending orders
GET /api/v1/financial/health # Check service healthGET /api/v1/news/ # Get news articles
GET /api/v1/news/{article_id} # Get specific article
GET /api/v1/news/sources/available # Get available sources
POST /api/v1/news/fetch # Manually fetch news
GET /api/v1/news/stats/summary # Get news statistics
GET /api/v1/news/health # Check service healthGET /health # Basic health check
GET /api/v1/health/detailed # Detailed health check
GET /api/v1/health/ready # Kubernetes readiness
GET /api/v1/health/live # Kubernetes livenessThe application is configured via environment variables:
# Application
DEBUG=false
LOG_LEVEL=INFO
# Database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/tradingpilot_core
# JWT
SECRET_KEY=your-secret-key-change-in-production
JWT_ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
# Microservices
FIN_DATAHUB_URL=http://localhost:8001
NEWS_HUB_URL=http://localhost:8002
# CORS
CORS_ORIGINS=["http://localhost:3000", "http://localhost:8080"]GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/google/callback- Login: User provides credentials → Receive access + refresh tokens
- API Calls: Include
Authorization: Bearer <access_token>header - Token Refresh: Use refresh token to get new access token
- Logout: Revoke refresh token
# Register user
curl -X POST "http://localhost:8000/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","username":"testuser","password":"password123","full_name":"Test User"}'
# Login
curl -X POST "http://localhost:8000/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"password123"}'
# Use API with token
curl -X GET "http://localhost:8000/api/v1/financial/symbols" \
-H "Authorization: Bearer <access_token>"# Create new migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1- User: User accounts and profiles
- PasswordResetToken: Password reset tokens
- RefreshToken: JWT refresh tokens
# Build and start
docker-compose up --build -d
# View logs
docker-compose logs -f app
# Stop services
docker-compose down
# Clean up (removes volumes)
docker-compose down -v
# Access database
docker-compose exec postgres psql -U tradingpilot -d tradingpilot_core# Format code
black .
# Sort imports
isort .
# Lint code
flake8 .
# Type checking
mypy .# Run tests
pytest
# Run with coverage
pytest --cov=appThe core service integrates with:
- TradingPilotFinDatahub: Financial data and MT5 integration
- TradingpilotNewsHub: Financial news aggregation
- Start FinDatahub on port 8001
- Start NewsHub on port 8002
- Start Core service on port 8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
- Change
SECRET_KEYto secure value - Configure proper
DATABASE_URL - Set
DEBUG=false - Configure
CORS_ORIGINSfor production domains - Set up proper logging
- Configure SSL/TLS
- Set up monitoring and alerting
# Production settings
DEBUG=false
LOG_LEVEL=WARNING
SECRET_KEY=<secure-random-key>
DATABASE_URL=<production-database-url>
CORS_ORIGINS=["https://yourdomain.com"]- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.