ConnectivityBeginner

Broker APIs

A broker API is a programmatic interface a broker exposes so that software — rather than a human clicking a screen — can fetch market data, read account state, and place, modify or cancel orders.

Quick answer: A broker API is a programmatic interface a broker exposes so that software — rather than a human clicking a screen — can fetch market data, read account state, and place, modify or cancel orders.

In simple words

A broker API is a set of doorways into your broker's systems that a program can walk through. Instead of you tapping buy on an app, your code sends a structured message that says buy 1 lot of Nifty at market, and the broker responds with an order id. It is the same account and the same exchange rules — just driven by code instead of fingers.

Purpose

Broker APIs exist so that systematic and automated strategies can run without a human in the loop, turning tested rules into real orders reliably and at machine speed.

Visual explanation

Broker APIs

Where the broker API sits between your trading system and the exchange.

System ArchitectureLogging & MonitoringData LayerSignalGenerationPosition SizingRisk EngineExecution / OMSBrokerPortfolio · positions · cash · P&L

Professional explanation

What an API actually is

An API (Application Programming Interface) is a contract: a documented set of operations, their inputs, their outputs and their error conditions. A broker API specifies, for example, that to place an order you send an HTTP request to a named endpoint with fields like tradingsymbol, exchange, transaction_type, quantity, order_type and product, and that you will receive back either an order id or a structured error. Your code and the broker's servers never share memory; they exchange messages over the network according to this contract. Because the contract is explicit, you can build against it, test it, and reason about failure.

The three capability areas

Broker APIs cluster into three families of functionality. Market data endpoints return quotes, historical candles, the full instrument master and often a live streaming feed. Order and trade endpoints let you place, modify, cancel and query orders, and read fills, positions and the order book. Account endpoints expose funds, margins, holdings and the profile. A complete trading system touches all three: it reads data to generate a signal, checks funds and margin before acting, places the order, then polls or streams to confirm the fill and reconcile positions.

REST plus streaming, together

Almost every broker API is two protocols working in tandem. A REST (request/response) interface handles discrete actions — place order, cancel order, fetch positions — where you ask once and get one answer. A WebSocket (persistent streaming) interface pushes continuous data — live ticks, order-status updates — without you asking repeatedly. The design rule is durable: use REST to change state, use the stream to observe state changing. Confusing the two — for example, polling REST every 100 ms for prices instead of subscribing to the stream — is a common way to exhaust rate limits and miss ticks.

The India landscape and SEBI-approved access

In India several brokers expose retail-accessible APIs — Zerodha's Kite Connect and Angel One's SmartAPI are widely used examples, and others offer comparable interfaces. These are not back doors: order flow still passes through the broker's risk checks and reaches NSE or BSE under the same exchange rules as manual trading. SEBI has issued a framework governing retail algorithmic trading that assigns responsibilities to brokers, requires registration or tagging of algos in some cases, and distinguishes static from dynamic strategies. You must use only exchange- and broker-approved routes; screen-scraping or reverse-engineering an app's private endpoints is both fragile and against terms of service. Treat the current SEBI circulars and your broker's policy as the authority, because the rules evolve.

Statefulness and the source of truth

A critical mental model: the broker is the single source of truth for your account, not your program's memory. Your code holds a belief about your positions; the broker holds the fact. Network drops, restarts and partial fills can desynchronise the two. Robust systems therefore treat every local state as a cache that must be reconciled against the broker's positions and order book — typically at startup and periodically thereafter. Assuming your in-memory view is correct after an outage is how automated systems place duplicate or contradictory orders.

Idempotency and confirmation

Because the network can fail after your request leaves but before the response returns, you can never assume an order succeeded just because you sent it. A well-built client records the intent, sends the request, and then confirms the resulting state through the order book or a stream update before acting further. Some APIs support a client-supplied tag or reference on the order so you can detect whether a retried request created a duplicate. Designing for at-most-once order creation despite an at-least-once network is the central reliability problem of broker automation.

Manual trading vs API-driven trading

AspectManual (app/terminal)API-driven (code)
Who actsA human clicksA program sends requests
Speed & scaleOne order at a timeMany symbols, machine speed
ConsistencySubject to emotion/fatigueExactly the coded rules
Failure modeMisclick, hesitationBug, outage, desync — can repeat fast
Source of truthThe screen you readThe broker, reconciled by code

Practical example

Illustrative example (Indian market)

Suppose you run a simple end-of-day system on 20 Nifty-50 stocks with capital of about ₹5,00,000. Each evening your program calls the market-data endpoint to pull the day's candles, computes signals, then calls the funds endpoint to confirm available margin before acting. For two buy signals it sends two order requests and receives two order ids. Next morning it subscribes to the order-update stream, sees both fills, and reconciles its position book against the broker's positions endpoint. No number here is a recommendation — it simply shows the data, funds and order capabilities working together in one daily cycle.

In India, API order flow is still bound by exchange mechanics: F&O trades in fixed lots (illustratively 75 for Nifty), attract STT and stamp duty, and are subject to the exchange's circuit limits and product types (MIS, CNC, NRML). An API does not exempt you from any of these — it automates decisions that must still respect every regulatory and cost frictions of the live market.

Advantages

  • Turns tested rules into real orders without a human watching the screen
  • Scales across many instruments simultaneously, which manual trading cannot
  • Enables systematic reconciliation, logging and audit of every action
  • Gives access to structured historical and live data for research and execution

Limitations

  • The broker, not your code, is the source of truth; local state can silently desync
  • APIs change versions and deprecate endpoints, breaking working systems without notice
  • Access is subject to SEBI and broker policy, which can restrict or tag automated flow
  • A bug can place wrong or duplicate orders at machine speed before you notice
  • Data feeds and endpoints have outages; the system must degrade safely, not blindly

Why it matters in practice

  • It is the single bridge between a strategy and realised P&L — everything downstream depends on it
  • Its reliability, not the strategy's cleverness, often determines whether an automated system survives

Common mistakes

  • Assuming an order succeeded because the request was sent, without confirming the resulting state
  • Trusting in-memory positions after a restart or network drop instead of reconciling with the broker
  • Polling REST endpoints for prices instead of subscribing to the streaming feed, exhausting rate limits
  • Hardcoding API keys or access tokens into source code that then ends up in version control
  • Using unofficial or reverse-engineered endpoints that break and violate terms of service
  • Ignoring the SEBI/broker framework for retail algos and treating the API as a rule-free channel

Professional usage

Professional desks treat the broker or exchange gateway as an untrusted, failure-prone dependency and wrap it in an order-management layer that enforces idempotency, reconciles state continuously, and isolates strategy logic from connectivity. They version-pin the API, maintain a test/sandbox environment, and monitor connectivity as a first-class health signal. The strategy is considered the easy part; the plumbing that keeps orders correct through outages is where the engineering effort goes.

Key takeaways

  • A broker API is a documented contract for reading data and account state and driving orders from code
  • It combines REST for actions with a WebSocket stream for live data — use each for its purpose
  • In India use only SEBI- and broker-approved access; the exchange rules and costs still fully apply
  • The broker is the source of truth — always confirm and reconcile rather than trusting local state

Frequently asked questions

What is a broker API?
It is a programmatic interface a broker publishes so that software can fetch market data, read funds and positions, and place, modify or cancel orders. Your code exchanges structured messages with the broker's servers over the network according to a documented contract, instead of a person clicking an app.
Is using a broker API legal in India?
Yes, when you use an exchange- and broker-approved API. SEBI has a framework for retail algorithmic trading covering broker responsibilities and, in some cases, registration or tagging of algos. Reverse-engineering an app's private endpoints is not approved access and can breach terms of service.
What can I do with a broker API?
Three broad things: read market data (quotes, historical candles, live ticks), read account state (funds, margins, positions, holdings), and manage orders (place, modify, cancel, query). A full trading system uses all three in a single decision-to-fill cycle.
Which brokers in India offer APIs?
Several do; widely used examples include Zerodha's Kite Connect and Angel One's SmartAPI, and other brokers offer comparable interfaces. Capabilities, rate limits and pricing differ, so read each broker's current documentation rather than assuming they behave identically.
Do I still pay taxes and charges on API orders?
Yes. Orders placed through an API reach the same exchange and attract the same STT, stamp duty, brokerage and regulatory charges as manual orders. Automation changes who presses the button, not the cost structure or the exchange rules.
Is a broker API the same as a data vendor API?
No. A broker API can place orders and reflects your specific account; a data-vendor API only supplies market data and cannot trade. Many systems combine a broker API for execution with a separate data source for research or redundancy.
Why is the broker considered the source of truth?
Because your program's memory is only a belief about your account, while the broker holds the actual positions and orders. Network drops and restarts can desync the two, so robust systems reconcile local state against the broker rather than trusting the cache.
Can a broker API guarantee my order fills?
No. The API transmits the order; whether and at what price it fills depends on order type, liquidity and the market. A market order fills but with uncertain price; a limit order controls price but may never fill.
What is the difference between the REST and streaming parts?
REST handles discrete request/response actions such as placing or cancelling an order. The streaming (WebSocket) part pushes continuous live data such as ticks and order updates. The rule of thumb is: change state with REST, observe state with the stream.
Do I need coding skills to use a broker API?
To build your own client, yes — enough to make HTTP requests, parse JSON, handle errors and manage secrets. Some no-code or low-code platforms wrap broker APIs, but understanding the code lets you verify what your system actually does, which is a risk-management necessity.
Can API access be revoked or restricted?
Yes. Brokers can suspend keys for policy or risk reasons, and SEBI rules can change what retail algos are permitted to do. Treat access as a privilege bound by current regulation and your broker's terms, and design for the possibility of losing it.
What happens to my orders if my program crashes?
Orders already accepted by the broker remain live at the exchange; your program crashing does not cancel them. This is exactly why reconciliation on restart matters — the system must read the broker's live orders and positions before deciding anything new.
Is a broker API safe to use?
The interface itself is standard technology; the risk lies in how you use it. Leaking keys, skipping confirmation, or letting a bug loop can cause real losses fast. Safe use means guarding secrets, confirming state, rate-limiting yourself and building a kill switch.

Voice search & related questions

Natural-language questions people ask about Broker APIs.

What is a broker API in simple terms?
It is a set of code doorways into your broker so a program can pull data, check your funds and place orders for you, instead of you tapping an app.
Can I automate my trades using a broker API in India?
Yes, through an exchange- and broker-approved API and within SEBI's rules for retail algos. Stick to official access, not reverse-engineered app endpoints.
Does a broker API make my strategy profitable?
No. It only executes your rules reliably. A good strategy can be helped by clean automation, but the API cannot create an edge that is not there.
What three things can a broker API do?
Read market data, read your account state like funds and positions, and place, modify or cancel orders. Most systems use all three every cycle.
Is the app and the API the same account?
Yes, it is the same trading account and the same exchange rules. The API is just another way to reach it, driven by code rather than fingers.
What is the biggest risk of using a broker API?
A bug or a leaked key acting at machine speed before you notice. That is why you confirm every order, guard your secrets and keep a kill switch.

Sources & references

    Last reviewed 11 July 2026. Educational content only — not investment advice. Markets and rules change; verify current conventions with SEBI, NSE/BSE and your broker.

    Educational content only — not investment advice. Examples use illustrative numbers and simplified models. Algorithmic trading and derivatives involve substantial risk. See our Risk Disclosure and SEBI Disclaimer.