Dhan Nse Bse Mcx API Bridge for MT5
- Libraries
-
Rajesh Kumar Nait
Hi, I'm Rajesh, a MQL Developer with a B.Tech in Information Technology. With over 12 years of programming experience, I've transitioned from being a PHP developer, specializing in web development, to a full-time MQL5 programmer and crypto trader. Having expert level experience in coding EA related - Version: 1.0
- Activations: 8
DhanHQ v2 API Bridge for MetaTrader 5
Connect MetaTrader 5 to your DhanHQ trading account and control orders,
positions, funds and portfolio directly from MQL5. This library wraps the
official DhanHQ v2 REST API (NSE, BSE, MCX) so you can build your own EAs,
scripts and automated strategies on top of Dhan.
Features
- Full order lifecycle: place, modify, cancel, slice, order book, order by ID,
order by correlation ID, trade book and trades-by-order.
- Order helpers: Market, Limit, Stop-Loss and Stop-Loss-Market.
- Super Orders (bracket): place, modify leg, cancel leg, list.
- Portfolio: holdings, positions, convert position, exit all positions.
- Funds: fund limits and margin calculator.
- Trader's Control: kill switch.
- Authentication via access-token header + Dhan Client ID.
- Static IP whitelisting (Set / Modify / Get IP) with a simple enable/disable
switch in config — required by SEBI/exchange rules for order placement.
- JSON response helpers to read orderId and orderStatus.
- Debug logging of every request/response.
Setup
1. Generate a 24-hour Access Token and copy your Client ID from
web.dhan.co (My Profile -> Access DhanHQ APIs).
2. In MetaTrader 5 open Tools -> Options -> Expert Advisors, enable
"Allow WebRequest for listed URL" and add:
https://api.dhan.co
3. Enter your token, client ID and (if required) your static IP in the
script inputs.
4. Static IP whitelisting is mandatory for order placement, modification
and cancellation. Enable it in config or set it once on web.dhan.co.
References
- API documentation: https://docs.dhanhq.co/api/v2/
- Authentication: https://docs.dhanhq.co/api/v2/guides/authentication
- Trading APIs: https://docs.dhanhq.co/api/v2/trading-apis
- Static IP setup: https://docs.dhanhq.co/api/v2/authentication/set-ip
Note: Trading involves financial risk. Test on a non-critical account first.
Your API credentials are never stored in the code — you provide them at runtime.
Requirements
1. Dhan Chart & Trading API subscription
2. Dhan Charting product for Charts - https://www.mql5.com/en/market/product/197711
Sample Script for testing trading operations - https://www.mql5.com/en/blogs/post/776274
For support and free install /configure, DM to author after purchasing this product.
