Skip to content

Getting Started

Installation

Add to your Gemfile:

ruby
gem 'DhanHQ'

Or install directly:

bash
gem install DhanHQ

Requires Ruby 3.2 or newer.

Configuration

ruby
DhanHQ.configure do |c|
  c.client_id    = ENV["DHAN_CLIENT_ID"]
  c.access_token = ENV["DHAN_ACCESS_TOKEN"]
end

Authentication

The gem supports multiple authentication strategies:

MethodDescription
Static tokenDirect access_token configuration
PIN + TOTPAuto-generate and renew tokens via enable_auto_token_management!
Environment variablesDHAN_CLIENT_ID + DHAN_ACCESS_TOKEN

For PIN + TOTP auto-renewal:

ruby
DhanHQ.configure do |c|
  c.client_id = ENV["DHAN_CLIENT_ID"]
  c.access_token = ENV["DHAN_ACCESS_TOKEN"] # initial token
end

client = DhanHQ::Client.new
client.enable_auto_token_management!(
  dhan_client_id: ENV["DHAN_CLIENT_ID"],
  pin:            ENV["DHAN_PIN"],
  totp_secret:    ENV["DHAN_TOTP_SECRET"]
)

See the full authentication guide for details.

Community project — not affiliated with Dhan. MIT License.