FII and DII daily flows into Python and a CSV
NSE publishes the cash-market buy and sell figures for FII/FPI and DII each day. The API returns them as JSON so you can chart or archive them.
You need an API key: request a free beta key. Keep it in an environment variable, never in code you publish.
Script
import os
import requests
import pandas as pd
BASE = os.environ.get("EJI_BASE", "https://fin.ejiapi.com")
HEADERS = {"x-api-key": os.environ.get("EJI_KEY", "YOUR_KEY")}
r = requests.get(f"{BASE}/api/market/flows/fii-dii", headers=HEADERS, timeout=30)
r.raise_for_status()
df = pd.DataFrame(r.json()["data"])
print(len(df), "rows;", df["date"].min(), "to", df["date"].max())
# One row per day, FII and DII side by side (net, rupees crore)
wide = df.pivot_table(index="date", columns="category", values="netCr").sort_index()
wide["combined"] = wide.sum(axis=1)
print(wide.round(2))
# Keep a running file: append today's rows without duplicating days
path = "fii_dii.csv"
if os.path.exists(path):
old = pd.read_csv(path)
df = pd.concat([old, df]).drop_duplicates(subset=["date", "category"])
df.sort_values(["date", "category"]).to_csv(path, index=False)
print("saved", len(df), "rows to", path)Output
10 rows; 2026-11-02 to 2026-11-06 category DII FII/FPI combined date 2026-11-02 -392.20 3114.68 2722.48 2026-11-03 -3678.85 6836.81 3157.96 2026-11-04 -3712.23 7284.03 3571.80 2026-11-05 -10444.54 14974.68 4530.14 2026-11-06 -5968.70 13749.82 7781.12 saved 10 rows to fii_dii.csv
What to know
- All amounts are rupees crore.
netCris buy minus sell; the code uses it directly. - History starts when we first stored it. NSE only publishes the latest day, so there is no data before the API began collecting. That is why the script appends to a CSV: run it daily and you also hold your own copy.
- These are cash-market figures. Derivatives positions by participant are a separate endpoint,
/api/market/derivatives/participant-oi, in the reference.
Data comes from public disclosures and is for information, not investment advice. Sample outputs were produced on 2026-11-08 and change as new data is published.