Python Library
Place and manage orders from your own Python code, on any supported broker, with one set of functions.
The Python library lets your own code place and manage orders through AutoTrader Web. It talks to the platform directly over a secure web connection. Install it with pip, add your API key, and the same code works on any supported broker.
What it is
The Python library is a broker independent trading client for Indian stock exchanges. You write your strategy once in Python and run it against any broker that AutoTrader Web supports. The same function calls work everywhere, so changing broker does not mean rewriting your code.
It is a good fit if you already build in Python, want full control over your logic, or run your strategy on a server.
How it connects
Python is a direct client. Your code calls AutoTrader Web over a secure web connection, and AutoTrader Web passes each instruction on to your broker. Nothing extra needs to run on your computer.
Your code talks to the platform over the web. There is nothing to install on your machine beyond the library itself.
Before you begin
Have these ready first:
- Python 3.6 or higher, installed and available on your command line.
- An AutoTrader Web account. Your strategy runs through it.
- An API key. Generate it in your account settings, then keep it private.
- At least one broker account added, so your orders have somewhere to go.
Install
Install the library with pip. The first command installs it. The second upgrades an existing install to the latest version.
# Install
python -m pip install AutoTrader-Web-API-Stocks-Developer
# Upgrade to the latest version
python -m pip install --upgrade AutoTrader-Web-API-Stocks-Developer
You can also download it manually from the package index, but pip is easier because it also pulls the one dependency (requests) for you.
The current version is 1.4.0. Both commands above give you the newest release, so you do not need to write a version number. To check what you have:
python -m pip show AutoTrader-Web-API-Stocks-Developer
If it is older than 1.4.0, run the upgrade command — the AutoTrader bracket and cover order calls need 1.4.0 or newer.
Initialize
Create one AutoTrader instance and share it across your application. Pass your API key, which you can find in your account settings.
from com.dakshata.autotrader.api.AutoTrader import AutoTrader
autotrader = AutoTrader.create_instance('<your-api-key>', AutoTrader.SERVER_URL)
A minimal working example
This places one limit order, then prints the platform response. Replace the placeholder values with your own account and instrument.
from com.dakshata.autotrader.api.AutoTrader import AutoTrader
autotrader = AutoTrader.create_instance('<your-api-key>', AutoTrader.SERVER_URL)
# Place a regular limit order
response = autotrader.place_regular_order(
'ABC123', # your account
'<exchange>', # your exchange segment code
'SBIN', # trading symbol
'BUY', 'LIMIT', 'INTRADAY',
1, 330.35, 0.0)
print(response)
The same instance also handles bracket and cover orders, modify, cancel, square-off, and reading orders, positions and margins. Each function is documented with examples in the API reference.
Write the code with AI
You can have an AI coding assistant (ChatGPT, Claude, Gemini or Copilot) write your Python code for you. Many programmers now start this way, and it is much faster than a blank page. It only works well if the AI reads our documentation first. Without it, the AI guesses function names that look right and then fail.
- Give it our Python file first: stocksdeveloper.in/ai/trading-api/python.txt. It has every API call with Python examples, and nothing from other languages to mix up. If your tool cannot open links, open the file yourself, save it, and attach it to the chat.
- Then send a prompt like this one. Replace the parts in CAPITALS.
Read this file first: https://stocksdeveloper.in/ai/trading-api/python.txt
It is the official reference for the AutoTrader Web Python library.
Use only the functions, parameters and values it defines.
Write a Python program that DESCRIBE WHAT YOU WANT IT TO DO HERE.
My account nickname is MY_ACCOUNT. Read the API key from an
environment variable, never from the code.
Then check your code line by line against the reference, and list
anything you were not sure about instead of guessing it.
- Test it before real money. Run it once with the smallest quantity, in one account only.
Never paste your API key into an AI chat. Ask the AI to read it from an environment variable instead, as the prompt above does. Anyone who has your key can place orders in your accounts.
Build with AI has more prompts, the mistakes these tools make, and what to check before you trade with the result.
Frequently asked questions
Why do I get HTTP 401 (Unauthorized) when calling the API from my Python code?▾
A 401 means the Stocks Developer API key in your code is wrong or missing. It is not a licence or broker problem, and a recharge or an active account does not change it. Open Settings -> Security in AutoTrader Web, copy your exact API key, and pass that same key when you create the AutoTrader instance. If it still fails with the correct key, your user may have been disabled — contact support to re-enable it. Breaching the API rate limits does not disable your user; that only returns a 429 Too Many Requests error.
Next steps
Thanks for the feedback. Still stuck? Contact support.
Last updated 8 October 2026