dhanhq
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 limit
By dhan-oss · 1,094 installs
npx skills add dhan-oss/dhanhq-skills --skill dhanhq
Source repository · Upstream listing
DhanHQ — Indian Market Trading Skill
Setup
Stable install:
Use the current SDK branch when you need newer v2 capabilities such as 200 level depth or the latest helper coverage:
Minimal initialization:
Environment variable setup:
If generating scripts for this repo, prefer:
Safety Rules — Always Enforce
1. Confirm before placing live orders.
2. Show a readable order preview before execution.
3. Default to LIMIT orders unless the user explicitly wants MARKET .
4. Warn when notional exceeds Rs. 50,000 .
5. For F&O, validate lot size before placement.
6. Never use CNC or MTF for F&O, commodity, or currency segments.
7. Never hardcode credentials in generated code.
8. Ask for confirmation before modify order , cancel order , kill switch , or any multi leg live execution.
Access Checks Before Live Use
Before using the account for live work, verify:
1. Access token is valid.
2. dhan login.user profile(...) or GET /profile shows the needed account setup.
3. dataPlan is active for quote/history/feed/option chain use.
4. Static IP is configured for order placement, order modification, order cancellation, super orders, and forever orders.
Useful profile fields:
tokenValidity
activeSegment
ddpi
mtf
dataPlan
dataValidity
Current SDK Constants
Category Constant Value
Exchange dhanhq.NSE NSE EQ
dhanhq.BSE BSE EQ
dhanhq.NSE FNO NSE FNO
dhanhq.BSE FNO BSE FNO
dhanhq.MCX MCX COMM
dhanhq.CUR NSE CURRENCY
dhanhq.INDEX IDX I
Transaction dhanhq.BUY BUY
dhanhq.SELL SELL
Order Type dhanhq.LIMIT LIMIT
dhanhq.MARKET MARKET
dhanhq.SL STOP LOSS
dhanhq.SLM STOP LOSS MARKET
Product dhanhq.CNC CNC
dhanhq.INTRA INTRADAY
dhanhq.MARGIN MARGIN
dhanhq.MTF MTF
Validity dhanhq.DAY DAY
dhanhq.IOC IOC
Current SDK Methods To Prefer
Task Method
Place order dhan.place order()
Slice large order dhan.place slice order()
Modify order dhan.modify order()
Cancel order dhan.cancel order()
Order book dhan.get order list()
Order by ID dhan.get order by id()
Order by correlation ID dhan.get order by correlationID()
Trade book dhan.get trade book()
Trade history dhan.get trade history()
Ledger dhan.ledger report()
Super orders place super order() , modify super order() , cancel super order() , get super order list()
Forever orders place forever() , modify forever() , cancel forever() , get forever()
Holdings dhan.get holdings()
Positions dhan.get positions()
Convert position dhan.convert position()
eDIS dhan.generate tpin() , dhan.open browser for tpin() , dhan.edis inquiry()
Fund limits dhan.get fund limits()
Margin calculator dhan.margin calculator()
Daily history dhan.historical daily data()
Minute history dhan.intraday minute data()
Expired options data dhan.expired options data()
Market quote snapshot dhan.ticker data() , dhan.ohlc data() , dhan.quote data()
Expiry list dhan.expiry list()
Option chain dhan.option chain()
Security master dhanhq.fetch security list()
Live market feed MarketFeed
Live order updates OrderUpdate
Full market depth FullDepth
Kill switch dhan.kill switch() , dhan.status kill switch()
High Value Gotchas
The SDK wraps HTTP responses as {"status": "success" "failure", "remarks": ..., "data": ...} . Response shapes vary by endpoint — success payloads differ significantly (arrays, flat objects, nested dicts) depending on the API.
Repo helpers add a normalization layer. Fields like ce ltp , ce oi , ce iv are repo defined names — not raw Dhan field names.
intraday minute data(...) is the current SDK method. Do not reference historical minute data() .
Historical timestamps are epoch values. Convert them explicitly.
The SDK currently validates expiry code with [0, 1, 2, 3] , but Dhan's v2 annexure documents 0 , 1 , 2 . Prefer the documented values unless Dhan updates the API docs.
Quote APIs are rate limited to 1 request/sec .
Option chain REST data is keyed by strike string under data["oc"] . Use repo helpers for analysis friendly rows.
Market orders via API are currently converted by Dhan into limit orders with MPP.
Order placement APIs require static IP whitelisting.
Trading APIs are free for Dhan users; Data APIs require an active data plan.
Lot sizes and freeze quantities change. Treat hardcoded values as fallback only.
Product Type Rules
Segment Allowed Product Types
NSE EQ , BSE EQ CNC , INTRADAY , MARGIN , MTF
NSE FNO , BSE FNO , MCX COMM , NSE CURRENCY , BSE CURRENCY INTRADAY , MARGIN
Instrument Resolution Rules
Use the security master as the primary source for:
security id
lot size
tick size
expiry
strike
derivative contract lookup
Quick reference index underlyings:
Underlying security id Underlying Segment
NIFTY 50 13 IDX I
BANK NIFTY 25 IDX I
FINNIFTY 27 IDX I
MIDCPNIFTY 442 IDX I
SENSEX 51 IDX I
Preferred Helper Layer
When generating scripts in this repo, prefer:
get client() for SDK bootstrapping
resolve symbol() for cash market lookup
resolve derivative() for contract lookup
fetch chain df() for option chain normalization
find atm row() for ATM selection
check margin() for pre flight margin checks
preview order() for readable confirmation
Core Patterns
1. Check account access before data calls
2. Fetch historical data with epoch conversion
3. Normalize option chain data for analysis
4. Margin check before live order placement
5. Live market feed
Rate Limits
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
Reference Files
Dhan APIs cover execution, quotes, OHLC, option chain, and portfolio. For fundamental data (PE, EPS, revenue), technical indicators (RSI, MACD), or shareholding patterns not available via Dhan, use ScanX — see references/scanx data.md .
Need File
Orders, super orders, forever orders [references/orders.md](references/orders.md)
Holdings, positions, eDIS [references/portfolio.md](references/portfolio.md)
Daily/minute history, quotes, expired options [references/market data.md](references/market data.md)
Option chain usage and normalization [references/option chain.md](references/option chain.md)
Fund limits and margin checks [references/funds.md](references/funds.md)
Live feeds and depth [references/live feed.md](references/live feed.md)
Error handling and subscription troubleshooting [references/error codes.md](references/error codes.md)
Instrument resolution [references/instruments.md](references/instruments.md)
Multi step execution patterns [references/common workflows.md](references/common workflows.md)
Options analytics [references/options analysis patterns.md](references/options analysis patterns.md)
Backtesting patterns [references/backtesting with dhan.md](references/backtesting with dhan.md)
PE ratio, RSI, financials, screeners — data Dhan does not provide [references/scanx data.md](references/scanx data.md)
Data API Subscription Invalid
If the user gets DH 902 or 806 :
1. Log in to web.dhan.co
2. Open My Profile Access DhanHQ APIs
3. Verify that dataPlan is active
4. Activate the Data API plan if needed
5. Generate a fresh access token
6. Re test with ticker data() or ohlc data()
7. If order APIs still fail, check static IP separately