Static Ip Dhan cloud is not working

This is my code

from dhanhq import  dhanhq
import time

client_id    = {{CLIENT_ID}}
access_token = {{ACCESS_TOKEN}}

dhan = dhanhq(client_id, access_token)

while True:
    quote = dhan.ticker_data(securities={"NSE_EQ": [1333]})
    print(f"Infosys LTP: {quote}")
    time.sleep(60)
    break

I have taken access key from Dhan developer portal and my client id but it does not work

This errror 2026-06-17 20:15:06 IST] ==================== SCRIPT OUTPUT START ====================

[2026-06-17 20:15:06 IST] Traceback (most recent call last):

[2026-06-17 20:15:06 IST] File “/tmp/script.py”, line 5, in

[2026-06-17 20:15:06 IST] access_token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJkaGFuIiwicGFydG5lcklkIjoiZTkxNWVhbjUiLCJicm9hZGNhc3RfZmxhZyI6dHJ1ZSwiZXhwIjoxNzgxNzkzNzY0LCJ0b2tlbkNvbnN1bWVyVHlwZSI6IlBBUlRORVIiLCJkaGFuQ2xpZW50SWQiOiIxMTAzNjk1NzU1In0.C3patYpkbHGwa_C8U_IAAFwvShk9v33KA80sXqLHivtTnt_sBYzHiNJF9k7HfIHUJ5XMUhHWMqBgeg6tx**›**[2026-06-17 20:15:06 IST] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[2026-06-17 20:15:06 IST] NameError: name ‘eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9’ is not defined

[2026-06-17 20:15:06 IST] ==================== SCRIPT OUTPUT END ====================

[2026-06-17 20:15:06 IST] Execution failed with exit code: 1

**›**Execution completed.

Hi @rahulraj1 ,

The {{CLIENT_ID}} and {{ACCESS_TOKEN}} will be interpreted as variable names rather than strings. Therefore, they should be enclosed in quotes as "{{CLIENT_ID}}" and "{{ACCESS_TOKEN}}" so that they are treated as string values.

Refer this code -

from dhanhq import  dhanhq,DhanContext
import time

client_id    = "{{CLIENT_ID}}"
access_token = "{{ACCESS_TOKEN}}"
dhan_context = DhanContext(client_id, access_token)
dhan = dhanhq(dhan_context)

while True:
    quote = dhan.ticker_data(securities={"NSE_EQ": [1333]})
    print(f"Infosys LTP: {quote}")
    time.sleep(60)
    break

Output -

image

Thanks! This helped with the data fetching part.

I have one more question — when I add dhan.place_order() to my algo code in Dhan Cloud, I get a HIGH security violation and it does not allow me to save. The error says “The code attempts to place orders through the Dhan API which could lead to financial transactions.”

How do I structure order placement code in Dhan Cloud to pass the security scanner? I have seen a video where orders are placed from Dhan Cloud so I know it is possible.

Hi @Jayachandran_S ,

Dhan Cloud scanner blocks direct order API calls like dhan.place_order() inside algo code because it can execute financial transactions.

So keep Dhan Cloud code only for signal generation, and place the actual order through Dhan Cloud’s approved order/execution mechanism .

Refer the code -

from dhanhq import  dhanhq,DhanContext
import time

client_id    = "{{CLIENT_ID}}"
access_token = "{{ACCESS_TOKEN}}"
dhan_context = DhanContext(client_id, access_token)
dhan = dhanhq(dhan_context)
order = {
    "security_id": "11915",          
    "exchange_segment": dhanhq.NSE,
    "action": dhanhq.BUY,
    "quantity": 1,
    "order_type": dhanhq.LIMIT,
    "product_type": dhanhq.INTRA,      
    "price": 27.50,                  
}


def execute_order(order):
    return dhan.place_order(
        security_id=order["security_id"],
        exchange_segment=order["exchange_segment"],
        transaction_type=order["action"],
        quantity=order["quantity"],
        order_type=order["order_type"],
        product_type=order["product_type"],
        price=order["price"],
        validity="DAY",
    )


placed_order = execute_order(order)

print(placed_order)

Output -

Thank you for the response. I have one more question on architecture.

My algo has two parts — a scanner that fetches historical data for 499 NSE symbols, computes signals and fetches current holdings to apply position caps, and an order executor that places CNC equity orders for the signals found.

When I put both parts in one script, the scanner gives HIGH security violation and blocks saving. It flags both the historical data fetch and the order placement together.

Do you run signal generation and order execution as two separate Dhan Cloud scripts? If yes, how does the order script know which symbols to buy — do you update the Variables Tab manually between runs or is there another way? Is there a Dhan Cloud approved template for a production EOD equity scanner with order placement?

I have a static IP already whitelisted. The strategy is simple with a few entry conditions and one exit condition. The infrastructure around it is what the scanner is flagging.

Hi @Jayachandran_S ,

A separate file would be required for the scanner and another separate file for the order executor.

Thank you — that makes sense. One follow-up: how do the two scripts share data? Can the scanner script write a result (e.g. list of buy signals with price and quantity) to a Variable that the order executor script then reads? Or is there another recommended way to pass signals from one script to the other?

Introduction to Algo Trading for Beginners! (Complete Algo Series Part 1)

sir is series kae liye installation file kahan se mile gi mujhe mil nahi rahi please link dijie

Since SEBI has implemented automated static IP whitelisting requirements, running trading algorithms on cloud servers has become operationally difficult for individual traders.

My current challenge is that if I deploy my Python-based trading algorithm on a cloud server/VPS, I need to regularly generate access tokens and update them on the cloud environment. This creates additional complexity and maintenance overhead.

Is there any compliant solution that allows me to run my Python trading algorithm directly from my local desktop or laptop while still satisfying the static IP whitelisting requirements?

Specifically, I would like to know:

  1. Can a residential broadband connection with a static IP be used for API trading and IP whitelisting?

  2. Is there any way to expose a locally running algorithm through a fixed public IP without deploying the strategy to a cloud server?

  3. Can technologies such as VPNs, reverse tunnels, SD-WAN, or static-IP proxy services be used in a SEBI-compliant manner?

  4. Are there any recommended architectures that allow local execution of the algorithm while maintaining a single whitelisted static IP?

  5. How are other retail algo traders handling this issue after the implementation of automated static IP whitelisting?

My objective is to keep the strategy running on my personal desktop/laptop while avoiding the operational burden of managing cloud deployments and frequent token updates.

Hi @HASAN_khan ,

Refer this link -

Hi @ROCKY2 ,

Using the PIN + TOTP login method, tokens do not need to be generated or updated manually every day. This applies whether the system is running on a local desktop/laptop, cloud server, or VPS. The system can automatically generate/update the token when it starts.

  1. Residential or office broadband static IP can be used if the IP is fixed public static IP and the broker accepts it for whitelisting.

  2. A locally running algorithm can work through a fixed public IP as long as all broker API requests go through the approved static IP.

  3. VPN, reverse tunnel, SD-WAN, or static-IP proxy can be used only if the broker allows it and the outgoing IP is a dedicated static IP mapped to the client/API key. Shared VPN/proxy IPs should be avoided.

  4. The recommended approach is to ensure that all API requests originate from one approved whitelisted static IP, whether the algo runs on a server, on cloud, or locally.

  5. Most retail algo traders use cloud servers or VPS with static IPs for reliability and 24/7 operation. Others use residential or office broadband connections with a fixed public static IP, or broker-approved static IP solutions, depending on what their broker supports.

To install the required libraries, run these commands in CMD terminal:

pip install dhanhq==2.2.0
pip install Dhan-Tradehull==3.3.1

Refer to this code for automatic login:

from Dhan_Tradehull import Tradehull

client_code = ""
tsl = Tradehull(client_code, mode="pin_totp", pin="", totp_secret="")

The strategy can run on a server, on cloud, or locally. The important point is that all API requests must come from the whitelisted static IP, and token generation can be automated using PIN + TOTP.

2 Likes

Thank you — that makes sense. One follow-up: how do the two scripts share data? Can the scanner script write a result (e.g. list of buy signals with price and quantity) to a Variable that the order executor script then reads? Or is there another recommended way to pass signals from one script to the other?
Could you please give your thoughts for this? appreciate your help

Hi @Jayachandran_S

Here we need a method using which we can pass information between 2 codes.
A way to do this is using supabase

Scanner script can send data to supabase.
and order executed can read from it

Example code below for sender

import requests

url = "https://YOUR_PROJECT.supabase.co/rest/v1/your_table"
headers = {
    "apikey": "YOUR_ANON_KEY",
    "Authorization": "Bearer YOUR_ANON_KEY",
    "Content-Type": "application/json"
}
data = {"symbol": "RELIANCE", "price": 2890.5, "oi": 152300}

requests.post(url, headers=headers, json=data)

Example code below for receiver

import requests

url = "https://YOUR_PROJECT.supabase.co/rest/v1/your_table?select=*&order=id.desc&limit=1"
headers = {"apikey": "YOUR_ANON_KEY", "Authorization": "Bearer YOUR_ANON_KEY"}

resp = requests.get(url, headers=headers).json()
print(resp)

Thanks sir for link

Sri first session me kuch code kam nahi kar rahe to kya koin new updated code he kya

Hi @HASAN_khan ,

Could you provide more details about the error or share a screenshot of it?

Hi Imran Sir,

Sir i am running below code in Dhan Cloud and getting below error, can help me

[2026-07-03 18:20:29 IST] :chart_increasing: Buy signal generated for 360ONE›[2026-07-03 18:20:29 IST] :white_check_mark: BUY Super Order executed for ID 13061. Response: {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-906’, ‘error_type’: ‘Order_Error’, ‘error_message’: ‘Market is Closed! You cannot place this order now.’}, ‘data’: {‘errorType’: ‘Order_Error’, ‘errorCode’: ‘DH-906’, ‘errorMessage’: ‘Market is Closed! You cannot place this order now.’}}

HI @Venkata_Narasimha_Ra ,

The order cannot be placed because the market is closed. Order placement is only supported during market hours, so try executing the code when the market is open.

Hi Sir,

In market time also having same errro

[2026-07-06 13:10:47 IST] :chart_increasing: Buy signal generated for ABB

[2026-07-06 13:10:47 IST] :white_check_mark: BUY Super Order executed for ID 1247. Response: {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-906’, ‘error_type’: ‘Order_Error’, ‘error_message’: ‘Transactions Fails.’}, ‘data’: {‘errorType’: ‘Order_Error’, ‘errorCode’: ‘DH-906’, ‘errorMessage’: ‘Transactions Fails.’}}

Hi @Venkata_Narasimha_Ra ,

Check whether the payload parameters are correct and ensure that Super Order placement has been activated. If the issue still persists, share the code so that it can be verified.