Skip to content

Customised data collection, real time data processing and trade execution system for kite api.

Notifications You must be signed in to change notification settings

Mayank-8127/zerodha

Repository files navigation

Zerodha Automated Trading & Data Analysis Platform

A fully automated trading and data analysis system built with Python, featuring modular architecture, real-time data processing, and automated strategy execution for the Indian stock market through Zerodha Kite API.

🏗️ Architecture Overview

This project implements a distributed, modular architecture with the following key components:

  • Data Collection Module: Real-time market data ingestion and storage
  • Trading Strategy Module: Automated trading logic and execution
  • Login Module: Automated authentication and session management
  • Order Management Module: Order placement and position tracking
  • Configuration Module: Centralized configuration management
  • Data Analysis Module: Historical data analysis and reporting

🚀 Key Features

  • Fully Automated Trading: Hands-off operation with scheduled execution
  • Real-time Data Processing: Live market data collection and analysis
  • Modular Design: Independent, scalable components for easy maintenance
  • Redis Pub/Sub: Decoupled communication between modules
  • Cron Job Integration: Scheduled automated tasks and monitoring
  • Process Management: Robust monitoring and recovery mechanisms
  • Historical Analysis: Comprehensive data analytics and reporting

📁 Project Structure

zerodha/
├── ConfigModule/          # Configuration management
│   ├── config.json       # Main configuration file
│   └── config_loader.py  # Configuration loading utilities
├── DataModule/           # Real-time data collection
│   ├── data_collection.py # Market data ingestion
│   └── get_instruments.py # Instrument data fetching
├── LoginModule/          # Authentication management
│   └── kite_login.py     # Automated login handling
├── OrderModule/          # Order management
│   └── place_order.py    # Order placement logic
├── Scripts/              # Trading strategies
│   └── 01_nifty50_half_hour_buy_sell_strategy.py
├── DataAnalysis/         # Analytics and reporting
│   ├── 01_strike_price_graph.py
│   └── 02_5min_candle.py
├── ShellScripts/         # Automation scripts
│   ├── manage_processes.sh
│   ├── data_collection.sh
│   └── daily_login.sh
├── Data/                 # Historical data storage
└── Log/                  # Application logs

🛠️ Technologies Used

  • Python 3.12: Core programming language
  • KiteConnect API: Zerodha trading platform integration
  • Redis: Real-time message broker for pub/sub communication
  • Pandas: Data analysis and manipulation
  • Shell Scripting: Process automation and monitoring
  • Cron Jobs: Scheduled task execution
  • JSON: Configuration and data storage

⚙️ Setup and Installation

Prerequisites

  • Python 3.12+
  • Redis server
  • Zerodha Kite trading account with API access

Installation

  1. Clone the repository:
git clone https://github.com/Mayank-8127/zerodha.git
cd zerodha
  1. Install dependencies:
pip install -r requirements.txt
  1. Start Redis server:
redis-server
  1. Configure the application:

    • Update ConfigModule/config.json with your Zerodha API credentials
    • Set correct file paths for your environment
  2. Set up cron jobs (optional):

# Add to crontab for automated execution
crontab -e

🚦 Usage

Manual Execution

  1. Start data collection:
python3 -m DataModule.data_collection
  1. Run trading strategy:
python3 -m Scripts.01_nifty50_half_hour_buy_sell_strategy
  1. Monitor processes:
./ShellScripts/manage_processes.sh

Automated Execution

The system supports fully automated operation through shell scripts and cron jobs:

  • Daily login automation: ./ShellScripts/daily_login.sh
  • Data collection: ./ShellScripts/data_collection.sh
  • Process monitoring: ./ShellScripts/manage_processes.sh

📊 Data Flow

  1. Authentication: Automated login through Zerodha Kite API
  2. Data Ingestion: Real-time market data collection via WebSocket
  3. Message Broker: Redis pub/sub for inter-module communication
  4. Strategy Execution: Automated trading decisions based on market data
  5. Order Management: Automatic order placement and position tracking
  6. Data Storage: Historical data archival and analysis

🔧 Key Modules

Data Collection Module

  • Real-time market data ingestion using KiteTicker
  • Redis pub/sub for broadcasting tick data
  • CSV storage for historical analysis
  • Support for multiple instruments and indices

Trading Strategy Module

  • Nifty 50 options trading strategy
  • Real-time price monitoring via Redis
  • Automated buy/sell signal generation
  • Position management and risk controls

Configuration Module

  • Centralized configuration management
  • JSON-based configuration storage
  • Dynamic configuration loading
  • Environment-specific settings

📈 Analytics and Reporting

The platform includes comprehensive data analysis capabilities:

  • Strike Price Analysis: Options strike price visualization
  • Candlestick Charts: 5-minute interval market analysis
  • Historical Data Processing: Automated report generation
  • Performance Metrics: Trading strategy backtesting

🔒 Security Features

  • Secure API key management
  • Two-factor authentication support
  • Session management and token refresh
  • Error handling and logging

📝 Logging

Comprehensive logging system with:

  • Application-level logging in Log/ directory
  • Strategy-specific logs for debugging
  • Error tracking and monitoring
  • Process execution logs

🔄 Process Management

Robust process management with:

  • Automated process monitoring
  • Recovery mechanisms for failed processes
  • Shell script-based process control
  • Cron job integration for scheduling

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/new-feature)
  5. Create a Pull Request

⚠️ Disclaimer

This software is for educational and research purposes only. Trading in financial markets involves substantial risk of loss. Users should:

  • Thoroughly test strategies in paper trading mode
  • Understand the risks involved in automated trading
  • Comply with all applicable regulations
  • Use proper risk management techniques

📄 License

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

📞 Support

For support and questions:

  • Create an issue on GitHub
  • Review the documentation in each module
  • Check the logs for debugging information

Note: Make sure to properly configure your Zerodha API credentials and test thoroughly before using in live trading environments.

About

Customised data collection, real time data processing and trade execution system for kite api.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published