Skip to content

Dhan Context

A module that has a class encapsulating connection context and connection mediums to Dhan APIs.

This library provides methods to manage orders, retrieve market data, and perform various trading operations through the DhanHQ API.

:copyright: (c) 2025 by Dhan. :license: see LICENSE for details.

dhanhq.dhan_context

A module that has a class encapsulating connection context and connection mediums to Dhan APIs.

This library provides methods to manage orders, retrieve market data, and perform various trading operations through the DhanHQ API.

:copyright: (c) 2025 by Dhan. :license: see LICENSE for details.

Classes

DhanContext

DhanContext(client_id, access_token, disable_ssl=False, pool=None)

A class that encapsulates connection context to Dhan APIs like client-id, access-tocken, base-url and passes this to all the connection protocols like http and websocket that it is composed of.

Functions
get_access_token
get_access_token()

Return authorization token that is used for connecting to Dhan API Returns access_token that is used for authorization in accessing Dhan API

get_client_id
get_client_id()

Return client's id that is used to identify the client interacting with Dhan API Returns client_id that is used to identify the client interacting with Dhan API

get_dhan_http
get_dhan_http()

Return HTTP Connection Request object that has all necessary context to connect to Dhan API

Returns http_connection_request (DhanHTTP): DhanContext enabled HTTP Connection Request object