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
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.
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.
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?
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:
Can a residential broadband connection with a static IP be used for API trading and IP whitelisting?
Is there any way to expose a locally running algorithm through a fixed public IP without deploying the strategy to a cloud server?
Can technologies such as VPNs, reverse tunnels, SD-WAN, or static-IP proxy services be used in a SEBI-compliant manner?
Are there any recommended architectures that allow local execution of the algorithm while maintaining a single whitelisted static IP?
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.
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.
Residential or office broadband static IP can be used if the IP is fixed public static IP and the broker accepts it for whitelisting.
A locally running algorithm can work through a fixed public IP as long as all broker API requests go through the approved static IP.
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.
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.
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:
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.
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
Sir i am running below code in Dhan Cloud and getting below error, can help me
[2026-07-03 18:20:29 IST] Buy signal generated for 360ONE›[2026-07-03 18:20:29 IST] 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.’}}
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.
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.