
Zerodha Trading
STDIOPython-based Zerodha trading assistant with interactive chat interface for account management.
Python-based Zerodha trading assistant with interactive chat interface for account management.
A Python-based trading assistant that connects to a Zerodha MCP server to help users manage their trading account.
git clone https://github.com/mtwn105/zerodha-mcp-server-client.git cd zerodha-mcp-server-client
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
# Copy the example environment file cp .env.example .env # Edit the .env file with your credentials
.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
The server provides a set of tools for interacting with the Zerodha trading platform. To start the server:
Make sure your .env
file is properly configured with your Zerodha API credentials.
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 authenticationget_access_token
: Generate access token using request tokenget_user_profile
: Get user's Zerodha profile informationget_margins
: Get available margins and fund detailsget_holdings
: Get portfolio holdingsget_positions
: Get current positionsget_orders
: Get all orders for the dayget_order_history
: Get history of a specific orderget_order_trades
: Get trades generated by an orderplace_order
: Place a new ordermodify_order
: Modify an existing ordercancel_order
: Cancel an orderThis project provides three client implementations:
client/agno_client.py
)client/agno_gradio_client.py
)client/google_adk_client.py
)All clients connect to the MCP server and provide an interactive interface for trading operations.
.env
file includes OPENAI_API_KEY
.# 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
GOOGLE_API_KEY
environment variable (and uncommenting it in .env
) or by using Application Default Credentials (run gcloud auth application-default login
).# 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
.env
file includes OPENAI_API_KEY
.# Using environment variables from .env file python client/agno_gradio_client.py # Using command line arguments for server configuration python client/agno_gradio_client.py --host localhost --port 8001
Open your web browser and navigate to the URL shown in the terminal (typically http://localhost:7860
).
Use the web interface to:
The Gradio interface provides:
Both clients support configuration through multiple sources, with the following precedence:
.env
file variablesConfiguration options:
MCP_HOST
and MCP_PORT
--host
and --port
.env
file variables: MCP_HOST
, MCP_PORT
, OPENAI_API_KEY
, and GOOGLE_API_KEY
Default values (if no configuration is provided):
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
The client will automatically connect to the MCP server using the provided configuration.
Once connected, you can interact with the assistant using natural language commands. For example:
To exit the client, type 'quit' when prompted.
client/agno_client.py
: MCP client implementation using Agnoclient/google_adk_client.py
: MCP client implementation using Google ADKclient/agno_gradio_client.py
: Web interface using Gradio and Agnoserver.py
: MCP server implementation with Zerodha API integrationgenerate_token.py
: Utility for generating access tokensrequirements.txt
: Project dependencies.env
: Environment configurationThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.