--- id: dhanhq version: "2.2.0" license: MIT LICENSE license_treatment: permissive maintenance: active --- # dhanhq — The official Python client for communicating with the DhanHQ API License: permissive · Maintenance: active · Downloads: 73.5K/mo ## What it is and what it does DhanHQ-py is the official Python client for the Dhan trading platform's REST and WebSocket APIs. It abstracts the complexity of communicating with Dhan's trading infrastructure, allowing developers to place and manage orders, stream real-time market data, retrieve historical candles, and query account positions and balances programmatically. The library wraps HTTP requests via the requests library and real-time feeds via websockets, with data serialization handled by pandas. The package is designed for traders and algorithmic trading systems that need to automate execution and data collection on the Dhan platform. It handles authentication via DhanLogin (OAuth or PIN/TOTP flows), manages credentials through a DhanContext object to reduce credential sprawl, and provides a high-level API for common trading workflows such as placing market or limit orders, querying order status, fetching option chains, and accessing fund details. Version 2.2.0 introduced 200-level market depth, expired options data, super orders for risk management, and IP whitelisting capabilities. Use it for: - Automate equity and derivatives order placement and cancellation on NSE and BSE exchanges without manual intervention. - Build algorithmic trading strategies that consume real-time market depth and tick data via the live market feed. - Retrieve historical OHLC candles and option chain data for backtesting and analysis workflows. - Monitor and manage open positions, holdings, and account margins programmatically. - Implement swing trading systems using Forever Orders (single or OCO) for automated risk and profit management. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Python client library for the Dhan trading API, enabling automated order placement, position management, live market data streaming, and historical data retrieval for equity and derivatives trading. Yes, if you trade on the Dhan platform and need programmatic order execution or market data access. The library has low install friction, active maintenance, permissive licensing, and no known vulnerabilities. However, v2.2.0 contains breaking changes from v2.1.0, so verify compatibility with your codebase or pin to v2.0.2 if stability is critical. Requires valid Dhan credentials and is only useful if you already have a Dhan trading account. ## Install pip install dhanhq uv add dhanhq poetry add dhanhq ## Installing dhanhq Before you install: Low install friction with a pure Python wheel and four standard runtime dependencies (pandas, requests, websockets, pyOpenSSL). Marked as active maintenance with a recent release in April 2026, though repository metadata is not publicly available. License in practice: Licensed under MIT, a permissive license that allows commercial and private use with minimal restrictions, making it safe to integrate into most projects. Quickstart: pip install dhanhq from dhanhq import DhanContext, dhanhq dhan_context = DhanContext("client_id", "access_token") dhan = dhanhq(dhan_context) dhan.place_order(security_id='1333', exchange_segment=dhan.NSE, transaction_type=dhan.BUY, quantity=10, order_type=dhan.MARKET, product_type=dhan.INTRA, price=0) Requires valid Dhan broker credentials (client_id and access_token) obtained through OAuth or PIN/TOTP authentication; API access is tied to a Dhan trading account. Verify before relying: - Whether Python version requirements are enforced (requires_python is unspecified in metadata) - Stability guarantees for v2.2.0 given the documented breaking changes from v2.1.0 - Real-world latency and reliability of websockets-based market feed under production load ## Package facts - License: MIT LICENSE (permissive) - Python support: unspecified - Install friction: low - Maintenance: active - Downloads: 73.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags trading api client python, automated order execution, real-time market data feed, dhan broker integration, equity derivatives trading, live market depth streaming, trading account management, trading-api, broker-integration, market-data [View on SkillFed](https://skillfed.io/packages/dhanhq) · [View on PyPI](https://pypi.org/project/dhanhq/)