Cover image
Try Now
2025-04-15

Zerodha MCP服务器和客户端(风筝X AGNO)

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

Zerodha MCP Server & Client

A Python-based trading assistant that connects to a Zerodha MCP server to help users manage their trading account.

Features

  • Account Management: Manage Zerodha trading account, orders, and positions
  • Interactive Chat Interface: Natural language interface for trading operations
  • MCP Integration: Built on the Model Context Protocol for standardized communication
  • Zerodha API Integration: Uses Zerodha's API to interact with the trading platform
  • Agno Agent: Uses Agno Agent to interact with the trading platform
  • Google ADK Agent: Uses Google ADK Agent to interact with the trading platform

Tech Stack

Tools

  • Place Orders: Place orders in the trading platform
  • Modify Orders: Modify orders in the trading platform
  • Cancel Orders: Cancel orders in the trading platform
  • Get Orders: Get orders in the trading platform
  • Get Order History: Get order history in the trading platform
  • Get Order Trades: Get order trades in the trading platform
  • Get Margins: Get margins in the trading platform
  • Get Holdings: Get holdings in the trading platform
  • Get Positions: Get positions in the trading platform
  • Get User Profile: Get user profile in the trading platform

Prerequisites

  • Python
  • Zerodha trading account with Personal API access from here
  • Zerodha API key and secret
  • OpenAI API key (for Agno Agent)
  • Gemini API key or Application Default Credentials (for Google ADK Agent)

Installation

  1. Clone the repository:
git clone https://github.com/mtwn105/zerodha-mcp-server-client.git
cd zerodha-mcp-server-client
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
# Copy the example environment file
cp .env.example .env

# Edit the .env file with your credentials
  1. Create a .env file with your configuration:
# Server Configuration
ZERODHA_API_KEY=your_api_key
ZERODHA_API_SECRET=your_api_secret
PORT=8001
SERVER_MODE=sse  # or stdio

# Client Configuration
MCP_HOST=localhost
MCP_PORT=8001
OPENAI_API_KEY=your_openai_api_key
# GOOGLE_API_KEY=your_google_api_key

Server Usage

The server provides a set of tools for interacting with the Zerodha trading platform. To start the server:

  1. Make sure your .env file is properly configured with your Zerodha API credentials.

  2. Start the server using one of the following methods:

# Using environment variables
python server.py

# Or using command line arguments
python server.py --api-key your_api_key --api-secret your_api_secret --port 8001 --mode sse

The server provides the following tools:

  • get_login_url: Get the login URL for user authentication
  • get_access_token: Generate access token using request token
  • get_user_profile: Get user's Zerodha profile information
  • get_margins: Get available margins and fund details
  • get_holdings: Get portfolio holdings
  • get_positions: Get current positions
  • get_orders: Get all orders for the day
  • get_order_history: Get history of a specific order
  • get_order_trades: Get trades generated by an order
  • place_order: Place a new order
  • modify_order: Modify an existing order
  • cancel_order: Cancel an order

Client Usage

This project provides two client implementations: one using the Agno framework (client/agno_client.py) and another using Google ADK (client/google_adk_client.py). Both connect to the MCP server and provide an interactive interface for trading operations.

Running the Agno Client

  1. Ensure your .env file includes OPENAI_API_KEY.
  2. Start the client using one of the following methods:
# Using environment variables from .env file
python client/agno_client.py

# Using command line arguments
python client/agno_client.py --host localhost --port 8001

# Using a combination (command line arguments take precedence)
MCP_HOST=localhost MCP_PORT=8001 python client/agno_client.py --host otherhost --port 9000

Running the Google ADK Client

  1. Ensure you have authenticated with Google AI, either by setting the GOOGLE_API_KEY environment variable (and uncommenting it in .env) or by using Application Default Credentials (run gcloud auth application-default login).
  2. Start the client using one of the following methods:
# Using environment variables from .env file
python client/google_adk_client.py

# Using command line arguments
python client/google_adk_client.py --host localhost --port 8001

# Using a combination (command line arguments take precedence)
MCP_HOST=localhost MCP_PORT=8001 python client/google_adk_client.py --host otherhost --port 9000

Client Configuration

Both clients support configuration through multiple sources, with the following precedence:

  1. Command-line arguments (highest precedence)
  2. Environment variables
  3. .env file variables

Configuration options:

  • Environment variables: MCP_HOST and MCP_PORT
  • Command-line arguments: --host and --port
  • .env file variables: MCP_HOST, MCP_PORT, OPENAI_API_KEY, and GOOGLE_API_KEY

Default values (if no configuration is provided):

  • Host: localhost
  • Port: 8001

The client automatically loads environment variables from the .env file in the project root directory. Make sure your .env file contains the necessary configuration:

# Client Configuration
MCP_HOST=localhost
MCP_PORT=8001
OPENAI_API_KEY=your_openai_api_key
# GOOGLE_API_KEY=your_google_api_key
  1. The client will automatically connect to the MCP server using the provided configuration.

  2. Once connected, you can interact with the assistant using natural language commands. For example:

    • "Show me my portfolio holdings"
    • "What are my current positions?"
    • "Place a market order for 10 shares of RELIANCE"
    • "Cancel order ID 123456"
  3. To exit the client, type 'quit' when prompted.

Development

Project Structure

  • client/agno_client.py: MCP client implementation using Agno
  • client/google_adk_client.py: MCP client implementation using Google ADK
  • server.py: MCP server implementation with Zerodha API integration
  • generate_token.py: Utility for generating access tokens
  • requirements.txt: Project dependencies
  • .env: Environment configuration

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

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

Acknowledgments

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • Lists Tailwind CSS classes in monospaced font

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • tomoyoshi hirata
  • Sony α7IIIマニュアルアシスタント

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • HiveNexus
  • 一个适用于中小型团队的AI聊天机器人,支持DeepSeek,Open AI,Claude和Gemini等车型。 专为中小团队设计的ai聊天应用,支持deepSeek,打开ai,claude,双子座等模型。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

    Reviews

    2 (1)
    Avatar
    user_GxI0P3Sk
    2025-04-16

    Zerodha-mcp is an exceptional tool for streamlining financial operations. The user-friendly interface makes it easy to navigate and utilize its features. Created by mtwn105, this application is a game-changer for those trading on Zerodha. I highly recommend it for anyone looking to enhance their trading experience. More info can be found on GitHub at https://github.com/mtwn105/zerodha-mcp.