Skip to content

Tanmay-312/trade-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📈 AI-Powered Nifty Options Scalper

A high-frequency, ML-backed trading engine designed for scalping Nifty 50 Options. It uses a hybrid architecture with Go for low-latency execution and Python for machine learning inference.


🎯 Features

  • Hybrid Architecture: Go for speed, microservices and concurrency; Python for real-time data intelligence and time-series.

  • Real-time Scalping: Targets 1-3 point scalps on Nifty 50.

  • Ghost Mode: Test strategies with paper money before risking real capital.

  • Smart Order Execution: Uses Zerodha Kite Connect API for direct market access.

  • Web-based Dashboard: Monitor trades, P&L, and system health in real-time.

  • Auto-Recovery: Built-in logic to handle network disconnects and resume trading.


🚀 System Architecture

The system is split into three decoupled microservices:

The Muscle (Backend - Go):

  • Connects to Zerodha Kite Ticker (Websockets).

  • Manages "Ghost Mode" vs. "Live Execution".

  • Handles Order Management System (OMS) and risk checks.

  • Communcates with the Brain via gRPC.

The Brain (ML Service - Python):

  • Runs an XGBoost model trained on technical indicators (RSI, MACD, Bollinger Bands).

  • Receives real-time ticks, calculates feature vectors, and returns probabilities.

  • Exposes a gRPC endpoint (GetPrediction).

The Dashboard (Frontend - Next.js):

  • Real-time visualization of market ticks and trade logic.

  • Manual "Kill Switch" and configuration.


🛠️ Tech Stack

  • Languages: Go (Golang) 1.21+, Python 3.11+

  • Broker API: Zerodha Kite Connect

  • Machine Learning: XGBoost, Pandas, TA-Lib/Pandas-TA, yfinance

  • Communication: gRPC (Protobuf), WebSockets

  • Database: QuestDB (Tick storage), PostgreSQL (Trade logs)

  • Frontend: Next.js 14, TailwindCSS, Recharts


⚙️ Installation & Setup

Prerequisites

  • Docker & Docker Compose

  • Go 1.21+

  • Python 3.11+

  • Node.js 20+

  • Zerodha Kite API Key & Secret


Choose either of method 1.2 or method 2.1 + 2.2 + 2.3. Method 1.1 is common.

1.1. Clone & Configure

git clone https://github.com/yourusername/trade-engine.git
cd trade-engine

Create a root .env file:

# Zerodha Credentials
KITE_API_KEY=your_api_key
KITE_API_SECRET=your_api_secret
KITE_REQUEST_TOKEN=  # Updated manually daily

# System Configuration
MODE=LIVE            # SIMULATION or LIVE
TRADING_ENABLED=false # Safety switch (false = Ghost Mode)
BRAIN_URL=localhost:50051

# Kindly put both the db urls, name, password, dbname, port, etc in env after running them on local system

1.2. Run all the once

# windows
./start_all.ps1

# linux
chmod +x start_all.sh
./start_all.sh

# mac
chmod +x start_all.command
./start_all.command

2.1. The Brain (Python)

Install dependencies and train the initial model:

cd brain
poetry install  # or pip install -r requirements.txt
python train.py # Downloads data from yfinance and generates model.json
python server.py # Starts the gRPC inference engine

2.2. The Muscle (Go)

Run the execution engine:

cd backend
go mod tidy
go run main.go
# Follow the terminal prompt to login to Zerodha if token is expired.

2.3. The Dashboard (Next.js)

cd frontend
npm install
npm run dev
# Visit http://localhost:3000 to view the trading desk.

🚦 Usage Guide

Phase 1: Backtesting (Python)

Before going live, verify your strategy:

cd brain
python backtest.py
# Check the generated equity_curve.png to ensure positive expectancy.

Phase 2: Ghost Mode (Simulation)

  • Set TRADING_ENABLED=false in .env.

  • Start the Go backend.

  • Watch the logs. The bot will process real live ticks and simulate orders:

🤖 [GHOST] Would have BOUGHT NIFTY26FEB24500CE at 120.50

Phase 3: Live Trading

  • Verify Ghost Mode performance for at least 1 hour.

  • Set TRADING_ENABLED=true.

  • Restart the Backend.

  • Monitor the dashboard closely. Use the UI "Stop" button to kill the engine instantly if needed.


⚠️ Risk Warning

  • Options trading involves significant risk. This software is for educational purposes. The authors are not responsible for financial losses incurred by using this bot.

  • Always test in "Ghost Mode" first.

  • Keep TRADING_ENABLED=false until you are 100% sure.

  • Hardcode a MAX_LOSS limit in the Go backend.

About

Nifty Options Scalper built on top of GOlang, Python, Next.js Typescript, Postgresql, QuestDB using yfinance and Zerodha over Websockets, gRPC (protobuf - proto3)

Topics

Resources

Stars

Watchers

Forks

Contributors