Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TradingPilot Core

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).

🚀 Features

  • 🔐 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

🏗️ Architecture

┌─────────────────┐    ┌──────────────┐    ┌─────────────────┐
│   Frontend      │    │   TradingPilot│    │   PostgreSQL   │
│   (React/Vue)   │───▶│   Core       │───▶│   Database     │
└─────────────────┘    └──────────────┘    └─────────────────┘
                              │
                              ▼
┌─────────────────┐    ┌──────────────┐    ┌─────────────────┐
│   FinDatahub    │◀───│   NewsHub    │    │   Real-time     │
│   (MT5 Data)    │    │   (News)     │    │   Processing    │
└─────────────────┘    └──────────────┘    └─────────────────┘

🔧 Quick Start

Prerequisites

  • Python 3.10+
  • PostgreSQL 13+
  • Docker and Docker Compose (optional)

1. Local Development

# 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

2. Docker Deployment

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

📊 API Endpoints

Authentication

POST /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 profile

Financial Data

GET  /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 health

News

GET  /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 health

Health

GET  /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 liveness

⚙️ Configuration

The application is configured via environment variables:

Core Settings

# 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 OAuth (Optional)

GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/google/callback

🔐 Authentication

JWT Token Flow

  1. Login: User provides credentials → Receive access + refresh tokens
  2. API Calls: Include Authorization: Bearer <access_token> header
  3. Token Refresh: Use refresh token to get new access token
  4. Logout: Revoke refresh token

Example Usage

# 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>"

🗄️ Database

Migrations

# Create new migration
alembic revision --autogenerate -m "Description"

# Apply migrations
alembic upgrade head

# Rollback migration
alembic downgrade -1

Models

  • User: User accounts and profiles
  • PasswordResetToken: Password reset tokens
  • RefreshToken: JWT refresh tokens

🐳 Docker Commands

# 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

📝 Development

Code Quality

# Format code
black .

# Sort imports
isort .

# Lint code
flake8 .

# Type checking
mypy .

Testing

# Run tests
pytest

# Run with coverage
pytest --cov=app

🔗 Integration

Microservices

The core service integrates with:

  • TradingPilotFinDatahub: Financial data and MT5 integration
  • TradingpilotNewsHub: Financial news aggregation

Environment Setup

  1. Start FinDatahub on port 8001
  2. Start NewsHub on port 8002
  3. Start Core service on port 8000

📚 API Documentation

🚀 Deployment

Production Checklist

  • Change SECRET_KEY to secure value
  • Configure proper DATABASE_URL
  • Set DEBUG=false
  • Configure CORS_ORIGINS for production domains
  • Set up proper logging
  • Configure SSL/TLS
  • Set up monitoring and alerting

Environment Variables

# Production settings
DEBUG=false
LOG_LEVEL=WARNING
SECRET_KEY=<secure-random-key>
DATABASE_URL=<production-database-url>
CORS_ORIGINS=["https://yourdomain.com"]

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Trading pilot backend core

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages