dhanapi-go

module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT

README

dhanapi-go

Unofficial Dhan v2 SDK for Go. It provides api, instruments, and ws packages. The examples package contains reusable examples for the common flows.

client := api.NewClient(dhanClientID, apiKey, apiSecret)
loginURL, err := client.GenerateLoginURL(ctx)

// After Dhan redirects with tokenId:
session, err := client.GenerateSession(ctx, tokenID)

// Persist session yourself, then restore it when required:
client.SetSession(session)

Instrument master:

err := instruments.CheckAndDownload(ctx, "data/instruments.csv")
items, err := instruments.Load("data/instruments.csv")
matches := instruments.FindInstruments(instruments.Filter{
	Exchange:              "NSE",
	TradingSymbolContains: "NIFTY",
})

Live feed mode is selected once for the client. Reconnects restore active subscriptions automatically.

feed := ws.NewWSClient(clientID, session.AccessToken, ws.ModeQuote)
feed.OnTickData(func(tick ws.TickData) {
	// Consume tick quickly so the feed read loop is not blocked.
})
err := feed.Connect(ctx)
err = feed.Subscribe([]ws.Instrument{{
	ExchangeSegment: "NSE_EQ",
	SecurityID:      "1333",
}})

SetDebug(true) prints complete request and response data, including secrets and access tokens. Enable it only in a safe local environment.

Directories

Path Synopsis
Package examples contains small, reusable examples for the SDK packages.
Package examples contains small, reusable examples for the SDK packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL