Skip to main content
Broker Guides

Fyers API for Algo Trading: Complete Setup Guide

How to set up the Fyers API for algo trading — creating an app at myapi.fyers.in, the daily auth flow, connecting to a no-code platform, and fixing common errors.

BhavAI Research Team 8 min read

Ask around in Indian algo trading communities and Fyers comes up constantly — not because of marketing, but because the broker made an early, deliberate bet on being API-friendly. Generous data access, solid documentation and a straightforward app-creation process have made it a default choice for traders who automate.

This guide covers everything you need to go from a plain Fyers account to a live, automated strategy: what the API offers, how to create your app, how the daily authentication flow actually works, and how to connect it all to a no-code platform like BhavAI.

What is the Fyers API?

The Fyers API is the broker’s official programmatic interface for trading and market data — it lets external software place and manage orders across NSE equity and F&O, fetch historical candles, and stream live market data over WebSocket, all against your own Fyers account. It is the sanctioned route for automation on Fyers, and the one that keeps you inside SEBI’s framework for retail algo trading through registered brokers.

In practice, the API gives you four things:

  • Order management — place, modify and cancel orders across the segments enabled on your account (equity, F&O, and others).
  • Portfolio state — positions, holdings, funds and margin, readable in real time.
  • Historical data — candle data across multiple timeframes for backtesting and indicator warm-up.
  • Live market data — quotes, market depth and tick-by-tick updates streamed over WebSocket, plus order-status updates so your system knows the moment a fill happens.

Why algo traders like Fyers

FactorWhat it means for you
API-first cultureThe API is a core product, not an afterthought — documentation and developer tooling reflect that
Historical data accessCandle data comes with the API, which matters for anyone validating strategies properly
WebSocket market dataLive ticks and order updates without polling — essential for intraday automation
Broad segment coverageEquity and F&O on NSE, plus other segments enabled on your account
Straightforward app creationSelf-serve dashboard at myapi.fyers.in; no lengthy approval gauntlet for personal use

No broker API is perfect — Fyers, like every broker, enforces rate limits and a daily re-authentication — but the overall developer experience is a big part of why it shows up so often in algo stacks. If you are comparing brokers before committing, our Zerodha Kite Connect guide and Dhan API guide cover the two other most popular choices.

Creating your app at myapi.fyers.in

Everything starts with an “app” — a registered identity that represents your software (or the platform acting on your behalf) to Fyers. You create one at myapi.fyers.in:

  • Log in with your Fyers credentials and choose to create a new app.
  • Give it a name (anything memorable) and select the permissions it needs — for live trading you want both data and transaction permissions.
  • Enter the redirect URL. This is where Fyers sends you after a successful login. If you are connecting through a platform, it will tell you the exact URL to paste here; it must match character for character.
  • On creation you receive an App ID and an app secret. The App ID is semi-public; the secret must be guarded like a password.

That’s the one-time setup. The recurring part is authentication.

The daily auth flow, in plain language

The Fyers API uses an OAuth-style flow, which sounds technical but reduces to a simple idea: you prove who you are to Fyers directly, and Fyers hands your software a temporary pass.

Here is the sequence in plain words:

  1. Your platform sends you to Fyers’ own login page, identifying itself with your App ID.
  2. You log in on Fyers’ page — credentials and two-factor authentication are entered there and nowhere else.
  3. Fyers redirects back to the registered redirect URL with a short-lived authorization code.
  4. The platform exchanges that code, together with the app secret, for an access token.
  5. That token authorizes API calls — orders, data, positions — for the rest of the trading day.

The token is deliberately short-lived: it expires daily, so each trading day starts with a fresh login. This is a regulatory-minded design, not an inconvenience bug — it ensures a human authorizes each day’s session and that no third party ever needs your password. Self-hosted scripts must automate the token exchange every morning; platforms compress it into a one-tap reconnect prompt.

Step-by-step: connect Fyers to BhavAI

  1. Create the app at myapi.fyers.in as described above, with trading and data permissions enabled.
  2. Copy the redirect URL from the dashboard. Open the broker connection screen, select Fyers, and paste the URL it displays into your Fyers app’s redirect field. Save the app.
  3. Enter your App ID and secret. Both are stored encrypted; the platform never asks for, sees, or stores your Fyers password.
  4. Complete the first login. Click connect — the Fyers login page opens, you authenticate with your credentials and 2FA, and you are redirected back with the connection showing active.
  5. Re-authenticate each trading morning. When the previous day’s token expires, the dashboard shows a reconnect prompt; one tap and a quick Fyers login restores the session. Make it part of the pre-market routine, before 9:15 AM.
  6. Deploy a validated strategy. Choose a strategy that has already survived backtesting on NSE data, Monte Carlo analysis and paper trading, set capital and risk limits, and deploy. The whole pre-deployment sequence is laid out in how retail traders can automate trading.

The order of operations matters. Broker connection is step five of the strategy lifecycle, not step one — a live API attached to an unvalidated idea just automates losses faster. If you haven’t stress-tested the strategy yet, Backtesting vs Paper Trading explains what each stage catches that the other misses.

Rate limits: the constraint to design around

Like every broker, Fyers enforces rate limits — caps on how many API requests you can make per second and per day. The exact numbers vary by endpoint and can change, so treat the official documentation as the source of truth. What matters for strategy design:

  • Don’t poll when you can stream. Fetching quotes in a tight loop burns through request limits; the WebSocket feed exists precisely so you don’t have to.
  • Batch what can be batched. Requesting quotes for multiple symbols in one call beats one call per symbol.
  • Leave headroom for order management. A strategy that spends its request budget on data can find itself throttled at the exact moment it needs to modify a stop-loss.

Managed platforms handle this plumbing for you — BhavAI maintains the market data streams and spaces API calls within limits, so a strategy built in its AI or visual builder never has to think about request budgets.

Safety notes

  • The app secret is the crown jewel. Never post it in forums, commit it to public code, or share it in screenshots. If exposed, regenerate it at myapi.fyers.in immediately.
  • Passwords never leave Fyers. The OAuth-style flow means you only ever type credentials on Fyers’ own login page. Any tool asking for your Fyers password directly is a red flag.
  • Credentials are encrypted at rest on any platform worth using — App ID, secret and daily tokens alike. Ask the question before connecting; a serious platform will answer it plainly.
  • You can revoke access anytime by deleting or disabling the app in the Fyers API dashboard, or disconnecting the broker in your platform. Either action stops automation cold.
  • Set kill switches before the first live order — max daily loss, max positions, max order size — and verify they actually trip before trusting them with real capital.

Troubleshooting

Login succeeds but the redirect fails. Almost always a redirect URL mismatch between the Fyers app settings and what the platform sent. Re-paste the URL exactly, including the protocol and any trailing path.

“Invalid token” or authentication errors mid-day. The access token may have been invalidated — commonly by generating a fresh token from another application using the same app. Reconnect, and avoid running two systems off one app simultaneously.

Orders rejected for margin. The account’s available margin doesn’t cover the order at current requirements. F&O margins move with volatility and event calendars; reduce position size or add funds, and set strategy capital below your total balance to leave a buffer.

Order rejected with an RMS reason. Broker-side risk checks reject orders for contract bans, price bands, or invalid trigger prices, among other reasons. The rejection text from Fyers is specific — read it in the platform’s order log before changing anything.

Historical data requests failing or throttled. Long backfills across many symbols can hit rate limits. Request smaller date ranges, fewer symbols per burst, or rely on a platform that maintains its own NSE historical dataset for backtesting.

WebSocket disconnections. Network blips happen; the fix is automatic reconnection with resubscription to your symbol list. If you self-host, build this in — a strategy that silently loses its data feed is a strategy trading blind.

FAQ

Does the Fyers API cost anything? Fyers has positioned its API as accessible to retail traders, and API access has been available without the recurring fee some other brokers charge. Confirm current terms on the official Fyers API portal before budgeting, as broker pricing can change.

Do I need to know how to code to use the Fyers API? Only if you self-host. Using the raw API means writing and maintaining code for auth, data, orders and error handling. A no-code platform like BhavAI sits on top of the same official API — you build strategies in plain English or a visual editor, and it speaks to Fyers for you. You can start free and connect Fyers only when you’re ready to deploy.

Why do I have to log in every day? Access tokens expire daily by design across Indian broker APIs. It guarantees a human authorizes each session and that your password never sits on a third-party server. Expect a one-tap reconnect each trading morning.

Can I trade options strategies through the Fyers API? Yes — F&O order placement is supported on segments enabled on your account, and live market data covers option contracts. Just be aware that options margins and broker-side risk checks are stricter, so test with paper trading first.


Trading in securities involves risk of loss. Nothing in this article is investment advice; it is educational content. Always test strategies thoroughly before deploying real capital.

Put this into practice

Build and backtest your own strategy free — no coding, no card.

Start free
Free · No card

Create your account

25 free backtests on seven years of NSE data. We'll set you up and email your login.

By continuing you agree to our Terms and Privacy Policy.