An option chain is a big table: every strike, calls on one side, puts on the other, with prices, open interest and Greeks. Building it by hand means many quote calls and a lot of symbol wrangling. The OpenAlgo option chain call gives you the whole thing in one request.
This tutorial uses the OpenAlgo Python SDK. We fetch NIFTY, load it into pandas, compute a few useful numbers and draw two charts. Everything is read only. No orders are placed.
What you need
- OpenAlgo running locally and logged in to your broker.
- Your OpenAlgo API key in an environment variable.
pip install openalgo pandas plotly kaleido
This run used openalgo 2.3.0 on Python 3.13. The same code also works on 2.4.1. The server was in Analyze mode, and the market was closed on Saturday, 28 November 2026, so the prices below are the last traded values from Friday, 27 November. During market hours you get live quotes.
pip install -U openalgo pandas plotly kaleido
export OPENALGO_API_KEY="your_api_key"
Step 1: pick an expiry
The chain needs an expiry date in DDMMMYY format. The expiry call lists what is available.
import os
from openalgo import api
client = api(api_key=os.environ["OPENALGO_API_KEY"], host="http://127.0.0.1:5000")
exp = client.expiry(symbol="NIFTY", exchange="NFO", instrumenttype="options")
print("Nearest expiries:", exp["data"][:5])
Nearest expiries: ['01-DEC-26', '08-DEC-26', '15-DEC-26', '22-DEC-26', '29-DEC-26']
The list comes back as 01-DEC-26. The chain call wants it as 01DEC26, without the dashes.
Step 2: fetch the OpenAlgo option chain with Greeks
One call returns the underlying price, the at the money strike and every leg. Two options matter here. strike_count=10 returns 10 strikes above and below the at the money strike, which is 21 rows. with_greeks=True adds implied volatility, delta, gamma, theta and vega to each leg, calculated from the quotes already fetched. If you want to compute Greeks yourself, see Computing Option Greeks Using OpenAlgo and Mibian.
r = client.optionchain(
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date="01DEC26",
strike_count=10,
with_greeks=True,
)
print({k: r[k] for k in ["underlying_ltp", "underlying_prev_close",
"expiry_date", "atm_strike", "greeks_included"]})
{'underlying_ltp': 25607.2, 'underlying_prev_close': 25884.5, 'expiry_date': '01DEC26', 'atm_strike': 25600.0, 'greeks_included': True}
On Friday’s close, NIFTY stood at 25,607.20, against a previous close of 25,884.50. The at the money strike was 25,600.
The response has a chain list. Each item has a strike, plus a ce and a pe object. Each leg carries the symbol, a moneyness label such as ATM, ITM2 or OTM4, bid and ask, OHLC, volume, open interest, lot size and the Greeks. If a contract does not exist at a strike, that leg is null, so the code guards for it.
Step 3: put the OpenAlgo option chain in a DataFrame
import pandas as pd
rows = []
for s in r["chain"]:
ce, pe = s["ce"] or {}, s["pe"] or {}
rows.append({
"strike": s["strike"],
"ce_ltp": ce.get("ltp"), "pe_ltp": pe.get("ltp"),
"ce_oi": ce.get("oi"), "pe_oi": pe.get("oi"),
"ce_iv": ce.get("implied_volatility"), "pe_iv": pe.get("implied_volatility"),
"ce_delta": ce.get("delta"), "pe_delta": pe.get("delta"),
})
df = pd.DataFrame(rows)
lot = r["chain"][0]["ce"]["lotsize"]
Here is the middle of the real table from this run, around the at the money strike:
| Strike | Call LTP | Put LTP | Call IV | Put IV | Call delta | Put delta |
|---|---|---|---|---|---|---|
| 25550 | 167.10 | 133.40 | 16.01 | 16.21 | 0.5408 | -0.4596 |
| 25600 (ATM) | 143.75 | 158.25 | 16.24 | 16.24 | 0.4877 | -0.5123 |
| 25650 | 122.00 | 187.25 | 16.35 | 16.43 | 0.4357 | -0.5639 |
At the money, the call and put implied volatility match at 16.24 percent, and the deltas sit close to 0.5 on each side, as you would expect.
Step 4: put call ratio and straddle cost
Put call ratio. Divide total put open interest by total call open interest across the strikes you fetched.
Straddle cost. Add the at the money call and put prices. This is the market price for movement until expiry, and a useful way to compare how expensive options are from one day to the next.
Lot value. Multiply by the lot size to get rupees per lot.
pcr = df.pe_oi.sum() / df.ce_oi.sum()
atm = r["atm_strike"]
a = df[df.strike == atm].iloc[0]
straddle = a.ce_ltp + a.pe_ltp
print(f"Lot size: {lot}")
print(f"Put call ratio (OI, 21 strikes): {pcr:.2f}")
print(f"ATM straddle premium: {straddle:.2f} points = Rs {straddle * lot:,.2f} per lot")
print(f"Straddle as pct of spot: {straddle / r['underlying_ltp'] * 100:.2f}")
Lot size: 65
Put call ratio (OI, 21 strikes): 0.70
ATM straddle premium: 302.00 points = Rs 19,630.00 per lot
Straddle as pct of spot: 1.18
Total call open interest across these strikes was 97,781,255 and total put open interest was 68,655,080. That gives a ratio of 0.70. The at the money straddle cost 302 points, or ₹19,630 per lot, which is 1.18 percent of the index. That is what the market was charging for movement until the 1 December expiry, three days away.
The ratio depends on how many strikes you include. Ten strikes each side gives a local view. Fetch the full chain by leaving out strike_count if you want the whole picture. Treat it as a reading of positioning, not a forecast.
Chart the open interest by strike
Open interest shows where traders have positions open. Calls are red and puts are green.
import plotly.graph_objects as go
x = df.strike.astype(int).astype(str)
fig = go.Figure()
fig.add_bar(x=x, y=df.ce_oi / 1e5, name="Call OI", marker_color="#c0392b")
fig.add_bar(x=x, y=df.pe_oi / 1e5, name="Put OI", marker_color="#1f7a5a")
fig.update_layout(template="simple_white", barmode="group",
title="NIFTY open interest by strike",
xaxis_title="Strike", yaxis_title="Open interest (lakh contracts)")
fig.write_image("oi_by_strike.png", scale=2)

Open interest is heavier in calls on the higher strikes and heavier in puts on the lower ones. That is the normal shape of a chain, with traders holding calls above the market and puts below it. It also shows why a quick glance at the chart beats scanning 42 numbers.
Chart implied volatility and delta
The second chart plots the Greeks the API returned. Implied volatility rises gently on the upper strikes, from around 16 percent near the money to about 18.6 percent at the highest strike we fetched. Delta falls smoothly for calls and moves toward minus one for puts as strikes go deeper in the money.

The walkthrough above uses the 1 December 2026 expiry so the printed numbers match this article. The full script pulls the nearest OpenAlgo option chain and builds both charts, so it stays current when you rerun it. You can also download the script as a zip file.
Other OpenAlgo option chain settings
- Full chain. Skip
strike_countto get every strike. - Stock options. Pass a stock such as
RELIANCEwith exchangeNSE. - Future as underlying. Pass a symbol like
NIFTY29DEC26FUTwith exchangeNFO, and the expiry is detected for you. - Interest rate.
with_greeks=Trueuses a 0 percent rate unless you passinterest_rate, for exampleinterest_rate=6.5. - Strict fields. The endpoint accepts only the documented fields. Anything extra returns an error, so keep your request clean.
What you can build next
The chain is the base for almost every options tool you might write: strike pickers, straddle cost trackers, Greeks dashboards and expiry day monitors. Start with this script, then change the symbol or the expiry and rerun it. To read the cash market book the same way, see Read the Live Order Book with OpenAlgo Market Depth. To place option orders by label, use OpenAlgo’s optionsorder API, and test it in Analyze mode first. This tutorial only reads data.
The full reference is on docs.openalgo.in.
# Read the NIFTY option chain with the OpenAlgo Python SDK.
# Read-only: no orders are placed.
# Set OPENALGO_API_KEY in your environment.
# OPENALGO_HOST defaults to http://127.0.0.1:5000.
#
# Requires: pip install openalgo pandas plotly kaleido
import os
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from openalgo import api
client = api(
api_key=os.environ["OPENALGO_API_KEY"],
host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)
exp = client.expiry(symbol="NIFTY", exchange="NFO", instrumenttype="options")
print("Nearest expiries:", exp["data"][:5])
# The expiry list uses dashes (01-DEC-26). The chain call wants 01DEC26.
expiry_date = exp["data"][0].replace("-", "")
r = client.optionchain(
underlying="NIFTY",
exchange="NSE_INDEX",
expiry_date=expiry_date,
strike_count=10,
with_greeks=True,
)
print({k: r[k] for k in ["underlying_ltp", "underlying_prev_close",
"expiry_date", "atm_strike", "greeks_included"]})
rows = []
for s in r["chain"]:
ce, pe = s["ce"] or {}, s["pe"] or {}
rows.append({
"strike": s["strike"],
"ce_ltp": ce.get("ltp"),
"pe_ltp": pe.get("ltp"),
"ce_oi": ce.get("oi"),
"pe_oi": pe.get("oi"),
"ce_iv": ce.get("implied_volatility"),
"pe_iv": pe.get("implied_volatility"),
"ce_delta": ce.get("delta"),
"pe_delta": pe.get("delta"),
})
df = pd.DataFrame(rows)
lot = r["chain"][0]["ce"]["lotsize"]
pcr = df.pe_oi.sum() / df.ce_oi.sum()
atm = r["atm_strike"]
a = df[df.strike == atm].iloc[0]
straddle = a.ce_ltp + a.pe_ltp
print(f"Lot size: {lot}")
print(f"Put call ratio (OI, 21 strikes): {pcr:.2f}")
print(f"ATM straddle premium: {straddle:.2f} points = Rs {straddle * lot:,.2f} per lot")
print(f"Straddle as pct of spot: {straddle / r['underlying_ltp'] * 100:.2f}")
x = df.strike.astype(int)
x_str = x.astype(str)
tickvals = [str(s) for s in x if s % 100 == 0]
axis = dict(tickangle=-45, tickvals=tickvals, ticktext=tickvals)
fig = go.Figure()
fig.add_bar(x=x_str, y=df.ce_oi / 1e5, name="Call OI", marker_color="#c0392b")
fig.add_bar(x=x_str, y=df.pe_oi / 1e5, name="Put OI", marker_color="#1f7a5a")
fig.update_layout(
template="simple_white",
paper_bgcolor="#fbfaf7",
plot_bgcolor="#fbfaf7",
barmode="group",
title=f"NIFTY open interest by strike, expiry {r['expiry_date']}",
xaxis_title="Strike",
yaxis_title="Open interest (lakh contracts)",
width=1400,
height=800,
legend=dict(orientation="h", y=-0.22),
)
fig.update_xaxes(**axis)
fig.write_image("oi_by_strike.png", scale=2)
fig = make_subplots(
rows=2,
cols=1,
vertical_spacing=0.14,
subplot_titles=("Implied volatility by strike (percent)", "Delta by strike"),
)
fig.add_scatter(
x=x_str, y=df.ce_iv, name="Call IV", mode="lines+markers",
line_color="#c0392b", row=1, col=1,
)
fig.add_scatter(
x=x_str, y=df.pe_iv, name="Put IV", mode="lines+markers",
line_color="#1f7a5a", row=1, col=1,
)
fig.add_scatter(
x=x_str, y=df.ce_delta, name="Call delta", mode="lines+markers",
line_color="#c0392b", row=2, col=1,
)
fig.add_scatter(
x=x_str, y=df.pe_delta, name="Put delta", mode="lines+markers",
line_color="#1f7a5a", row=2, col=1,
)
fig.update_layout(
template="simple_white",
paper_bgcolor="#fbfaf7",
plot_bgcolor="#fbfaf7",
width=1400,
height=1000,
legend=dict(orientation="h", y=-0.08),
)
for row in (1, 2):
fig.update_xaxes(title_text="Strike", **axis, row=row, col=1)
fig.write_image("iv_delta.png", scale=2)
print("Wrote oi_by_strike.png and iv_delta.png")
Learn by watching: free videos every week
Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

