Dhan MCP服务器——Python版
一个用于Dhan交易API的模型上下文协议(MCP)服务器,由官方构建 dhanhq Python库。
特性
✅ OAuth身份验证 --安全的用户驱动OAuth流 ✅ 完整的Dhan API --所有交易、市场数据和投资组合API ✅ HTTP传输 --Docker的持久服务器模式 ✅ 官方图书馆 --用途 dhanhq Python包直接
设置
选项A:Docker(推荐)
- 创建
.env:
cp .env.example .env- 编辑
.env具有凭据(见下文)
- 启动服务器:
docker compose up -d- 检查健康状况:
curl http://localhost:3005/health选项B:本地Python
- 安装依赖项:
pip install -r requirements.txt- 运行服务器:
python server.pyOAuth流
第一步:启动OAuth
curl http://localhost:3005/oauth/login第二步:用户登录
打开返回的 login_url 在浏览器中进行身份验证
第三步:代币交换
服务器在回调时自动将令牌交换为access_token
可用工具
认证
- oauth_start、oauth_exchange_token
投资组合
- get_fund_limits、get_holdings、get_positions
订单
- get_order_list、get_order_by_id、place_order、cancel_order和modify_order
市场数据
- get_quote、get_market_depth、get_ohlc
历史数据
- get_traday_candles、get_dely_handles、get_trade_history
账户
- get_count_summary
配置
# Required
DHAN_CLIENT_ID=your_client_id
# OAuth (Recommended)
DHAN_APP_ID=your_app_id
DHAN_APP_SECRET=your_app_secret
# OR Static Token
DHAN_ACCESS_TOKEN=your_access_token
# Server
MCP_TRANSPORT=http|stdio
MCP_PORT=3005许可证
麻省理工学院
