Skip to content

About

AI-powered stock trading platform with natural language commands | FastAPI + React + Google Gemini

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

πŸš€ OneCommand Trader

AI-Powered Stock Trading Platform with Natural Language Commands

Trade stocks using simple commands like "Buy 10 Apple stocks" or "What's Coal India worth?"

License: MIT


✨ Features

  • Natural Language Trading: Use plain English to buy/sell stocks
  • AI-Powered NLP: Google Gemini API with pattern-based fallback
  • Multi-Market Support: US stocks (AAPL, TSLA) & Indian stocks (COALINDIA.NS, RELIANCE.NS)
  • Real-Time Data: NSE India for Indian stocks, Alpha Vantage for US stocks
  • Portfolio Management: Track holdings, cash balance, and trade history
  • AI Predictions: ML-based price predictions with confidence scores
  • Secure Authentication: JWT-based auth with bcrypt password hashing

Quick Start

Prerequisites

  • Docker Desktop (Windows/Mac) or Docker Engine (Linux)
  • 8GB RAM available
  • Ports 3000, 8000, 5432, 6379 free

1. Clone Repository

git clone <your-repo-url>
cd onecommand

2. Configure Environment

Generate SECRET_KEY (Windows PowerShell):

$bytes = New-Object Byte[] 32
[Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
$key = [System.BitConverter]::ToString($bytes).Replace("-","").ToLower()
Write-Host "Your SECRET_KEY: $key"

Or using bash/WSL:

openssl rand -hex 32

Edit .env - Replace your_generated_secret_key_here with the key above:

SECRET_KEY=<paste_generated_key_here>

# Optional: Add real API keys (works with demo data without these)
ALPHA_VANTAGE_KEY=your_key_here
FINNHUB_KEY=your_key_here
GEMINI_API_KEY=your_key_here

3. Start Application

docker-compose up -d

Wait for services to start (~30-60 seconds):

docker-compose ps

Expected output - all services should show "Up" or "Up (healthy)":

NAME                     STATUS
onecommand_backend       Up (healthy)
onecommand_frontend      Up
onecommand_postgres      Up (healthy)
onecommand_redis         Up (healthy)
onecommand_mcp           Up

4. Access Application

5. Login

Email: demo@onecommand.com
Password: demo123

6. Try Commands

"Buy 10 Apple stocks"
"What's Tesla worth?"
"Show my portfolio"
"Buy 5 shares of Coal India"
"Sell all my Google shares"

πŸ“– Usage Guide

Supported Commands

Trading:

  • "Buy 10 shares of Apple"
  • "Purchase 5 Coal India stocks"
  • "Sell all my Tesla"
  • "Sell 3 shares of Google"

Price Queries:

  • "What's Apple worth?"
  • "Show me Coal India price"
  • "How much is Tesla?"

Portfolio:

  • "Show my portfolio"
  • "What do I own?"
  • "My holdings"

Stock Symbols

US Stocks: Use ticker symbols (AAPL, TSLA, MSFT, GOOGL, AMZN) Indian Stocks: Use .NS suffix (RELIANCE.NS, COALINDIA.NS, TCS.NS, INFY.NS)


πŸ—οΈ Architecture

Frontend (React + Vite)
    ↓ REST API
Backend (FastAPI + Python)
    ↓
β”œβ”€β†’ PostgreSQL (portfolio/trades)
β”œβ”€β†’ Redis (caching)
β”œβ”€β†’ Gemini AI (NLP)
β”œβ”€β†’ NSE India (Indian stock data)
β”œβ”€β†’ Alpha Vantage (US stock data)
└─→ ML Service (predictions)

Tech Stack:

  • Frontend: React, Vite, TailwindCSS, Lucide Icons
  • Backend: FastAPI, SQLAlchemy, Pydantic
  • Database: PostgreSQL, Redis
  • AI/ML: Google Gemini API, scikit-learn, transformers
  • Stock Data: nsepy (NSE India), Alpha Vantage, YFinance

πŸ”§ Development

View Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f backend
docker-compose logs -f frontend

Restart Services

# All services
docker-compose restart

# Specific service
docker-compose restart backend

Clean Restart

docker-compose down -v
docker-compose up -d --build

Database Access

# PostgreSQL shell
docker exec -it onecommand_postgres psql -U postgres -d postgres_db

# Redis CLI
docker exec -it onecommand_redis redis-cli

πŸ” Security

Required Security Steps

  1. Generate Secure SECRET_KEY (see Quick Start section)
  2. Change Default Credentials in production
  3. Use HTTPS with SSL certificates
  4. Set Proper CORS Origins in .env
  5. Revoke Exposed API Keys (see SECURITY_NOTICE.md)

⚠️ NEVER commit .env files or API keys to version control!


πŸ“Š API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login and get token
  • GET /api/auth/me - Get current user info

Trading

  • POST /api/command - Process natural language command
  • GET /api/portfolio - Get user portfolio
  • GET /api/trades - Get trade history

Stock Data

  • GET /api/stocks/{symbol}/prediction - Get AI prediction
  • GET /api/stocks/{symbol}/sentiment - Get sentiment analysis

Full API documentation: http://localhost:8000/docs


πŸš€ Production Deployment

For production deployment, see DEPLOYMENT.md which covers:

  • Security hardening
  • Environment configuration
  • SSL/HTTPS setup
  • Database backups
  • Monitoring and logging
  • Cloud deployment options (Railway, Render, Fly.io)

πŸ› Troubleshooting

Services Won't Start

# Check what's running
docker-compose ps

# View logs
docker-compose logs

# Clean restart
docker-compose down -v
docker-compose up -d --build

Port Already in Use

# Windows: Find process using port
netstat -ano | findstr :3000
taskkill /PID <process_id> /F

# Linux/Mac: Find and kill process
lsof -ti:3000 | xargs kill -9

Database Connection Error

# Verify database is running
docker-compose ps postgres

# Check database logs
docker-compose logs postgres

# Wait for database to be ready (30 seconds)

API Keys Not Working

# Restart backend after updating .env
docker-compose restart backend

# Verify keys are loaded
docker exec onecommand_backend env | grep KEY

🀝 Contributing

Contributions welcome! Please:

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

πŸ“„ License

MIT License - see LICENSE file for details


πŸ”— Links


Built with ❀️ using FastAPI, React, and Google Gemini AI

🌟 Star this repo if you find it useful!

About

AI-powered stock trading platform with natural language commands | FastAPI + React + Google Gemini

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages