The Retail API Algo Framework in India
SEBI's framework for safer retail algo trading - API keys, static IP, unique algo IDs, white-box vs black-box classification and the broker and exchange responsibilities.
- ·SEBI retail algo circular (2025)
- ·API keys and static IP
- ·Unique algo ID registration
- ·White-box vs black-box algos
- ·Broker and exchange duties
- ·What changes for retail quants
For years, a retail quant in India lived in a quiet grey area. You could take an API key from your broker, point a Python script at it, and let an algorithm trade your account - and almost nobody could say with confidence whether that was allowed, who was accountable when it misfired, or what happened if your script fired a thousand stray orders into a thin market. The strategy loop from Chapter 29 was easy to build; the question of whether you were permitted to run it was a fog. On 4 February 2025, the regulator cleared that fog. The SEBI circular "Safer participation of retail investors in Algorithmic trading" turned the grey area into a written rulebook, and every retail quant who automates an order in India now lives inside it. This chapter is the map.
From grey area to rulebook
Before this circular, broker APIs were widely used to automate trading, but the formal framework only really contemplated institutional algos vetted one at a time. SEBI's "Safer participation of retail investors in Algorithmic trading" circular, dated 4 February 2025 and addressed to the stock exchanges and registered brokers, did three structural things. It explicitly permitted brokers to offer algorithmic trading to retail clients, including through APIs and third-party platforms. It made the broker the principal - the accountable party for every algo order that flows through it. And it built an audit trail so that each automated order is traceable back to a specific, approved algorithm.
That last point is the spine of the whole framework. The regulator's worry was never that retail traders write code; it was that an unidentifiable flood of automated orders has no owner, no off-switch, and no accountability when it goes wrong. So the circular's logic is simple: if an order is generated by a machine, it must be tagged, and the tag must lead back to someone responsible. Everything else - the keys, the IP locks, the registration - exists to make that tagging trustworthy.
The 4 February 2025 SEBI circular makes the broker the principal for every algo order routed through it, and requires that each such order be identifiable back to an approved algorithm. The aim is not to ban retail algos but to ensure none of them is anonymous or un-owned.
The three controls: API key, static IP, unique algo ID
The framework rests on three technical controls that together answer "who sent this, from where, and which algorithm produced it." Learn them as a set, because OpenAlgo touches all three.
First, the API key. Access to a broker's order API must run through a vendor-specific, uniquely issued key rather than a shared or anonymous credential. The key binds the automated traffic to a particular client and a particular platform, so the broker can authenticate every request and revoke access cleanly. A key is an identity, not a password to be passed around.
Second, the static IP. Algorithmic API access must originate from a fixed IP address that the trader whitelists with the broker, rather than from a roaming or dynamic address. A static IP turns "some order arrived from the internet" into "an order arrived from this registered machine," which is what makes the audit trail meaningful and stops a leaked key from being usable from anywhere.
Third, the unique algo ID. The exchange issues a unique identifier for each registered algorithm, and every order the algorithm sends must carry that tag. Crucially, the framework treats order rate as the trigger for what counts as an algo: once your API traffic crosses an order-per-second threshold set by the exchange, it is treated as algorithmic and must run under a registered algo ID. Below that, slow manual-style API use is just trading; above it, you are running an algo and the rules attach.
Do not hard-code the order-rate threshold, the number of algo IDs, or any specific limit into your assumptions. The circular sets the structure; the exchanges set the numbers, and they revise them. Treat the durable rule - "fast automated traffic must be a registered, tagged algo from a fixed IP" - as the constant, and pull the live figure from your broker or exchange when you need it.
This is also where a platform like OpenAlgo fits cleanly. OpenAlgo is the order gateway from Chapter 29: it holds your broker API key, runs on a machine whose IP you can fix and whitelist, and routes tagged orders onward. Its analyzer mode - sandbox trading - lets you exercise the entire pipeline without sending a single real order, which is exactly the cautious posture the framework rewards. Our first example reads the gateway's real execution mode and then runs the kind of pre-flight check the rules expect of every bot:
# Responsible automation: read OpenAlgo's real execution mode, then run a
# SEBI-style retail-algo pre-flight compliance gate in code. No orders are sent.
import os
from openalgo import api
client = api(
api_key=os.getenv("OPENALGO_API_KEY", "your_api_key_here"),
host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)
# --- 1) REAL execution mode from the running OpenAlgo server ---
status = client.analyzerstatus()
data = status.get("data", {})
mode = str(data.get("mode", "unknown")) # "analyze" (sandbox) or "live"
sandbox = bool(data.get("analyze_mode", False))
logged = data.get("total_logs", 0)
print(f"OpenAlgo execution mode : {mode.upper()} "
f"(sandbox={sandbox}, {logged} orders in the log)")
# --- 2) The pre-flight gate the retail framework expects every bot to pass ---
# A registered/unique algo ID, a fixed static IP, an order rate within the
# broker/exchange ceiling, and a wired kill switch. The exact ceiling is set
# by the broker/exchange; 10/sec here is illustrative only.
RATE_LIMIT = 10 # orders per second
def preflight(cfg):
return {
"registered algo ID": bool(cfg.get("algo_id")),
"static IP set": bool(cfg.get("static_ip")),
"rate within limit": cfg.get("orders_per_sec", 0) <= RATE_LIMIT,
"kill switch wired": bool(cfg.get("kill_switch")),
}
bots = {
"mean-reversion bot": {"algo_id": "NSE-ALGO-7F3A", "static_ip": "203.0.113.24",
"orders_per_sec": 4, "kill_switch": True},
"rushed scalper": {"algo_id": "", "static_ip": "203.0.113.24",
"orders_per_sec": 25, "kill_switch": False},
}
print(f"\nPre-flight compliance gate (rate ceiling = {RATE_LIMIT}/sec):")
cleared = 0
for name, cfg in bots.items():
checks = preflight(cfg)
ok = all(checks.values())
cleared += ok
flags = " ".join(f"{k}={'y' if v else 'n'}" for k, v in checks.items())
print(f" {name:18s} {'CLEARED' if ok else 'BLOCKED'} : {flags}")
verdict = "safe to dry-run" if sandbox else "orders would reach the broker"
print(f"\n{cleared}/{len(bots)} bots cleared the gate; server is in {mode.upper()} "
f"mode ({verdict}).")OpenAlgo execution mode : LIVE (sandbox=False, 66 orders in the log) Pre-flight compliance gate (rate ceiling = 10/sec): mean-reversion bot CLEARED : registered algo ID=y static IP set=y rate within limit=y kill switch wired=y rushed scalper BLOCKED : registered algo ID=n static IP set=y rate within limit=n kill switch wired=n 1/2 bots cleared the gate; server is in LIVE mode (orders would reach the broker).
The run reported the OpenAlgo server in LIVE mode with 66 orders already in its log, and the gate cleared only 1 of 2 sample bots - the "rushed scalper" was blocked for having no registered algo ID, exceeding the rate ceiling, and wiring no kill switch. That is the framework in miniature: an order with no identifiable algorithm behind it should never reach the exchange.
White-box versus black-box
The circular draws one classification that every retail quant must understand, because it decides how much paperwork your strategy carries. Algorithms are split into two kinds by a single question: can the logic be known and reproduced?
A white-box algorithm - sometimes called an execution algo - has logic that is fully disclosed to the user and is replicable: feed it the same inputs and it produces the same orders, every time, and you can read exactly why. A 9/21 EMA crossover bot is the textbook case. Anyone can see the rule, trace each signal, and reproduce the output by hand. White-box algos sit in the lighter-touch lane: they run under a standard registered, tagged algo ID.
A black-box algorithm is one whose logic is not disclosed to the user or is not replicable - the classic example being a model whose decisions cannot be reproduced from a written rule. The framework treats these as higher-risk. They carry a heavier burden: the strategy must be documented and registered, the provider faces additional obligations, and a material change to the logic means going back through registration rather than quietly editing a file. The picture below routes one algorithm through that decision:
# Decision tree: classify a retail algo as white-box or black-box from yes/no facts.
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.patches import FancyBboxPatch
sns.set_theme(style="whitegrid")
# --- the algo we are classifying, described by a few yes/no facts ---
algo = {
"name": "9/21 EMA crossover bot",
"logic_disclosed": True, # the user can read the full rule set
"output_replicable": True, # same inputs -> same orders, every time
}
def classify(a):
if not a["logic_disclosed"]:
return "BLACK BOX", "logic not disclosed to the user"
if not a["output_replicable"]:
return "BLACK BOX", "output not replicable from the logic"
return "WHITE BOX", "logic disclosed and replicable"
label, reason = classify(algo)
disclosed, replicable = algo["logic_disclosed"], algo["output_replicable"]
GREEN, RED, PURPLE, GREY = "#16a34a", "#dc2626", "#7c83ff", "#b8b8b8"
def box(ax, xy, w, h, text, edge, face="#ffffff", lw=1.7, fs=10):
ax.add_patch(FancyBboxPatch((xy[0] - w / 2, xy[1] - h / 2), w, h,
boxstyle="round,pad=0.01,rounding_size=0.04",
fc=face, ec=edge, lw=lw))
ax.text(xy[0], xy[1], text, ha="center", va="center", fontsize=fs, color="#1a1a1a")
def arrow(ax, src, dst, text, active):
col = GREEN if active else GREY
ax.annotate("", xy=dst, xytext=src,
arrowprops=dict(arrowstyle="-|>", color=col, lw=2.6 if active else 1.2))
mx, my = (src[0] + dst[0]) / 2, (src[1] + dst[1]) / 2
ax.text(mx, my, text, ha="center", va="center", fontsize=9, color=col,
fontweight="bold", bbox=dict(boxstyle="round", fc="white", ec="none"))
fig, ax = plt.subplots(figsize=(9, 5.6))
ax.set_xlim(0, 1); ax.set_ylim(0, 1); ax.axis("off"); ax.grid(False)
q1, q2 = (0.5, 0.85), (0.5, 0.52)
bb, wb = (0.22, 0.17), (0.78, 0.17)
box(ax, q1, 0.46, 0.14, "Is the strategy logic\nfully DISCLOSED to you?", PURPLE)
box(ax, q2, 0.46, 0.14, "Same inputs -> same orders?\n(output REPLICABLE?)", PURPLE)
box(ax, bb, 0.30, 0.16, "BLACK BOX\nbroker registers it,\nstrategy documented",
RED, face="#fdecec" if label == "BLACK BOX" else "#ffffff",
lw=2.4 if label == "BLACK BOX" else 1.4)
box(ax, wb, 0.30, 0.16, "WHITE BOX\nstandard unique\nalgo ID", GREEN,
face="#eafaf0" if label == "WHITE BOX" else "#ffffff",
lw=2.4 if label == "WHITE BOX" else 1.4)
arrow(ax, (0.34, 0.81), (0.27, 0.25), "no", not disclosed)
arrow(ax, q1, q2, "yes", disclosed)
arrow(ax, (0.40, 0.46), (0.27, 0.25), "no", disclosed and not replicable)
arrow(ax, (0.62, 0.47), (0.73, 0.25), "yes", disclosed and replicable)
ax.set_title(f"White-box vs black-box: '{algo['name']}' -> {label}", fontsize=13)
fig.tight_layout()
out = Path(__file__).with_suffix(".png")
plt.savefig(out, dpi=110, bbox_inches="tight")
print(f"Classified '{algo['name']}' as {label} ({reason}). Saved {out.name}")Classified '9/21 EMA crossover bot' as WHITE BOX (logic disclosed and replicable). Saved 02_whitebox_blackbox.png

The example classified the EMA crossover bot as WHITE BOX because its logic is both disclosed and replicable. The practical lesson for a retail quant is to prefer the white-box lane. Keep your logic transparent and deterministic, and you stay in the lighter regime; reach for an opaque model whose outputs you cannot reproduce, and you have just signed up for the black-box obligations.
If you cannot write down your algorithm's logic clearly enough for another person to reproduce its orders, the framework likely treats it as black-box, with registration and documentation duties attached and re-registration required when the logic changes. Reproducibility is not just good research hygiene here - it is the line between two regulatory regimes.
Who is responsible for what
The framework spreads duties across three parties, and knowing your slice keeps you out of trouble.
- The broker is the principal. It must obtain approval for the algorithms it offers, tag every algo order with its unique ID, run due diligence on any algo provider or platform it onboards, supervise the order flow, and handle client grievances. When something goes wrong, the broker is answerable first.
- The exchange sets and runs the machinery: it registers algorithms, issues the unique algo IDs, sets the order-per-second threshold and other limits, provides surveillance and testing facilities, and can pull the plug. The numbers in the framework are the exchange's to set and revise.
- You, the retail quant, own the algorithm you deploy. You are responsible for trading from your whitelisted static IP, guarding your API key, staying within the rate limits, running registered and tagged algos, and not engineering around any of these controls.
Build every new strategy in OpenAlgo's analyzer (sandbox) mode first, exactly as Chapter 29 urged. Because the sandbox runs the identical code path, a clean dry run is real evidence that your bot tags orders, respects the rate ceiling, and behaves - all before it can touch a live account. Promote to live only when the sandbox version is boringly predictable.
What it changes for an OpenAlgo quant
In practice the framework is less a cage than a checklist, and most of it is good engineering you would want anyway. Run OpenAlgo on a machine with a fixed IP and whitelist it. Keep your broker API key private and per-platform, never shared. Deploy your strategies as registered, tagged algos through your broker rather than as anonymous scripts. Stay under the exchange's order-rate threshold, or accept that you are formally an algo and register accordingly. Keep your logic white-box and reproducible unless you have a strong reason to go black-box. And rehearse everything in analyzer mode first.
The framework was rolled out through 2025, with detailed implementation standards left to a brokers' industry forum and the exchanges, so the precise mechanics and figures will keep evolving - which is exactly why you should learn the durable structure rather than memorise a number. Chapter 40 takes the next logical step: the kill switches, pre-trade risk gates and surveillance that turn this compliance posture into hard, automatic limits, and Chapter 77 returns to governance, audit and market-conduct ethics for the production quant. Compliance, it turns out, is just risk management with a regulator's signature on it.