# Dhan(Sandbox)

**What is Dhan SandBox API?**

Dhan SandBox API is a simulated testing environment designed for developers and traders to experiment with Dhan’s trading and market data APIs without needing a live brokerage account or actual capital. It replicates the real trading environment but ensures zero risk by not executing trades on the actual exchange. It is ideal for testing integrations, validating order logic, and experimenting with strategies.

***

**Who Should Integrate Dhan SandBox API with OpenAlgo?**

OpenAlgo is an open-source algo trading automation framework that connects with platforms like TradingView, Amibroker, and custom dashboards. Integrating Dhan’s SandBox API with OpenAlgo is highly recommended for:

* **Algo Developers** building broker connectors.
* **Traders** who want to simulate real-time automated strategies before going live.
* **Educators and Trainers** who want a safe demo environment.
* **Early-stage Fintech Builders** exploring trading APIs.
* **QA and Support Teams** needing to replicate live bugs or behaviors in a controlled setup.

***

**Step-by-Step: How to Get Started with Dhan SandBox API**

Here’s how to register, access tokens, and start testing with OpenAlgo:

#### 1. **Visit DhanHQ DevPortal**

You’ll land on a login screen where you can enter your email or mobile number.

<figure><img src="https://17901342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBwEhITzgv0O0fEGIIRN%2Fuploads%2FIzgdPzoEZpMQ8DMg6F0X%2Fimage.png?alt=media&#x26;token=bece3781-d1fb-4b3b-a50a-36eb8a02d064" alt=""><figcaption></figcaption></figure>

***

#### 2. **Register (if new)**

If you’re a new user, click to register. Provide:

* Email ID
* Mobile Number
* Your Name

Proceed to the next step.

<figure><img src="https://17901342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBwEhITzgv0O0fEGIIRN%2Fuploads%2FaOapZO5BFQ1QR0ucXSBx%2Fimage.png?alt=media&#x26;token=f6c6f317-02d8-4aed-992d-37729646567e" alt=""><figcaption></figcaption></figure>

***

#### 3. **OTP Verification**

You will receive two OTPs:

* One on your **email**
* One on your **mobile**

Enter both to complete verification.

<figure><img src="https://17901342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBwEhITzgv0O0fEGIIRN%2Fuploads%2FjyFu4RGXropouL8ainGS%2Fimage.png?alt=media&#x26;token=d5869073-d12e-4287-acf7-fbe81a2ad75d" alt=""><figcaption></figcaption></figure>

***

#### 4. **Access Your Sandbox Token and Client ID**

Once inside, go to the **Sandbox** tab. You’ll see:

* Application Name (e.g., `openalgo`)
* **Access Token** (JWT for authorization)
* **Client ID** (unique to your application)
* API Playground and documentation links

<figure><img src="https://17901342-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBwEhITzgv0O0fEGIIRN%2Fuploads%2FxSkIpsVEwZZ3t9mhJAOK%2Fimage.png?alt=media&#x26;token=f71ae9c3-57fa-4df2-9557-c5ad6f985062" alt=""><figcaption></figcaption></figure>

These credentials are what you will use inside OpenAlgo’s configuration or `.env` file to test trading orders programmatically.

***

#### Retrieve API Credentials

Once you've successfully logged into the DhanHQ DevPortal and created your sandbox application:

1. **Copy the Client ID**
   * This is your `BROKER_API_KEY`
   * It uniquely identifies your application (e.g., `2505178942`)
2. **Copy the Access Token**
   * This is your `BROKER_API_SECRET`

It acts like a password (JWT format) to authenticate your API requests.

#### Configuration for OpenAlgo

Inside your OpenAlgo project (or any backend using Dhan APIs), create or update the `.env` file with the following keys:

```bash
BROKER_API_KEY = 'your_dhan_sandbox_clientid_here' 
BROKER_API_SECRET = 'your_dhan_sandbox_token_here' 
REDIRECT_URL = 'http://127.0.0.1:5000/dhan_sandbox/callback'
```

**Summary: Why It Matters for OpenAlgo**

Integrating Dhan SandBox with OpenAlgo means:

* Safer testing for order placement, cancellation, and position handling.
* No compliance delay since no KYC is needed.
* Faster debugging and integration turnaround.
* Enables workshops, testing, and community support for algo development.

By setting up your sandbox environment with Dhan and OpenAlgo, you accelerate your readiness for live algorithmic trading while ensuring a risk-free development experience.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.openalgo.in/connect-brokers/brokers/dhan-sandbox.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
