Upstox

Upstox API

Log in with OAuth, read funds and portfolio, pull quotes, option chains and candles, and test orders in the Upstox sandbox.

Finance & bankingGuided#trading#stock-broking#india#market-data#orders#sandbox

Fork copies the collection into your workspace, without the publisher's secrets, so you can add your own key and send requests. Star saves it to your starred APIs (Account › Marketplace) and helps others find it.

Overview

The Upstox Developer API is the trading API of Upstox, an Indian stock broker: REST endpoints to log users in with OAuth 2.0, read profile, funds, holdings and positions, download instruments, pull quotes, option chains and historical candles, calculate margin and brokerage, and place, modify and cancel regular and GTT orders, plus WebSocket feeds for market data and order updates. This guided collection covers those flows in run order and points order calls at the Upstox sandbox by default.

> Orders can be real. The order requests use orderBaseUrl and orderToken. Left at the sandbox defaults they never reach the exchange. Change them to the live order host and live token only when you intend to trade, and start with a small quantity and a LIMIT price away from the market. GTT orders have no sandbox: when a GTT triggers it places a real order.

Get credentials

  1. Open a Upstox trading account, then go to Manage API apps.
  2. Sandbox: in the sandbox section choose New Sandbox App, fill the form, open the app and press Generate to get a sandbox access token (valid 30 days, only for sandbox orders). Paste it into orderToken.
  3. Live: create an app with a redirect URL you control and copy the API key and API secret into apiKey and apiSecret, and the redirect URL into redirectUri.
  4. For live orders, register a static IP (primary and optional secondary) in the app settings; since April 2026 order APIs from other IPs are rejected.

Authentication

  1. Open the authorization dialog URL in a browser, log in, and copy code from the redirect into authCode.
  2. Send Exchange the code for an access token; it saves accessToken.
  3. Every request then sends Authorization: Bearer <token> (set on the collection).

Access tokens expire at 3:30 AM IST the next day whatever time they were issued.

Base URLs

PurposeURL
Most APIs (v2)https://api.upstox.com/v2 (baseUrl)
v3 endpoints (quotes, candles, funds, GTT)https://api.upstox.com/v3/... (written in full in each request)
Live order placementhttps://api-hft.upstox.com
Sandbox ordershttps://api-sandbox.upstox.com (orderBaseUrl default)
Instrument fileshttps://assets.upstox.com/market-quote/instruments/exchange/

Run order

Folder 1 (log in, profile, funds, static IPs) → folder 2 (instruments; set instrumentKey, then quotes, candles, option chain) → folder 3 (margin and brokerage, then place, modify and cancel in the sandbox; read the order book on live) → folder 4 (GTT) → folder 5 (portfolio) → folder 6 (logout).

Limits

Order APIs (place, modify, cancel, multi-order, GTT) share a per-user limit per second, per minute and per 30 minutes; algos above 10 orders per second must be exchange-registered. Other APIs have a higher per-second limit. Current figures: Rate limiting.

Common errors

Errors come back as {"status":"error","errors":[{"errorCode":"UDAPI...","message":"..."}]}.

CodeMeaningWhat to do
UDAPI100050Invalid or expired tokenLog in again
UDAPI100057Authorization code invalid or reusedRestart the login
UDAPI1154Order from an IP that is not registeredSend from your registered static IP
UDAPI100074Place order called between midnight and 5:30 AM ISTRetry after 5:30 AM
UDAPI1158Market order blockedUse a limit order or market protection
UDAPI100011Invalid instrument keyLook it up in the instrument file
429Rate limitSlow down

Links

Endpoints 28

1. Start here: login and account

  • GETOpen the authorization dialog (browser step)/login/authorization/dialogOpen this URL in a browser (sending it here just follows a redirect to the login page). The user logs in to Upstox and is sent to your registered redirect URI…
  • POSTExchange the code for an access token/login/authorization/tokenSwaps the one-time authorization code for an access_token (saved into accessToken). The body is form-encoded: code, client_id (API key), client_secret (API…
  • GETGet the user profile/user/profileReturns the account's email, user ID (UCC), name, enabled exchanges, products (I intraday, D delivery, MTF, CO), order types and whether POA/DDPI is set. A…
  • GETGet funds and margin (v3)https://api.upstox.com/v3/user/get-funds-and-marginThe v3 funds call groups the balance into available_to_trade (cash and pledge buckets, each with margin used: SPAN/exposure, VAR/ELM, premium, MTF, realised…
  • GETGet registered static IPs/user/ipReturns the primary and optional secondary static IP registered for your user account. Since April 2026 order placement, modification, cancellation,…

2. Market data

  • GETDownload the NSE instrument file (public)https://assets.upstox.com/market-quote/instruments/exchange/NSE.json.gzDownloads the beginning-of-day instrument master for NSE as gzipped JSON from Upstox's asset host; no token is needed. Each object has segment, name,…
  • GETSearch instruments/instruments/searchFinds instruments by symbol, name, ISIN or contract details without downloading the master file. Filters: exchanges (NSE, BSE, MCX), segments (EQ, FO, INDEX,…
  • GETGet full market quotes (v3)https://api.upstox.com/v3/market-quote/quotesFull snapshot for up to 500 instruments: last price, OHLC (with volume and ts), five-level depth, volume, average price, OI, circuit limits, previous close,…
  • GETGet LTP quotes (v3)https://api.upstox.com/v3/market-quote/ltpLightweight price check: last price, last traded quantity (ltq), the day's volume and previous close (cp) for each instrument key. Use it to pick a limit…
  • GETGet OHLC quotes (v3)https://api.upstox.com/v3/market-quote/ohlcReturns the current (live_ohlc) and previous (prev_ohlc) candle with volume and start timestamp for each instrument. interval is required: 1d (day), I1 (1…
  • GETGet historical candles (v3)https://api.upstox.com/v3/historical-candle/{{instrumentKeyPath}}/days/1/2026-11-17/2026-10-01OHLCV(+OI) candles between two dates. Path: instrument key (pipe URL-encoded as %7C), unit (minutes, hours, days, weeks, months), interval (1-300 for minutes,…
  • GETGet today's intraday candles (v3)https://api.upstox.com/v3/historical-candle/intraday/{{instrumentKeyPath}}/minutes/5Candles for the current trading day only, in custom intervals: unit minutes (1-300), hours (1-5) or days (1). Useful for strategies that need today's bars;…
  • GETGet the put/call option chain/option/chainReturns, per strike, the call and put instrument keys with market data (LTP, volume, OI, bid/ask) and Greeks (delta, gamma, theta, vega, IV) plus PCR and the…

3. Orders (sandbox first)

  • POSTCalculate margin for an order (no trade)/charges/marginReturns the margin needed for up to 20 instruments: span, exposure, equity, net buy premium, additional and total margin, plus required_margin and…
  • GETEstimate brokerage and charges/charges/brokerageBreaks down the cost of a hypothetical trade: brokerage, GST, STT, stamp duty, exchange transaction, clearing, IPFT and SEBI fees, and the DP charge. Query:…
  • POSTPlace an order (v3){{orderBaseUrl}}/v3/order/placePlaces an order and returns order_ids (several when slice splits a large quantity by the freeze limit); the first ID is saved into orderId. The place-order…
  • PUTModify an order (v3){{orderBaseUrl}}/v3/order/modifyChanges an open or pending order identified by order_id (from orderId). Send order_type, price, trigger_price and validity (required) plus optional quantity…
  • DELETECancel an order (v3){{orderBaseUrl}}/v3/order/cancelCancels an open or pending order, regular or AMO, by order_id in the query string. Run it after your test order so nothing is left working. Completed orders…
  • GETGet the order book/order/retrieve-allLists every order placed today with its latest status (open, complete, rejected, cancelled, trigger pending and so on), filled/pending quantity, average…
  • GETGet order details/order/detailsReturns the latest state of one order (orderId): status, quantities, prices, exchange order ID and timestamps. Poll this after placing to learn whether the…
  • GETGet order history/order/historyReturns every status step of an order, from put order req received through validation to open, complete, rejected or cancelled. Filter by order_id, by tag…
  • GETGet trades for an order/order/tradesLists the fills of one order: trade ID, quantity, average price and exchange timestamps. A partially filled order shows several trades. Empty when the order…

4. GTT orders

  • POSTPlace a GTT orderhttps://api.upstox.com/v3/order/gtt/placeCreates a GTT. type is SINGLE (one ENTRY rule) or MULTIPLE (ENTRY plus TARGET and/or STOPLOSS legs; add trailing_gap on the STOPLOSS for a trailing stop).…
  • GETGet GTT order detailshttps://api.upstox.com/v3/order/gttReturns the GTT identified by gtt_order_id with its rules, status of each leg, quantity, product and expiry. Leave the query parameter out to list all your…
  • DELETECancel a GTT orderhttps://api.upstox.com/v3/order/gtt/cancelDeletes a pending GTT so its rules can no longer fire. The ID goes in a JSON body (gtt_order_id) even though the method is DELETE. Run it to clean up after…

5. Portfolio

  • GETGet holdings/portfolio/long-term-holdingsLists long-term holdings with ISIN, company name, quantity, t1_quantity (bought, not yet delivered), average price, last and close price, P&L, day change,…
  • GETGet positions/portfolio/short-term-positionsLists short-term positions: intraday, F&O and today's delivery buys, with quantity, average price, last price, realised and unrealised P&L and the…

6. End the session

  • DELETELog out/logoutEnds the session so the current access token stops working; the user has to authorize again for a new token. Returns data: true on success.

API details

Base URL
https://api.upstox.com/v2
https://api.upstox.com/v3
https://api-hft.upstox.com
https://api-sandbox.upstox.com
Authentication
OAuth 2.0 (authorization code flow)
A bearer token in the Authorization header
Operations
28 operations on 28 pathsGET 20POST 4DELETE 3PUT 1
Main resources
1. Start here: login and account 52. Market data 83. Orders (sandbox first) 94. GTT orders 35. Portfolio 26. End the session 1
Description format
Swastik Codes guided collection, API version checked against the docs on 2026-11-18

How to test the Upstox API in Swastik Codes

  1. Open the APISelect “Fork & run in Swastik Codes” on this page. Sign in or create a free account if asked.
  2. Fork it into your workspaceChoose a workspace. You get your own copy of the Upstox API collection, without the publisher's secrets.
  3. Add your credentialsThis API uses OAuth 2.0 (authorization code flow). Add yours in the collection's variables or an environment; the requests already reference it.
  4. Send a requestPick an endpoint, for example “Open the authorization dialog (browser step)” (GET /login/authorization/dialog), and press Send. Check the response, add tests and run the whole collection with the runner.

Frequently asked questions

What is the Upstox API?

Log in with OAuth, read funds and portfolio, pull quotes, option chains and candles, and test orders in the Upstox sandbox. It is listed under Finance & banking and has 28 endpoints.

Who publishes the Upstox API?

It is listed from Upstox's public API description (an OpenAPI document), not published by Upstox on Swastik Codes. Anyone who controls upstox.com can claim the profile by adding a DNS TXT record.

What is the base URL of the Upstox API?

Its description lists 4 base URLs: https://api.upstox.com/v2, https://api.upstox.com/v3, https://api-hft.upstox.com, https://api-sandbox.upstox.com. The first is the usual one; the others are typically sandbox or regional servers.

How do I authenticate with the Upstox API?

It accepts 2 methods: OAuth 2.0 (authorization code flow); A bearer token in the Authorization header.

How many endpoints does the Upstox API have?

28 operations on 28 paths (20 GET, 4 POST, 3 DELETE, 1 PUT). The largest groups are 1. Start here: login and account, 2. Market data, 3. Orders (sandbox first), 4. GTT orders.

Is forking the Upstox API free?

Yes. Forking copies the collection into your workspace for free. It has been starred 0 times and forked 0 times.

Suggest an API

Tell us which public API is missing. We check it, then add it here with its endpoints when it has an OpenAPI (Swagger) description.