A powerful web application that combines real-time stock analysis, technical strategy ranking, and an AI-powered chatbot to help traders make informed decisions.
- Automated Strategy Ranking: Scans the market for Breakout, Swing, and Day trading opportunities based on daily OHLCV data.
- AI-Powered Analysis: Integrated Chatbot (LLM) to explain technical signals and answer queries like "Why is RELIANCE in the top 5?".
- Interactive Charts: Detailed daily candle charts with annotated patterns, entry, stop, and target levels.
- Real-time Updates: WebSocket integration for live ranking updates and price changes.
- Fundamental Insights: Integrates fundamental data to provide a holistic view of stocks.
The system is built with a clean separation of concerns, featuring a FastAPI backend for data processing and a React frontend for the user interface.
graph TD
subgraph "Frontend (React)"
UI[User Interface]
Chart[Interactive Charts]
Chat[Chat Window]
end
subgraph "Backend (FastAPI)"
API[REST API]
WS[WebSocket Server]
TA[TA Engine]
Strategy[Strategy Engine]
LLM[LLM Service]
end
subgraph "Data Layer"
DB[("SQLite Cache")]
ExtAPI["External APIs (Fyers/NSE)"]
Scraper[Fundamental Scraper]
end
UI -->|HTTP Requests| API
UI <-->|Real-time Updates| WS
Chat -->|Queries| API
API --> TA
API --> Strategy
API --> LLM
TA --> DB
Strategy --> DB
TA --> ExtAPI
Scraper --> DB
sequenceDiagram
participant User
participant UI as Frontend
participant API as Backend
participant LLM as AI Service
User->>UI: Select Strategy (e.g., Breakout)
UI->>API: Request Ranked Stocks
API->>API: Run Strategy Engine
API-->>UI: Return Ranked List
User->>UI: Click on Stock (e.g., TATASTEEL)
UI->>API: Get Details & Chart Data
API-->>UI: Return OHLCV & Indicators
User->>UI: Ask "Why is this a good buy?"
UI->>API: Send Chat Message
API->>LLM: Generate Explanation (Context: TA + Fundamentals)
LLM-->>API: Return Explanation
API-->>UI: Display AI Response
- Backend: FastAPI (Python), Pandas, Pandas-TA, NumPy
- Frontend: React.js, TailwindCSS (optional), Plotly/Recharts
- Database: SQLite (for caching and metadata)
- AI/LLM: Ollama - llama 3.1b (or OpenAI API) for natural language explanations
- Data Sources:
nsepy(Historical), Fyers (Real-time/Optional), Screener.in (Fundamentals)
Follow these steps to get the project running on your local machine.
- Python 3.9 or higher
- Node.js and npm
- Git
git clone https://github.com/Anshul-ydv/Trading_Chatbot.git
cd Trading_Chatbot# Create a virtual environment
python -m venv .venv
# Activate the virtual environment
# On macOS/Linux:
source .venv/bin/activate
# On Windows:
# .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtcd frontend
# Install Node dependencies
npm installCreate a .env file in the root directory and add your API keys:
OPENAI_API_KEY=your_openai_api_key_here # Or u can use a local LLM like ollama (we used the local one so it will easier to set up)
FYERS_APP_ID=your_fyers_app_id_here # Optional
FYERS_ACCESS_TOKEN=your_fyers_token_here # OptionalUse the authtoken.ipynb file to generate the fyers token for this project refer to this : https://myapi.fyers.in
From the root directory:
# Make sure your virtual environment is activated
uvicorn src.main:app --reload
or TCHATBOT/.venv/bin/python trading-chatbot/run.pyThe API will be available at http://localhost:8000.
Open a new terminal, navigate to the frontend folder:
cd frontend
npm start
or cd trading-chatbot/frontend && npm run devThe application will open in your browser at http://localhost:3000.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.