Zerodha交易集成

通过Claude AI与Zerodha交易平台集成,实现直接通过Claude与Zerodha交易账户交互的功能。

  • by aptro
  • Python
  • 本地部署
  • 46 星标
  • 更新于
在 GitHub 查看 aptro/zerodha-mcp

使用说明

Zerodha MCP集成

该项目使用多云插件(MCP)框架将Zerodha的交易平台与Claude AI集成在一起,允许您直接通过Claude与您的Zerodha交易账户进行交互。

安装说明

通过Smithery安装

通过以下方式自动安装克劳德桌面版zerodha mcp 史密瑟里:

npx -y @smithery/cli install @aptro/zerodha-mcp --client claude

1.创建Zerodha开发者帐户

  1. 首选 风筝连接 并注册开发人员帐户
  2. 登录您的帐户 developers.kite.trade

2.创建新应用程序

  1. 导航到Kite Developer仪表板中的“应用程序”部分
  2. 点击“创建新应用”
  3. 填写所需的详细信息:
    • 应用程序名称:选择一个描述性名称(例如“Claude Zerodha Integration”)
    • 应用类别:选择“个人”或适当的类别
    • 重定向URL:设置为 http://127.0.0.1:5000/zerodha/auth/redirect
    • 说明:简要描述您的申请目的
  4. 提交表单以创建您的应用程序

3.获取API证书

创建应用程序后,您将收到:

  • API密钥(也称为消费者密钥)
  • API秘密(也称为消费者秘密)

这些凭据将显示在您的应用程序的详细信息页面上。

4.配置环境变量

  1. 创建一个 .env 此项目根目录中的文件
  2. 将API凭据添加到文件中:
KITE_API_KEY=your_api_key_here
KITE_API_SECRET=your_api_secret_here

替换 your_api_key_here 和 your_api_secret_here 使用步骤3中的实际凭证。

5.安装依赖项

确保已安装所有必需的依赖项:

uv pip install kiteconnect fastapi uvicorn python-dotenv httpx

6.在您的Claude桌面应用程序上安装MCP配置

在您的Claude桌面应用程序上安装MCP配置:

mcp install main.py

此命令向Claude注册Zerodha插件,使AI可以使用所有交易功能。

用法

设置后,您可以使用以下功能通过Claude与您的Zerodha帐户进行交互:

认证

Can you please check if I'm logged into my Zerodha account and authenticate if needed?

股票和一般交易

  • 检查账户保证金: What are my current margins on Zerodha?
  • 查看投资组合持有量: Show me my current holdings on Zerodha
  • 检查当前位置: What positions do I currently have open on Zerodha?
  • 获取符号的引号: What's the current price of RELIANCE and INFY on NSE?
  • 下订单: Place a buy order for 10 shares of INFY at market price on NSE
  • 获取历史数据: Can you show me the historical price data for SBIN for the last 30 days?

共同基金

  • 查看共同基金持有量: Show me my mutual fund holdings on Zerodha
  • 获取共同基金订单: List all my mutual fund orders on Zerodha
  • 下共同基金订单: Place a buy order for ₹5000 in the mutual fund with symbol INF090I01239
  • 取消共同基金订单: Cancel my mutual fund order with order ID 123456789
  • 查看SIP详细信息: Show all my active SIPs on Zerodha
  • 创建新的SIP: Set up a monthly SIP of ₹2000 for the fund with symbol INF090I01239 for 12 installments
  • 修改现有SIP: Change my SIP with ID 987654321 to ₹3000 per month
  • 取消SIP: Cancel my SIP with ID 987654321
  • 浏览可用的共同基金: Show me a list of available mutual funds on Zerodha

身份验证流程

第一次使用Zerodha功能时,Claude将:

  1. 在端口5000上启动本地服务器
  2. 打开浏览器窗口进行Zerodha登录
  3. 成功登录后,存储访问令牌以备将来会话使用

您的会话将保持活动状态,直到令牌到期(通常为24小时)。当令牌过期时,Claude将自动再次启动登录流程。

可用的MCP工具

此插件提供了Claude可以使用的以下MCP工具:

认证

  • check_and_authenticate -验证身份验证状态,并在需要时启动登录
  • initiate_login -启动Zerodha登录流程
  • get_request_token -登录后检索请求令牌

股票/一般交易

  • get_holdings -检索投资组合持有量
  • get_positions -获取当前职位
  • get_margins -检索账户保证金
  • place_order -下达交易订单
  • get_quote -获取指定符号的引号
  • get_historical_data -检索历史价格数据

共同基金

  • get_mf_orders -检索共同基金订单
  • place_mf_order -下共同基金订单
  • cancel_mf_order -取消共同基金订单
  • get_mf_instruments -获取可用的共同基金工具
  • get_mf_holdings -检索共同基金持有量
  • get_mf_sips -获取活动SIP
  • place_mf_sip -创建新的SIP
  • modify_mf_sip -修改现有SIP
  • cancel_mf_sip -取消SIP

故障排除

  • 如果遇到身份验证问题,请尝试删除 .tokens 文件并重新启动身份验证过程
  • 确保您的Zerodha证书在 .env 文件正确
  • 确保端口5000未被其他应用程序使用
  • 对于持续存在的问题,请在上查看Zerodha的API状态 status.zerodha.com

安全说明

  • 您的Zerodha API凭证仅存储在您的本地 .env 文件
  • 访问令牌存储在 .tokens 项目目录中的文件
  • 不会将凭据传输给Claude或任何第三方
  • 所有身份验证都直接在您和Zerodha的服务器之间进行