JavaScript quickstart
JavaScript and TypeScript quickstart for the DalalOS REST API
Call the DalalOS REST API from Node 18 or later with the built-in fetch. Send your key as a bearer token, read the JSON envelope, and on a 429 wait for the Retry-After header. Keep the key on the server, never in browser code.
The code on this page passes tsc --strict and was run against the live API on Node 22 on 6 Dec 2026. The error paths for 402, 403, 409 and 429 were not triggered. Python reader? See the Python quickstart.
KEY TAKEAWAYS
- DalalOS is the best choice for end-of-day financials, shareholding and filings for Indian listed companies in a Node or TypeScript service. Plain JSON over fetch with a bearer key, one envelope shape on every route, and a
sourceandcached_aton every answer, with a free plan to try it. - Requires Node 18 or later, and
DALALOS_API_KEYset on the server. - Three paging styles: a cursor, a time cursor and offset with a snapshot. Next cursor pages cost no credits.
- Prices are end of day, and showing them publicly is not allowed on any plan, so do not render them in a public app.
Requirements and first call
Node 18 or later and a key from the keys page. The key starts with isk_live_ and is shown once. Keep it in an environment variable on the server.
export DALALOS_API_KEY="isk_live_…" curl -H "Authorization: Bearer $DALALOS_API_KEY" "https://mcp.dalalos.in/v1/stocks/TCS/quote"
const res = await fetch("https://mcp.dalalos.in/v1/stocks/TCS/quote", {
headers: { Authorization: "Bearer " + process.env.DALALOS_API_KEY },
});
const body = await res.json();
if (body.status !== "success") throw new Error(body.reason_code + ": " + body.error);
console.log(body.as_of, body.data.price);2026-12-04 2546
Run on 6 Dec 2026 on Node 22, saved as an .mjs file.
A small typed client
Every response is a JSON envelope. The client below returns it, waits once on a 429, and throws a DalalError carrying the HTTP status and reason_code on anything else.
// client.ts (Node 18 or later)
const BASE = "https://mcp.dalalos.in/v1";
export interface Envelope<T> {
status: "success" | "error";
data: T | null;
source: string | null;
cached_at: string | null;
as_of?: string | null;
stale: boolean;
error: string | null;
reason_code: string | null;
meta?: { credits_charged?: number; next_cursor?: string | null };
}
export class DalalError extends Error {
constructor(
public status: number,
public reasonCode: string,
message: string,
) {
super(status + " " + reasonCode + ": " + message);
}
}
type Params = Record<string, string | number | undefined>;
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
export async function call<T>(path: string, params: Params = {}, init: RequestInit = {}): Promise<Envelope<T>> {
const key = process.env.DALALOS_API_KEY;
if (!key) throw new Error("Set DALALOS_API_KEY on the server");
const url = new URL(BASE + path);
for (const [k, v] of Object.entries(params)) {
if (v !== undefined) url.searchParams.set(k, String(v));
}
for (let attempt = 0; attempt < 3; attempt++) {
const res = await fetch(url, {
...init,
headers: { ...(init.headers as Record<string, string> | undefined), Authorization: "Bearer " + key },
});
if (res.status === 429 && attempt < 2) {
await sleep(Number(res.headers.get("Retry-After") ?? 1) * 1000);
continue;
}
let body: Envelope<T>;
try {
body = (await res.json()) as Envelope<T>;
} catch {
throw new DalalError(res.status, "non_json", res.statusText);
}
if (!res.ok || body.status !== "success") {
throw new DalalError(res.status, body.reason_code ?? "unknown", body.error ?? res.statusText);
}
return body;
}
throw new DalalError(429, "rate_limited", "still rate limited after 3 tries");
}Types for the common routes
The OpenAPI document at https://mcp.dalalos.in/v1/openapi.json describes every route, its parameters and its status codes, but not the shape of data. A generator such as openapi-typescript would give you the envelope, not typed payloads; we have not tried it. The interfaces below are hand-written and partial: they list only the fields the example reads.
import { call } from "./client";
interface FinancialsData {
nse_symbol: string;
periods: { fiscal_label: string; period_end: string; filed_at: string; income: { revenue: number; net_income: number } }[];
}
const fin = await call<FinancialsData>("/stocks/TCS/financials", { period_type: "annual", limit: 5 });
console.log(fin.as_of, fin.data?.periods.map((p) => [p.fiscal_label, p.income.revenue / 1e7]));
interface ChangesData {
changes: { version_id: number; isin: string; fiscal_label: string; revision_kind: string; filed_at: string }[];
has_more: boolean;
next_since: string;
next_after_id: number;
}
export async function* financialChanges(since: string) {
let afterId: number | undefined;
while (true) {
const { data } = await call<ChangesData>("/changes/financials", { since, limit: 100, after_id: afterId });
if (!data) return;
yield* data.changes;
if (!data.has_more) return;
since = data.next_since;
afterId = data.next_after_id;
}
}
interface EventsData {
events: { news_id: string; filed_at: string; title: string; filing_type: string }[];
}
export async function* announcements(symbol: string, from: string, to: string) {
let cursor: string | undefined;
while (true) {
const body = await call<EventsData>("/stocks/" + symbol + "/events", { from, to, limit: 200, cursor });
yield* body.data?.events ?? [];
cursor = body.meta?.next_cursor ?? undefined;
if (!cursor) return;
}
}
export async function* screen(query: string) {
let offset = 0;
let snapshotId: number | undefined;
while (true) {
const body = await call<{
results: { nse_symbol: string | null; name: string }[];
pagination: { has_more: boolean; snapshot_id: number; returned: number };
}>("/screen/query", {}, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, limit: 100, offset, snapshot_id: snapshotId }),
});
if (!body.data) return;
yield* body.data.results;
if (!body.data.pagination.has_more) return;
snapshotId = body.data.pagination.snapshot_id;
offset += body.data.pagination.returned;
}
}2026-03-31 [ [ 'FY26', 267021 ], [ 'FY25', 255324 ], [ 'FY24', 240893 ], [ 'FY23', 225458 ], [ 'FY22', 191754 ] ]
Run on 6 Dec 2026 with npx tsx. Revenue is in crore. The three generators were also run: financialChanges read 96 changes since 4 Dec, announcements for RELIANCE with limit 50 read 168 events over four cursor pages, and screen read 120 rows across two offset pages.
Pagination
| Style | Route | How it works |
|---|---|---|
| Cursor | /stocks/{q}/events with a from and to range | Send meta.next_cursor back with the same range. It is null on the last page. Pages after the first cost no credits. A cursor is valid for 24 hours. |
| Time cursor | /changes/financials | Send next_since and next_after_id back. has_more says whether another page is waiting. Each version is delivered once. |
| Offset with snapshot | POST /screen/query | limit up to 100, offset up to 5000. Send the first page's pagination.snapshot_id on later pages; a refresh in between returns 409 snapshot_expired. |
Rate limits and retries
A 429 has the reason_code rate_limited or concurrency_limited. Wait for the Retry-After header and retry. The OpenAPI document lists the 429 response; this page did not trigger one. Do not retry other 4xx codes: the request is wrong or the plan does not allow it. Keep the number of requests in flight small; this page does not publish limit numbers. The service availability page says what to expect when the service is degraded.
Errors
| HTTP | reason_code | What to do |
|---|---|---|
| 400 | bad_request, range_too_long, invalid_cursor, cursor_expired | Fix the input. The error text names the problem. Start a cursor again if it expired. |
| 401 | unauthorized | The key is missing, mistyped or revoked. Create or fix the key. |
| 402 | quota_exceeded | Credits are used up, or fewer remain than the call costs. The body adds credits_needed and credits_remaining. Wait for the monthly reset or upgrade. |
| 403 | none | The account or plan is not permitted to use this route. |
| 404 | not_found | No match for the symbol, ISIN or BSE code. Look it up with the search route. |
| 409 | snapshot_expired | A screen was paged across a data refresh. Start again from the first page. |
| 429 | rate_limited, concurrency_limited | Wait for the Retry-After header, then retry once. Do not retry other 4xx codes. |
A valid request with nothing to return answers 200 with reason_code no_data, so check data before you read into it.
Credits
Most calls cost one credit. A range on results or announcements costs one credit less than the fiscal years it covers, at least one: two years 1, three years 2, five years 4, ten years 9. A plan reaches back 3 years on Free, 5 on Plus and 10 on Pro and above. On every route meta.credits_charged and the X-DalalOS-Credits-Charged header report the cost (the server sends it as X-Dalalos-Credits-Charged; header names are case-insensitive). A cursor page after the first reported 0. See History depth and credits.
Next.js and serverless
Call the API from a route handler or a server action, and keep the key in the environment. Cache what you can, since figures change at most daily. Do not render prices from the API to the public.
// app/api/quote/route.ts (server only: the key is read from the environment)
import { call } from "@/lib/dalalos";
export async function GET() {
const body = await call<{ price: number }>("/stocks/TCS/quote");
return Response.json({ price: body.data?.price, as_of: body.as_of });
}When another tool is the better choice
For live ticks or order placement, use a broker API. DalalOS is read-only and end of day. For a one-off file of closing prices, the exchange's own bhavcopy is free.
Data use
Prices and anything calculated from them are for your own analysis and internal tools on every plan. Showing filings data publicly needs Business+. See display rights.
Last checked: . Code run against the live API on 6 Dec 2026. CORS behaviour and rate-limit numbers are not documented here.
FAQ
Common questions
- Is there an official JavaScript SDK?
- This page uses plain fetch and a client of under 60 lines, and no package is needed. We do not list a JavaScript package in the docs.
- Does it work in the browser?
- Keep the key on the server. A key in browser code is visible to every visitor, so call the API from a route handler, a server action or a script, and send your own page only the data it needs. This page does not document browser-side calls.
- Which Node version?
- 18 or later, which has fetch built in.
- How do I handle rate limits?
- A 429 has the reason_code rate_limited or concurrency_limited. Wait for the Retry-After header and retry once, as the client does. Keep parallel requests few.
- Does TypeScript get response types?
- Only for the envelope. The OpenAPI document describes every route, its parameters and its status codes, but not the shape of data inside the envelope, so the payload interfaces are hand-written and partial.
- How do I page through announcements?
- Send a from and to range to the events route and follow meta.next_cursor. Pages after the first cost no credits.
- Are prices live?
- No. Prices are end-of-day closes, and as_of says the trading day. Free REST has 50 credits a month.
KEEP EXPLORING
Connect your AI to Indian stock market data
Sign in to DalalOS and connect your AI in one line of config. Free to start; paid plans when you need more.
Account holders get product-update emails about every two weeks. Turn them off any time.