Loading...
Loading...
Use when the user mentions DhanHQ, Dhan API, or wants to trade on Indian exchanges (NSE, BSE, MCX). Triggers for: place, modify, or cancel stock/F&O/commodity orders on Dhan; fetch portfolio holdings or positions; get live or historical market data; access option chains with Greeks; check fund limits or margin; build any trading automation for Indian markets; resolve NSE/BSE instrument IDs; stream live WebSocket market feeds or order updates. Also trigger for general questions about programmatic trading on Indian exchanges if Dhan is the user's broker.
npx skill4agent add dhan-oss/dhanhq-skills dhanhqpip install dhanhqpip install --upgrade dhanhqfrom dhanhq import DhanContext, dhanhq
dhan_context = DhanContext("YOUR_CLIENT_ID", "YOUR_ACCESS_TOKEN")
dhan = dhanhq(dhan_context)import os
from dhanhq import DhanContext, dhanhq
dhan_context = DhanContext(
os.environ["DHAN_CLIENT_ID"],
os.environ["DHAN_ACCESS_TOKEN"],
)
dhan = dhanhq(dhan_context)from scripts.dhan_helpers import get_client
dhan, dhan_context = get_client()LIMITMARKETRs. 50,000CNCMTFmodify_ordercancel_orderkill_switchdhan_login.user_profile(...)GET /profiledataPlantokenValidityactiveSegmentddpimtfdataPlandataValidity| Category | Constant | Value |
|---|---|---|
| Exchange | | |
| | |
| | |
| | |
| | |
| | |
| | |
| Transaction | | |
| | |
| Order Type | | |
| | |
| | |
| | |
| Product | | |
| | |
| | |
| | |
| Validity | | |
| |
| Task | Method |
|---|---|
| Place order | |
| Slice large order | |
| Modify order | |
| Cancel order | |
| Order book | |
| Order by ID | |
| Order by correlation ID | |
| Trade book | |
| Trade history | |
| Ledger | |
| Super orders | |
| Forever orders | |
| Holdings | |
| Positions | |
| Convert position | |
| eDIS | |
| Fund limits | |
| Margin calculator | |
| Daily history | |
| Minute history | |
| Expired options data | |
| Market quote snapshot | |
| Expiry list | |
| Option chain | |
| Security master | |
| Live market feed | |
| Live order updates | |
| Full market depth | |
| Kill switch | |
{"status": "success"|"failure", "remarks": ..., "data": ...}ce_ltpce_oice_ivintraday_minute_data(...)historical_minute_data()expiry_code[0, 1, 2, 3]0121 request/secdata["oc"]| Segment | Allowed Product Types |
|---|---|
| |
| |
security_idlot_sizetick_size| Underlying | security_id | Underlying Segment |
|---|---|---|
| NIFTY 50 | | |
| BANK NIFTY | | |
| FINNIFTY | | |
| MIDCPNIFTY | | |
| SENSEX | | |
get_client()resolve_symbol()resolve_derivative()fetch_chain_df()find_atm_row()check_margin()preview_order()from dhanhq import DhanLogin
dhan_login = DhanLogin("YOUR_CLIENT_ID")
profile = dhan_login.user_profile("YOUR_ACCESS_TOKEN")
print(profile["dataPlan"])
print(profile["dataValidity"])data = dhan.historical_daily_data(
security_id="2885",
exchange_segment=dhanhq.NSE,
instrument_type="EQUITY",
from_date="2024-01-01",
to_date="2024-12-31",
)
if data["status"] == "success":
candles = data["data"]
timestamps = [dhan.convert_to_date_time(ts) for ts in candles["timestamp"]]from scripts.dhan_helpers import fetch_chain_df, find_atm_row
chain_df, spot = fetch_chain_df(dhan, under_security_id=13, expiry="2025-03-27")
atm = find_atm_row(chain_df, spot)
print(spot)
print(atm["strike"])
print(atm["ce_security_id"], atm["ce_ltp"])from scripts.dhan_helpers import check_margin
margin = check_margin(
dhan,
security_id="2885",
exchange_segment=dhanhq.NSE,
transaction_type=dhanhq.BUY,
quantity=10,
product_type=dhanhq.CNC,
price=2450.0,
)
print(margin["sufficient"], margin["total_margin"], margin["available_balance"])from dhanhq import MarketFeed
instruments = [
(MarketFeed.NSE, "2885", MarketFeed.Ticker),
(MarketFeed.NSE_FNO, "49081", MarketFeed.Full),
]
feed = MarketFeed(dhan_context, instruments, "v2")
feed.run_forever()
print(feed.get_data())| API Category | Per Second | Per Minute | Per Hour | Per Day |
|---|---|---|---|---|
| Order APIs | 10 | 250 | 1000 | 7000 |
| Data APIs | 5 | - | - | 100000 |
| Quote APIs | 1 | Unlimited | Unlimited | Unlimited |
| Non-Trading APIs | 20 | Unlimited | Unlimited | Unlimited |
references/scanx-data.md| Need | File |
|---|---|
| Orders, super orders, forever orders | references/orders.md |
| Holdings, positions, eDIS | references/portfolio.md |
| Daily/minute history, quotes, expired options | references/market-data.md |
| Option-chain usage and normalization | references/option-chain.md |
| Fund limits and margin checks | references/funds.md |
| Live feeds and depth | references/live-feed.md |
| Error handling and subscription troubleshooting | references/error-codes.md |
| Instrument resolution | references/instruments.md |
| Multi-step execution patterns | references/common-workflows.md |
| Options analytics | references/options-analysis-patterns.md |
| Backtesting patterns | references/backtesting-with-dhan.md |
| PE ratio, RSI, financials, screeners — data Dhan does not provide | references/scanx-data.md |
DH-902806web.dhan.coMy ProfileAccess DhanHQ APIsdataPlanticker_data()ohlc_data()