newTejHQ MCP is live: backtest Indian market data with your own AI agent
TEJHQ
ai tools · setup · examples

Use TejHQ with an AI tool

A lot of our sign-ups come from ChatGPT. There is no TejHQ plugin and no MCP server yet, so the AI either writes code that calls our API, or calls the API itself through a coding agent or a Custom GPT. This page covers each of those, and the mistakes we expect it to make.

First, the key

Some data needs no key. A free keyadds adjusted prices and delivery. F&O, unusual activity, the screener, daily metrics and the current universe need Retail. Put the key in an environment variable and do not paste it into a chat.

shell
export TEJ_API_KEY="tej_live_..."

ChatGPT or Claude in a browser

Ask for a script, then run it on your own machine. Point the AI at our docs and be specific about the date and the fields, or it may guess. This is the prompt we would start from:

prompt
Write a Python script using the tejhq package (pip install tejhq, from tej import Client).
Docs: https://tejhq.dev/llms.txt
Read my API key from the TEJ_API_KEY environment variable.

Get the NIFTY option chain for 2026-10-30 at the nearest expiry. Keep only rows with
contracts > 0 and print the five strikes with the highest open interest.

Claude Code, Cursor, Codex

These can run the code too. Add this to the project's CLAUDE.md or AGENTS.md so the agent starts with the rules:

AGENTS.md
## Market data: TejHQ

Use TejHQ for Indian end-of-day data. Docs: https://tejhq.dev/llms.txt
Python: pip install tejhq, from tej import Client. Node: npm install tejhq.
Read the key from the TEJ_API_KEY environment variable. Never write it into code.

Coverage: NSE from 2010-01-04, BSE from 2024-07-08. End of day only, no intraday.
No key: ohlcv, snapshot, actions. Free key: adjusted, delivery, symbols.
Retail and up: F&O, F&O stats, unusual, metrics, universe, batch, resolve, screener.

- Use adjusted prices for returns. ohlcv is raw and jumps on splits and bonuses.
- F&O rows with contracts = 0 did not trade. Drop them when reading a price, keep them
  when summing open interest.
- contracts counts lots. open_interest counts units of the underlying.
- lot_size and underlying only exist from 2024-07-08.
- Never mix NSE and BSE delivery % in one series.

A private Custom GPT

This lets ChatGPT call the API inside the chat, using your key. Keep it private: anyone who can use the GPT is spending your key's quota, and Retail is for one person.

  1. In ChatGPT, create a GPT and open Configure, then Actions.
  2. Import from URL: https://tejhq.dev/openapi-gpt.yaml. It is a read-only copy of our spec, without the account and billing endpoints.
  3. Set Authentication to API Key, type Bearer, and paste your key.
  4. Set it to Only me.

Ask for short date ranges. A full-market snapshot or a long history can be too big for one response, and a script is the better tool for those.

Examples

We ran these with tejhq 0.5.0 for Python and 0.3.0 for Node on 7 November 2026. The output in the comments is what they printed. Replace the dates with your own.

Option chain, traded rows only (Retail)

chain.py
import os
from tej import Client

c = Client(api_key=os.environ["TEJ_API_KEY"])

env = c.fo_chain_envelope("NIFTY", date="2026-10-30")
print(env["meta"]["date"], env["meta"]["expiry"], env["meta"].get("underlying"))

traded = [r for r in env["data"] if r["contracts"] > 0]
print(len(env["data"]), "contracts,", len(traded), "traded that day")
for r in sorted(traded, key=lambda r: r["open_interest"], reverse=True)[:5]:
    print(r["strike"], r["option_type"], r["close"], r["open_interest"])

# 2026-10-30 2026-11-03 23053.1
# 208 contracts, 171 traded that day
# 22000 PE 3.65 13663780
# 23500 CE 6.65 12805780
# 22500 PE 12 11960455
# 21500 PE 1.85 11312470
# 24000 CE 1.3 11008140

Put-call ratio across all expiries (Retail)

pcr.py
import os
from tej import Client

c = Client(api_key=os.environ["TEJ_API_KEY"])

def pcr(symbol, date):
    puts = calls = 0
    for e in c.fo_expiries(symbol, date=date):
        if not e["instrument"].startswith("OPT"):
            continue
        for r in c.fo_chain(symbol, date=date, expiry=e["expiry"]):
            if r["option_type"] in ("PE", "PA"):
                puts += r["open_interest"]
            else:
                calls += r["open_interest"]
    return puts / calls

print(round(pcr("NIFTY", "2020-03-23"), 4))  # 1.0263

One request per expiry, so it uses up quota quickly. Our F&O post tested this ratio and found no usable signal.

Delivery % on both exchanges (free key)

delivery.py
import os
from tej import Client

c = Client(api_key=os.environ["TEJ_API_KEY"])

nse = c.delivery("RELIANCE", exchange="nse", from_="2026-10-26", to="2026-10-30")
bse = c.delivery("RELIANCE", exchange="bse", from_="2026-10-26", to="2026-10-30")
for a, b in zip(nse, bse):
    print(a["date"], a["delivery_pct"], b["delivery_pct"])

# 2026-10-26 36.46 50.23
# 2026-10-27 46.08 64.94
# 2026-10-28 45.27 55.34
# 2026-10-29 49.06 68.46
# 2026-10-30 54.73 59.48

BSE reads higher than NSE most of the time. Here is what we found when we tested what delivery % tells you.

Raw against adjusted, across a split (free key)

adjusted.py
import os
from tej import Client

c = Client(api_key=os.environ["TEJ_API_KEY"])

raw = c.ohlcv("NESTLEIND", "nse", "2024-01-03", "2024-01-08")
adj = c.adjusted("NESTLEIND", "nse", "2024-01-03", "2024-01-08")
for r, a in zip(raw, adj):
    print(r["date"], r["close"], round(a["adj_close"], 2))

# 2024-01-03 26635.2 1295.12
# 2024-01-04 27116.4 1318.52
# 2024-01-05 2666.4 1296.52   <- 10:1 split: raw falls 90%, adjusted does not
# 2024-01-08 2619.3 1273.62

No key

ohlcv.py
from tej import Client

rows = Client().ohlcv("TCS", "nse", "2026-10-26", "2026-10-30")
print(len(rows), rows[-1]["date"], rows[-1]["close"])  # 5 2026-10-30 2502.6

Node (Retail)

chain.mjs
import { Client } from "tejhq";

const c = new Client({ apiKey: process.env.TEJ_API_KEY });
const rows = await c.foChain("NIFTY", { date: "2026-10-30" });
const traded = rows.filter((r) => r.contracts > 0);
console.log(rows.length, traded.length); // 208 171

Check what it gives you

  • Returns from raw prices are wrong across a split or bonus. Use adjusted.
  • An F&O close on a row with zero contracts is not a trade from that day.
  • Dropping no-trade rows before summing open interest undercounts it.
  • contracts are lots and open_interest is units, so do not divide one by the other without the lot size.
  • There is no intraday data here. If the code asks for it, the AI made that up.
  • If NSE's own MCP server is also connected, its history is raw bhavcopy, so splits and bonuses look like crashes. Use it for delayed quotes and TejHQ for adjusted history, corporate actions and F&O. How the two differ.
  • A short date range is a small sample. Our data can show what happened, and it cannot tell you what will.

More in the API reference, the OpenAPI spec and llms.txt. What you can do with the data is in the data terms. If an AI tool keeps getting something wrong, tell us at support@tejhq.dev and we will add it here.