Logo vun Dhanhq

Dhanhq

Communautéit
dhan-oss
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 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.

Iwwersiicht

Editeurdhan-oss
Repositorydhanhq-skills
Skill-Nummdhanhq
Stären
42
Forks
15
Matgeliwwert Fichieren
27
LizenzMIT
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • 27 matgeliwwert Dateien

    Skripten, Virlagen a Referenzen, déi de Modell beim Schaffe liese kann. D'Dateie kënnen nëmme gelies ginn a ginn ni ausgeféiert.

  • Open Source

    Vum dhan-oss op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Dhanhq an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/dhan-oss/dhanhq-skills/tree/main/skills/dhanhq
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dhan-oss/dhanhq-skills.git /tmp/dhanhq-skills
mkdir -p .claude/skills
cp -r /tmp/dhanhq-skills/skills/dhanhq .claude/skills/dhanhq
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Dhanhq an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Dhanhq automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Dhanhq net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

DhanHQ — Indian Market Trading Skill

Setup

Stable install:

python
pip install dhanhq

Use the current SDK branch when you need newer v2 capabilities such as 200-level depth or the latest helper coverage:

python
pip install --upgrade dhanhq

Minimal initialization:

python
from dhanhq import DhanContext, dhanhq

dhan_context = DhanContext("YOUR_CLIENT_ID", "YOUR_ACCESS_TOKEN")
dhan = dhanhq(dhan_context)

Environment-variable setup:

python
import os
from dhanhq import DhanContext, dhanhq

dhan_context = DhanContext(
    os.environ["DHAN_CLIENT_ID"],
    os.environ["DHAN_ACCESS_TOKEN"],
)
dhan = dhanhq(dhan_context)

If generating scripts for this repo, prefer:

python
from scripts.dhan_helpers import get_client

dhan, dhan_context = get_client()

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

CategoryConstantValue
Exchangedhanhq.NSENSE_EQ
dhanhq.BSEBSE_EQ
dhanhq.NSE_FNONSE_FNO
dhanhq.BSE_FNOBSE_FNO
dhanhq.MCXMCX_COMM
dhanhq.CURNSE_CURRENCY
dhanhq.INDEXIDX_I
Transactiondhanhq.BUYBUY
dhanhq.SELLSELL
Order Typedhanhq.LIMITLIMIT
dhanhq.MARKETMARKET
dhanhq.SLSTOP_LOSS
dhanhq.SLMSTOP_LOSS_MARKET
Productdhanhq.CNCCNC
dhanhq.INTRAINTRADAY
dhanhq.MARGINMARGIN
dhanhq.MTFMTF
Validitydhanhq.DAYDAY
dhanhq.IOCIOC

Current SDK Methods To Prefer

TaskMethod
Place orderdhan.place_order()
Slice large orderdhan.place_slice_order()
Modify orderdhan.modify_order()
Cancel orderdhan.cancel_order()
Order bookdhan.get_order_list()
Order by IDdhan.get_order_by_id()
Order by correlation IDdhan.get_order_by_correlationID()
Trade bookdhan.get_trade_book()
Trade historydhan.get_trade_history()
Ledgerdhan.ledger_report()
Super ordersplace_super_order(), modify_super_order(), cancel_super_order(), get_super_order_list()
Forever ordersplace_forever(), modify_forever(), cancel_forever(), get_forever()
Holdingsdhan.get_holdings()
Positionsdhan.get_positions()
Convert positiondhan.convert_position()
eDISdhan.generate_tpin(), dhan.open_browser_for_tpin(), dhan.edis_inquiry()
Fund limitsdhan.get_fund_limits()
Margin calculatordhan.margin_calculator()
Daily historydhan.historical_daily_data()
Minute historydhan.intraday_minute_data()
Expired options datadhan.expired_options_data()
Market quote snapshotdhan.ticker_data(), dhan.ohlc_data(), dhan.quote_data()
Expiry listdhan.expiry_list()
Option chaindhan.option_chain()
Security masterdhanhq.fetch_security_list()
Live market feedMarketFeed
Live order updatesOrderUpdate
Full market depthFullDepth
Kill switchdhan.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

SegmentAllowed Product Types
NSE_EQ, BSE_EQCNC, INTRADAY, MARGIN, MTF
NSE_FNO, BSE_FNO, MCX_COMM, NSE_CURRENCY, BSE_CURRENCYINTRADAY, 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:

Underlyingsecurity_idUnderlying Segment
NIFTY 5013IDX_I
BANK NIFTY25IDX_I
FINNIFTY27IDX_I
MIDCPNIFTY442IDX_I
SENSEX51IDX_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

python
from dhanhq import DhanLogin

dhan_login = DhanLogin("YOUR_CLIENT_ID")
profile = dhan_login.user_profile("YOUR_ACCESS_TOKEN")

print(profile["dataPlan"])
print(profile["dataValidity"])

2. Fetch historical data with epoch conversion

python
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"]]

3. Normalize option-chain data for analysis

python
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"])

4. Margin check before live order placement

python
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"])

5. Live market feed

python
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())

Rate Limits

API CategoryPer SecondPer MinutePer HourPer Day
Order APIs1025010007000
Data APIs5--100000
Quote APIs1UnlimitedUnlimitedUnlimited
Non-Trading APIs20UnlimitedUnlimitedUnlimited

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.

NeedFile
Orders, super orders, forever ordersreferences/orders.md
Holdings, positions, eDISreferences/portfolio.md
Daily/minute history, quotes, expired optionsreferences/market-data.md
Option-chain usage and normalizationreferences/option-chain.md
Fund limits and margin checksreferences/funds.md
Live feeds and depthreferences/live-feed.md
Error handling and subscription troubleshootingreferences/error-codes.md
Instrument resolutionreferences/instruments.md
Multi-step execution patternsreferences/common-workflows.md
Options analyticsreferences/options-analysis-patterns.md
Backtesting patternsreferences/backtesting-with-dhan.md
PE ratio, RSI, financials, screeners — data Dhan does not providereferences/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

Matgeliwwert Fichieren

De Modell liest dës Dateie bei Bedarf, wärend de Skill gelueden ass. Si ginn als liesbar Dateie bereetgestallt a ginn ni ausgeféiert.

Heefeg gestallte Froen

Wat mécht de KI-Skill 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 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.

Firwat Dhanhq op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Dhanhq besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Dhanhq an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/dhan-oss/dhanhq-skills/tree/main/skills/dhanhq an. TypingMind liest d'Datei SKILL.md, bündelt déi zougehéiereg Dateien an installéiert dat Ganzt als Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Dhanhq benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Dhanhq benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Dhanhq domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Dhanhq gratis?

Jo. De Skill gëtt vum dhan-oss ënner der Lizenz MIT op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇