Register
Learn guide

Understand How Trading APIs Work

A trading API is the interface a broker provides so that software can read your account and place orders without a person clicking in an app. Every algo platform in India, including QuantPower, works through broker APIs. This guide explains what a trading API does, how authentication, market data and orders work, what the SEBI framework requires, how brokers charge for access and when it makes sense to use an API directly rather than through a platform.

QuantPower Research · Updated 16 Nov 2026 · 18 min read

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

PartWhat it doesTechnology
AuthenticationConfirms who you are and issues a session tokenA sign-in with two factors, often through the broker's own page
REST endpointsRequest and response calls: get positions, place an orderHTTPS requests returning JSON
Streaming feedA continuous stream of prices and order updatesA WebSocket connection that pushes data
PostbacksThe broker notifies your program when an order status changesHTTPS calls to a URL you register, or messages on the stream
Historical dataPast candles for charts and backtestsREST, usually with limits on how much and how often
Instrument listEvery tradable contract with its code, lot size, tick size and expiryA 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:

PatternHow it worksYou see
Redirect sign-inThe program sends you to the broker's own page; you sign in there and the broker returns a token to the programThe broker's page, then back to the program
API key and secretYou 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 sessionA code prompt each day
Token pasteYou generate a token in the broker's console and paste it into the programA 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:

FieldExampleNote
InstrumentNifty 25,000 call, current weekly expiryFrom the instrument list
ExchangeNFOThe F&O segment of NSE
SideSell
Quantity65Units, a multiple of the lot size
Order typeLimitMarket, limit, stop-limit or stop-market
Price₹92.50For limit and stop-limit orders
Trigger priceFor stop orders
ProductIntradayOr delivery or carry forward, by segment
ValidityDayDay, 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:

  1. The program checks its own rules and builds the order.
  2. It sends the order over HTTPS, with the session token.
  3. The broker checks the session, the static IP, the instrument, the quantity and the margin.
  4. The broker sends the order to the exchange and returns an order ID.
  5. The exchange matches it, or places it in the book at its price.
  6. The broker sends status updates: open, then complete, or rejected with a reason.
  7. 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, roughlyWhat it usually meansWhat a program should do
Session expired or invalid tokenThe day's session has endedStop sending orders; ask the user to sign in again
IP not allowedThe order came from an unregistered addressStop; never retry from another address
Insufficient marginNot enough free margin for this orderDo not retry; reduce size or stop the strategy
Invalid quantityNot a multiple of the lot size, or above the freeze quantityFix the quantity from the instrument list; split large orders
Price outside the bandA limit price beyond the exchange's allowed rangeReprice inside the band shown by the broker
Too many requestsThe rate limit was hitWait, then send the remaining orders at a slower pace
Instrument not foundAn expired or wrong contract codeReload 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:

  1. Read-only first. Run the program for a few days with order placement switched off, logging the orders it would have sent.
  2. Simulated orders. Route orders to a simulated account that fills at live prices, and compare its record with your own log.
  3. Failure drills. Disconnect the network, expire the token, send a bad quantity on purpose, and watch what the program does.
  4. One lot live. Start with the smallest size, during a quiet hour, with an account-level loss limit set at the broker or platform.
  5. 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:

ModelWhat it means
Free APIOrders and account data at no charge; live data may or may not be included
Paid APIA monthly fee per API key or per account
Separate data feeOrders are free, but live or historical prices cost extra
Included with a planAPI 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.

ItemWorkingResult
Exit orders at 3:10 pm20 algos × 6 legs120 orders
Time at 10 orders a second120 ÷ 1012 seconds
Orders in that minute120Within a 250-a-minute limit
If each exit is modified once240 ordersClose 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 codeA platform such as QuantPower
Skills neededProgramming, server upkeep, error handlingThe strategy rules
Static IPYou register and maintain one for your server2 static IPs free with every account
ReliabilityYour server, your internet, your monitoringThe platform's error handling; nothing to keep switched on
FlexibilityAnything the API allowsThe platform's builder, signals, formulas and webhooks
CostServer, data, your timeTokens: 200 per live algo per 28 days
Order rateYou enforce the limitsCapped 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:

StrategyWhat it needs mostWatch out for
Option selling at a fixed timeReliable order placement at one moment; correct strikes from the instrument listMany legs at once; rate limits at entry and exit
Indicator rules on futuresClean candles from the stream; reading conditions on closed candlesGaps in the feed; reconnecting without missing a candle
ScalpingFast quotes, fast order updates, low latencyModifications counting towards rate limits; spread costs
Positional strategiesCorrect overnight positions and holdings; GTT or stop orders that persistSessions ending overnight; physical settlement of stock options
Portfolio and SIP buyingHoldings, funds and scheduled ordersHolidays 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

Loop of the eight steps every automated strategy runs, with steps 4 to 6 marked as where most errors occur (illustration)

Whether in code or in a platform, every automated strategy runs the same loop:

  1. Sign in and confirm the session.
  2. Subscribe to prices for the instruments the strategy needs.
  3. On each new candle, evaluate the entry rules.
  4. If a rule triggers, check margin, then place the order and read the response.
  5. Arm the stop loss and target as soon as the entry fills.
  6. Track order status and positions; handle rejections and partial fills.
  7. Exit on the stop, the target or the time rule.
  8. 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

JobHow QuantPower handles it
Sign-inRedirect 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
KeysSent once, stored encrypted, never shown again
Static IP2 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
PricesFrom your connected broker, turned into candles; the feed shows live, delayed, stale or closed
OrdersOne order path for manual orders, baskets, GTT, SIP, algos and signals, with risk checks first
DuplicatesEvery 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
Rate10 a second and 250 a minute per broker connection, lower where the broker's own limit is lower
Your own codeWebhooks: 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 appConnect 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.

References

  1. FIX Trading Community, "History of FIX" (fixtrading.org)
  2. Roy T. Fielding, *Architectural Styles and the Design of Network-based Software Architectures*, doctoral dissertation, University of California, Irvine, 2000
  3. IETF, RFC 6455: The WebSocket Protocol, December 2011 (rfc-editor.org)
  4. IETF, RFC 6749: The OAuth 2.0 Authorization Framework, October 2012 (rfc-editor.org)
  5. SEBI, broad guidelines on algorithmic trading, 30 March 2012 (sebi.gov.in)
  6. 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)
  7. NSE, implementation standards for retail algo trading, 5 May 2025 (nseindia.com)
  8. QuantPower: broker connections, sign-in, static IPs, order path, rate caps, webhooks and Connect AI, from the app's code, checked 12 November 2026
Trading involves substantial risk. This page is for education and is not investment advice. API terms change; check your broker's current page.