An API sounds technical, but the idea is simple. Your broker's app is one program that talks to the broker's systems; an API lets other programs talk to them too, under rules the broker sets. Those rules decide what a program can see, what it can do, how fast it can do it and how it proves it is acting for you. Since 1 April 2026, SEBI's framework for retail algorithmic trading has added rules of its own: a registered static IP, a daily sign-in with two factors and a limit on how fast an unregistered algo may send orders. This guide covers the parts of an API, follows one order from signal to fill, works through the order-rate arithmetic and sets out the choice between writing your own code and using a platform.
What a trading API does
An application programming interface (API) is a set of rules for one program to talk to another. A broker's trading API lets a program:
- sign in to your account with your permission,
- read your funds, margin, holdings, positions and orders,
- receive market prices,
- place, modify and cancel orders, and
- receive confirmation when an order fills.
The program can be a platform such as QuantPower, a spreadsheet, or code you write yourself. The broker's systems apply the same risk checks to API orders as to orders from its app.
The parts of a trading API
| Part | What it does | Technology |
|---|---|---|
| Authentication | Confirms who you are and issues a session token | A sign-in with two factors, often through the broker's own page |
| REST endpoints | Request and response calls: get positions, place an order | HTTPS requests returning JSON |
| Streaming feed | A continuous stream of prices and order updates | A WebSocket connection that pushes data |
| Postbacks | The broker notifies your program when an order status changes | HTTPS calls to a URL you register, or messages on the stream |
| Historical data | Past candles for charts and backtests | REST, usually with limits on how much and how often |
| Instrument list | Every tradable contract with its code, lot size, tick size and expiry | A file downloaded daily |
A short history of trading APIs
Electronic trading began inside institutions. Exchanges and large brokers built their own links in the 1970s and 1980s, and in 1992 a group of firms created the FIX protocol, a common message format for orders that institutions still use.1 For individual traders, the building blocks came from the web: Roy Fielding's 2000 description of REST shaped how most web APIs answer requests,2 the WebSocket standard of 2011 made it easy to stream prices to a program,3 and OAuth 2.0, published in 2012, became the usual way for one application to act for a user without seeing their password.4
In India, brokers began offering retail trading APIs in the mid-2010s, and a generation of traders learned to automate with a few hundred lines of code. Platforms followed, built on the same APIs. SEBI's 2012 guidelines on algorithmic trading had set rules for exchanges and brokers,5 but retail API use grew faster than the rules written for it. SEBI's circular of 4 February 2025 on safer participation of retail investors in algorithmic trading closed the gap: brokers became responsible for every algo order through them, API access was tied to a registered static IP, and algos above an order-rate threshold had to be registered with the exchange.6 NSE's implementation standards of 5 May 2025 set out the details, and the framework applies to every broker from 1 April 2026.7
Authentication and the daily sign-in
Broker APIs use a sign-in in which you prove who you are with a password and a second factor. There are three common patterns:
| Pattern | How it works | You see |
|---|---|---|
| Redirect sign-in | The program sends you to the broker's own page; you sign in there and the broker returns a token to the program | The broker's page, then back to the program |
| API key and secret | You create a key and secret in the broker's API console; the program uses them, with a code you enter, to start the day's session | A code prompt each day |
| Token paste | You generate a token in the broker's console and paste it into the program | A new token when the old one ends |
In each case, the program never needs your broker password if the broker supports redirect sign-in, and every session ends before the next trading day under SEBI's framework. Tokens are the keys to your account for the day: a program that stores them must protect them, and you should revoke a program's access in your broker's settings if you stop using it.
Market data
APIs provide two kinds of price data:
- Quotes on request: the latest price, depth and open interest for an instrument, fetched when the program asks.
- Streaming ticks: every price change pushed over a WebSocket, for many instruments at once.
Brokers differ on what they include. Some bundle live data with API access, others charge for it, and historical candles for backtesting may be a separate product with limits on how far back and how often you can ask. A strategy that needs live prices for many option strikes should check the broker's limits on subscriptions per connection before relying on them.
The instrument list
Every API has a list of tradable contracts, downloaded daily, with each contract's code, lot size, tick size, strike and expiry. It is easy to forget and essential to keep current. Weekly options add new contracts every week, lot sizes change, and a program working from last month's list will place orders for contracts that no longer exist or in quantities that are no longer valid.
Orders through an API
An API order carries the same fields as an order in the app:
| Field | Example | Note |
|---|---|---|
| Instrument | Nifty 25,000 call, current weekly expiry | From the instrument list |
| Exchange | NFO | The F&O segment of NSE |
| Side | Sell | |
| Quantity | 65 | Units, a multiple of the lot size |
| Order type | Limit | Market, limit, stop-limit or stop-market |
| Price | ₹92.50 | For limit and stop-limit orders |
| Trigger price | For stop orders | |
| Product | Intraday | Or delivery or carry forward, by segment |
| Validity | Day | Day, IOC or GTD |
The broker returns an order ID, and the order's status changes through open, complete, cancelled or rejected. Our guide to order types explains the choices.
Three things differ from manual trading:
- Speed. A program can place an order within milliseconds of a signal, and many in a second. SEBI's framework sets a threshold of 10 orders a second, above which an algo must be registered with the exchange.
- Errors are silent. A rejected order does not pop up on screen. The program must read the response and decide what to do, for example closing a filled hedge leg if the other leg was rejected.
- No confirmation step. There is no "are you sure" dialog. A bug places real orders.
Following one order
Here is what happens when a program sells one lot of a Nifty call:
- The program checks its own rules and builds the order.
- It sends the order over HTTPS, with the session token.
- The broker checks the session, the static IP, the instrument, the quantity and the margin.
- The broker sends the order to the exchange and returns an order ID.
- The exchange matches it, or places it in the book at its price.
- The broker sends status updates: open, then complete, or rejected with a reason.
- The program records the fill and places or arms the stop loss.
Each step can fail. A lost network answer at step 4 is the dangerous one: the order may or may not have reached the exchange. A careful program does not resend blindly; it asks the broker for the order's status first, so that one signal never becomes two orders.
Partial fills, modifications and cancellations
Real orders do not always fill in one piece. An order for 10 lots may fill 4 lots at once and the rest over several seconds, or not at all. A program has to decide, for each strategy, what a partial fill means:
- Wait. Leave the rest of the order in the book at its price, and arm the stop for the quantity filled so far.
- Chase. Modify the price towards the market. Each modification sends the order to the back of the queue at its new price and counts towards the rate limit.
- Cancel the rest. Keep what filled, cancel the remainder and size the stop to match.
Modifying and cancelling are API calls of their own, and each can fail or arrive after the order has already filled. A program should always read the latest status before deciding, and treat "cancel requested" and "cancelled" as different states.
Reading an API error
Every broker words its errors differently, but they fall into a few groups:
| What the error says, roughly | What it usually means | What a program should do |
|---|---|---|
| Session expired or invalid token | The day's session has ended | Stop sending orders; ask the user to sign in again |
| IP not allowed | The order came from an unregistered address | Stop; never retry from another address |
| Insufficient margin | Not enough free margin for this order | Do not retry; reduce size or stop the strategy |
| Invalid quantity | Not a multiple of the lot size, or above the freeze quantity | Fix the quantity from the instrument list; split large orders |
| Price outside the band | A limit price beyond the exchange's allowed range | Reprice inside the band shown by the broker |
| Too many requests | The rate limit was hit | Wait, then send the remaining orders at a slower pace |
| Instrument not found | An expired or wrong contract code | Reload the instrument list |
The rule of thumb: retry only errors that are about timing, such as a rate limit or a brief network failure, and never retry errors that are about the order itself. Log every error with its time and order details; patterns in the log often point to a fix.
Testing an API program safely
Code that places real orders deserves more testing than code that only reads data:
- Read-only first. Run the program for a few days with order placement switched off, logging the orders it would have sent.
- Simulated orders. Route orders to a simulated account that fills at live prices, and compare its record with your own log.
- Failure drills. Disconnect the network, expire the token, send a bad quantity on purpose, and watch what the program does.
- One lot live. Start with the smallest size, during a quiet hour, with an account-level loss limit set at the broker or platform.
- Kill switch. Know how to stop everything in one action, at the broker and in your own program, before you need to.
Choosing a broker for API trading
If you plan to trade through an API, the broker's API is as important as its brokerage. Questions to ask:
- Does it offer redirect sign-in, or do you have to handle keys and codes yourself every day?
- How many static IPs can you register, and how often can you change them?
- Are live prices included with API access, and how many instruments can you stream at once?
- How much historical data can you download, and at what rate?
- What are its own order-rate limits, and are they lower than the exchange's threshold?
- How quickly does it publish notices of API changes, and how long do old versions keep working?
- What does it charge, and does the charge depend on the plan you choose?
A broker with a well-documented, stable API saves more time than one with slightly lower charges. Read its developer forum as well as its documentation: the questions other traders ask show where the API's rough edges are.
What the SEBI framework requires
SEBI's rules on retail algorithmic trading, in force for all brokers since 1 April 2026, apply to API trading:6 7
- A static IP. API orders must come from a static IP address registered with the broker. Brokers usually let you register a primary and a secondary address and limit how often you can change them. Our guide to static IP for algo trading covers the ways to get one and what they cost, and how to whitelist a static IP has the steps at each broker.
- An order-rate threshold. Algos that send more than 10 orders a second must be registered with the exchange through the broker and carry an identifier on their orders.
- Two-factor sign-in. API access uses a sign-in with two factors, and sessions end daily.
- Broker responsibility. The broker is responsible for algo orders through its systems and keeps an audit trail of them.
- No return claims. Brokers may not refer to the past or expected returns of an algo.
Our guide to SEBI rules for option trading covers the framework in full.
How brokers charge for API access
Brokers charge in different ways, and terms change often, so check your broker's current page before choosing:
| Model | What it means |
|---|---|
| Free API | Orders and account data at no charge; live data may or may not be included |
| Paid API | A monthly fee per API key or per account |
| Separate data fee | Orders are free, but live or historical prices cost extra |
| Included with a plan | API access comes with a particular brokerage plan |
When you trade through a platform such as QuantPower, prices come from your connected broker account, so a broker that charges for data charges you whether you code or not. See broker connection requirements for what each connection needs.
Order-rate arithmetic
The 10-orders-a-second threshold sounds generous until you count orders on a busy day. Take a trader running 20 option algos, each with up to 6 legs, all set to exit at 3:10 pm.
| Item | Working | Result |
|---|---|---|
| Exit orders at 3:10 pm | 20 algos × 6 legs | 120 orders |
| Time at 10 orders a second | 120 ÷ 10 | 12 seconds |
| Orders in that minute | 120 | Within a 250-a-minute limit |
| If each exit is modified once | 240 orders | Close to a 250-a-minute limit |
A program that ignores the rate will be refused by the broker partway through, leaving some legs open. A platform spaces the orders itself; your own code has to. The practical lessons: stagger exit times by a minute or two across strategies, avoid modifying orders more than you need, and test what your code does when the broker says "too many requests".
Using an API directly vs through a platform
| Your own code | A platform such as QuantPower | |
|---|---|---|
| Skills needed | Programming, server upkeep, error handling | The strategy rules |
| Static IP | You register and maintain one for your server | 2 static IPs free with every account |
| Reliability | Your server, your internet, your monitoring | The platform's error handling; nothing to keep switched on |
| Flexibility | Anything the API allows | The platform's builder, signals, formulas and webhooks |
| Cost | Server, data, your time | Tokens: 200 per live algo per 28 days |
| Order rate | You enforce the limits | Capped at 10 a second and 250 a minute per broker connection, lower where the broker's limit is lower |
Writing to an API directly suits traders who need logic a builder cannot express, or who want to integrate their own data. Our guide to python for algo trading shows the first steps. For most rule-based strategies, a platform is faster to set up and easier to run every day.
What different strategies need from an API
Not every strategy uses an API the same way:
| Strategy | What it needs most | Watch out for |
|---|---|---|
| Option selling at a fixed time | Reliable order placement at one moment; correct strikes from the instrument list | Many legs at once; rate limits at entry and exit |
| Indicator rules on futures | Clean candles from the stream; reading conditions on closed candles | Gaps in the feed; reconnecting without missing a candle |
| Scalping | Fast quotes, fast order updates, low latency | Modifications counting towards rate limits; spread costs |
| Positional strategies | Correct overnight positions and holdings; GTT or stop orders that persist | Sessions ending overnight; physical settlement of stock options |
| Portfolio and SIP buying | Holdings, funds and scheduled orders | Holidays and due dates; partial fills on less liquid stocks |
The same API serves all of them, but a program built for one is rarely ready for another without changes.
Market hours and the clock
Every API program needs an accurate clock and a market calendar. NSE and BSE cash and F&O, commodity and currency segments each have their own hours and holidays, F&O trading runs until 3:40 pm since 3 August 2026, and expiry days fall on fixed weekdays that move when a holiday intervenes. A program that schedules entries by its own computer's clock, without a holiday list, will try to trade on days the market is closed or miss the right expiry. Keep the clock synchronised and load the exchange's holiday list each year.
APIs and webhooks
An API is a door you knock on: your program asks, and the broker answers. A webhook is a door that knocks on you: another system calls a URL you gave it when something happens. Charting tools use webhooks to send alerts to platforms, and platforms use them to let your own code start and stop strategies. Our guide to api vs webhook explains when to use each, with chart alerts as the example.
A minimal trading loop
Whether in code or in a platform, every automated strategy runs the same loop:
- Sign in and confirm the session.
- Subscribe to prices for the instruments the strategy needs.
- On each new candle, evaluate the entry rules.
- If a rule triggers, check margin, then place the order and read the response.
- Arm the stop loss and target as soon as the entry fills.
- Track order status and positions; handle rejections and partial fills.
- Exit on the stop, the target or the time rule.
- Log every order and every decision for review.
Steps 4 to 6 are where most errors occur, and where a platform's built-in handling saves the most effort.
Common mistakes
- Resending an order after a timeout without checking whether the first one went through. It is the most common cause of duplicate positions.
- Placing the short leg first in a spread. If the hedge is then rejected, the position is naked.
- Working from an old instrument list. Expired contracts and old lot sizes cause rejections.
- Treating "no answer" as "no position". A broker that does not answer has not said you are flat.
- Logging tokens and secrets in plain text files or screenshots.
- Running on a laptop that sleeps, changes network or loses its static IP.
- Ignoring rate limits until the busiest minute of the day.
Where trading APIs are going
Three trends are shaping them. Sign-in is moving to redirect flows where the program never sees your password, which is safer for everyone. The static IP requirement ties orders to known machines, which favours platforms and servers over home computers. And AI apps are starting to use trading APIs through narrow, revocable permissions: the safe pattern lets an AI read an account and prepare an order, while only the account holder can confirm it. Each change makes APIs safer to use and a little more demanding to use well. For traders, the practical effect is that the hard parts of API trading, sessions, static IPs, rate limits and records, are increasingly handled once by a platform or a broker rather than separately by every individual program, while the rules about what may be automated and how fast are written down more clearly than before.
How QuantPower uses broker APIs
QuantPower connects to your broker through its official API: one connection type for the many brokers on the XTS trading system, and direct connections for Zerodha, Upstox, Fyers, Dhan, Angel One and Shoonya.8
| Job | How QuantPower handles it |
|---|---|
| Sign-in | Redirect sign-in for Zerodha, Upstox and Fyers; saved keys with "Log in again" for XTS brokers; the broker's own daily step for the others |
| Keys | Sent once, stored encrypted, never shown again |
| Static IP | 2 free per account, a primary and a backup; orders leave through a proxy that uses them, and are held, never rerouted, if it is down |
| Prices | From your connected broker, turned into candles; the feed shows live, delayed, stale or closed |
| Orders | One order path for manual orders, baskets, GTT, SIP, algos and signals, with risk checks first |
| Duplicates | Every order carries an idempotency key; if an answer is lost, the app asks the server by that key before saying anything, and never retries on its own |
| Rate | 10 a second and 250 a minute per broker connection, lower where the broker's own limit is lower |
| Your own code | Webhooks: up to 20 private URLs, each linked to up to 10 of your algos, to switch them on and enter, or stop and square off |
| Your AI app | Connect AI: one MCP server with scoped, revocable permissions; an AI app can read, backtest and save algos switched off, and can only prepare an order for you to confirm |
Start with 500 free tokens
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Frequently asked questions
Do I need to know programming to use a trading API?
To call the API yourself, yes. To use it through a platform, no: the platform's software talks to the API on your behalf, and you set rules in its screens.
Is API trading legal in India?
Yes, through a SEBI-registered broker that offers API access under SEBI's framework for retail algo trading.
Can a trading API withdraw money from my account?
No. Broker APIs do not offer withdrawals. Money leaves a trading account only to your registered bank account on your instruction to the broker.
What is the 10-orders-a-second rule?
Under SEBI's framework, an algo that sends more than 10 orders a second must be registered with the exchange through your broker and carry an identifier on its orders. Below that threshold, your own algo can run without registration, from your registered static IP.
Why do I need a static IP for API trading?
So that your broker accepts API orders only from known machines. Under SEBI's framework, every API order must come from a static IP registered with your broker; an order from any other address is refused.
What should a program do if it gets no answer after placing an order?
Ask the broker for the order's status before doing anything else. Resending without checking can create a second order. A careful platform tags each order with a unique key so that a retry can never place it twice.
Can I use a broker's API and a platform at the same time?
Yes, on the same broker account, but keep them apart. Do not let your own code and a platform's strategy trade the same contracts, because each will see positions it did not expect. If both run, set one account-level loss limit that covers everything, and check that your broker's limits on sessions and static IPs allow both connections.
Related guides
- API vs webhook: how alerts reach a platform
- Upstox API for algo trading: one broker's connection, step by step
- Static IP for algo trading: the rules, the options and the prices
- Whitelist a static IP with your broker: the steps at each broker
- Free static IP for algo trading: what free cloud tiers really give
References
- FIX Trading Community, "History of FIX" (fixtrading.org)
- Roy T. Fielding, *Architectural Styles and the Design of Network-based Software Architectures*, doctoral dissertation, University of California, Irvine, 2000
- IETF, RFC 6455: The WebSocket Protocol, December 2011 (rfc-editor.org)
- IETF, RFC 6749: The OAuth 2.0 Authorization Framework, October 2012 (rfc-editor.org)
- SEBI, broad guidelines on algorithmic trading, 30 March 2012 (sebi.gov.in)
- SEBI, circular on safer participation of retail investors in algorithmic trading, 4 February 2025, in force for every broker from 1 April 2026 (sebi.gov.in)
- NSE, implementation standards for retail algo trading, 5 May 2025 (nseindia.com)
- QuantPower: broker connections, sign-in, static IPs, order path, rate caps, webhooks and Connect AI, from the app's code, checked 12 November 2026