Guide

How to Build a Trading Bot for Indian Markets

By Fincrux Data Team · Updated 28 November 2026 · 11 min read

A trading bot is not a single program that "buys low and sells high". It is a small system with separate layers for data, decisions, risk and execution. The strategies are the interesting part; the plumbing is what decides whether the bot survives a normal trading day.

How to Build a Trading Bot for Indian Markets

The five layers of a trading bot

  1. Data. Historical and live prices, corporate actions, fundamentals and the trading calendar.
  2. Decision. Deterministic rules that turn data into a signal, using only information available at that moment.
  3. Risk. Position size, daily loss limit, maximum orders and a kill switch.
  4. Execution. A broker API that places, modifies and cancels orders, with idempotency and explicit error handling.
  5. Operations. Logs, alerts, health checks, a daily login and a recovery plan.

Keeping these layers separate makes the bot testable. You can replace a data source without rewriting the strategy, or change position sizing without touching the broker adapter.

Start with the data contract

For research and daily signals, a company financials API and a historical-price API are enough. Fincrux returns company records with statements, ratios and shareholding, plus historical OHLC candles. The same record includes a last-updated timestamp, which belongs in your logs and in any chart you show to a user.

company = requests.get(
    "https://api.fincrux.org/api/financials/RELIANCE",
    params={"api_key": API_KEY},
    timeout=30,
).json()

prices = requests.get(
    "https://api.fincrux.org/api/historicals/RELIANCE",
    params={"api_key": API_KEY, "interval": "day"},
    timeout=30,
).json()

For live intraday decisions you also need a broker market-data feed. Do not treat a delayed or end-of-day data source as a live signal. Write down the freshness of each input and what the bot should do when a source is stale.

Make the strategy deterministic

A rule such as "buy when the 20-day moving average crosses above the 50-day average" is testable. A rule such as "buy when the chart looks strong" is not. Specify the timeframe, whether the candle must be closed, the entry window, the exit, the stop and the maximum number of trades per day.

  • Use closed candles for signals unless the strategy is explicitly intraday.
  • Shift signals by one bar when the backtest executes on the next bar.
  • Write the rule for holidays, missing data and circuit limits.
  • Keep the parameter count small enough that the result can be explained.

Risk belongs in code, not in your head

The risk layer should be able to reject an order even when the strategy asks for it. That is the point. A practical first version has a maximum loss per trade, a maximum loss per day, a maximum number of orders and a kill switch that cancels working orders and stops new entries.

  • Size positions from the stop distance and the risk budget, not from conviction.
  • Check margin and available funds before sending an order.
  • Refuse to trade if the data timestamp is older than the allowed window.
  • Log every rejected order with the reason.

Treat execution as an unreliable network call

Broker APIs time out, reject orders and return ambiguous responses. Use a client order ID or another idempotency key so a retry does not create a duplicate position. After a timeout, query the order book before retrying. Never assume that a missing response means the order was not placed.

The execution adapter should also understand the broker's order types, freeze quantities and square-off rules. An order that is valid in a backtest can be rejected live because the quantity exceeds a freeze limit or the product type is wrong.

Operations decide whether the bot survives

  • Run on a server with a stable IP and a clock synced to IST.
  • Complete the broker login before the open and verify the session.
  • Alert on login failure, feed disconnect, order rejection and risk-limit hits.
  • Persist state so a restart does not forget an open position.
  • Keep a manual path to close positions in the broker app.

Test in stages

Backtest the rules, paper trade the exact production code, then go live with the smallest executable quantity. Compare live fills with the assumptions in the backtest. If slippage or rejection rates are outside the expected range, stop and fix the system before increasing size.

This guide is educational and is not investment advice. Automated trading can lose money quickly. Test with small size and follow your broker's current API and regulatory requirements.

Frequently asked questions

Do I need a broker API to build a trading bot in India?

Yes, if the bot places orders. A market data API is not an execution venue. You need a broker that offers API access, complete its algo onboarding and follow the current SEBI retail algo requirements, including the registered static IP and daily authentication.

Can I build a trading bot with only daily candles?

Yes. Daily-bar strategies are easier to test, require fewer infrastructure decisions and are less sensitive to execution latency. Intraday strategies need a live feed, stricter order handling and a much clearer plan for square-off, holidays and outages.

What should the bot do when the data feed disconnects?

It should stop creating new orders, alert you, and follow a pre-defined policy for open positions. The policy can be to hold, to exit with a broker-side protective order, or to flatten manually. The important part is that it is decided before the event, not during it.

How much capital do I need for an automated strategy?

There is no universal number. The practical constraint is that the smallest executable position and the worst-case drawdown must both be survivable. Start with the smallest quantity the instrument permits, and treat the first live phase as a test of the system rather than a profit target.

Does Fincrux execute trades?

No. Fincrux supplies Indian market data and company financials. Order placement, funds and positions stay with your broker. The bot uses Fincrux for data and the broker API for execution.

Keep exploring

Put this guide to work

Start free with the Hobby plan, then scale when your product needs more throughput.

Start free