{
  "openapi": "3.1.0",
  "info": {
    "title": "IndiaMTF Public Data API",
    "version": "1.0.0",
    "summary": "Daily NSE + BSE Margin Trading Facility (MTF) book data for India.",
    "description": "IndiaMTF publishes India's consolidated Margin Trading Facility book, rebuilt daily from NSE and BSE public disclosures.\n\nThis is a read-only API of static JSON and CSV documents served over HTTPS. There is no authentication, no rate limit, and no write surface. Every endpoint is a plain GET and is safe to cache.\n\nAll monetary values are in INR crore (1 crore = 10,000,000). All dates are ISO-8601 (YYYY-MM-DD) unless stated otherwise. BSE MTF disclosures begin around 2025-10-15; before that date, combined figures are NSE-only.\n\nIndiaMTF is an independent informational project. It is not a brokerage, not affiliated with NSE or BSE, and not registered with SEBI.",
    "license": { "name": "CC BY 4.0", "identifier": "CC-BY-4.0" },
    "contact": { "url": "https://indiamtf.com/contact.html" }
  },
  "servers": [{ "url": "https://indiamtf.com", "description": "Production" }],
  "tags": [
    { "name": "Daily", "description": "The most recent trading day." },
    { "name": "History", "description": "Time series across trading days." },
    { "name": "Scrips", "description": "Per-instrument data." }
  ],
  "paths": {
    "/latest.json": {
      "get": {
        "tags": ["Daily"],
        "operationId": "getLatest",
        "summary": "Latest trading day's MTF book",
        "description": "The full dashboard payload for the most recently published trading day: combined/NSE/BSE nets, day-on-day change, weekly and monthly change, scrip counts, the Top 100 funded scrips, and the biggest increases and decreases.",
        "responses": {
          "200": {
            "description": "Latest day payload.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/LatestPayload" }
              }
            }
          }
        }
      }
    },
    "/history/snapshots.json": {
      "get": {
        "tags": ["History"],
        "operationId": "getSnapshots",
        "summary": "Whole-book daily net time series",
        "description": "The authoritative market-wide daily net outstanding for each exchange. This is the only correct source for whole-book totals; summing the per-day scrip archive understates the book because that archive is capped at the top 500 instruments.",
        "responses": {
          "200": {
            "description": "Per-exchange daily series.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Snapshots" }
              }
            }
          }
        }
      }
    },
    "/history/archive/index.json": {
      "get": {
        "tags": ["History"],
        "operationId": "getArchiveIndex",
        "summary": "Index of every archived trading day",
        "description": "One entry per available trading day with the combined/NSE/BSE nets, scrip counts, and day, week and month changes. Use this to discover which dates exist before requesting a per-date document.",
        "responses": { "200": { "description": "Per-date index.", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    },
    "/history/scrip_trends.json": {
      "get": {
        "tags": ["Scrips"],
        "operationId": "getScripTrends",
        "summary": "Top 500 scrips with change windows",
        "description": "Every instrument in the top 500 by combined funded value, each with its current book and its change over the 1d, 5d, 10d, 30d, 3m, 6m and 12m windows. This is the dataset behind the on-site screener.",
        "responses": {
          "200": {
            "description": "Screener dataset.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ScripTrends" } } }
          }
        }
      }
    },
    "/history/sector_trends.json": {
      "get": {
        "tags": ["History"],
        "operationId": "getSectorTrends",
        "summary": "Sector-level book and flows",
        "description": "Aggregate MTF book per sector with change windows. Computed across the top 500 instruments (basis: top500), not the entire book.",
        "responses": { "200": { "description": "Sector aggregates.", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    },
    "/history/stock/index.json": {
      "get": {
        "tags": ["Scrips"],
        "operationId": "listStocks",
        "summary": "Index of every instrument with a per-stock document",
        "description": "Maps ticker to ISIN, display name, latest funded value and the number of days of history held. Use this to discover valid values for the ticker path parameter.",
        "responses": { "200": { "description": "Ticker index.", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    },
    "/history/stock/{ticker}.json": {
      "get": {
        "tags": ["Scrips"],
        "operationId": "getStock",
        "summary": "Full history for one instrument",
        "description": "Per-instrument time series and derived statistics: latest combined/NSE/BSE book and share counts, rank, peak and trough, change windows from 1 day to 1 year, largest single-day addition and unwind, and the full daily series.",
        "parameters": [
          {
            "name": "ticker",
            "in": "path",
            "required": true,
            "description": "Uppercase NSE ticker as listed in /history/stock/index.json, for example RELIANCE.",
            "schema": { "type": "string", "pattern": "^[A-Z0-9&._-]+$" },
            "example": "RELIANCE"
          }
        ],
        "responses": {
          "200": { "description": "Instrument document.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Stock" } } } },
          "404": { "description": "No such ticker, or the instrument has never appeared in the top 500." }
        }
      }
    },
    "/history/scripwise/daily/{date}.csv": {
      "get": {
        "tags": ["Scrips"],
        "operationId": "getScripwiseDay",
        "summary": "Top 500 funded scrips for one trading day (CSV)",
        "description": "One row per instrument, ranked by combined funded value, capped at 500 rows. Columns: symbol, isin, name, nse_cr, bse_cr, combined_cr, nse_qty, bse_qty, rank, pct_of_book, src. The src column is N for NSE-only, B for BSE-only, and N+B for both; treat it as optional and default it to N, because files written before BSE coverage began do not carry it. Summing combined_cr does NOT give the market book, because the file is capped at 500 rows; use /history/snapshots.json for whole-book totals.",
        "parameters": [
          {
            "name": "date",
            "in": "path",
            "required": true,
            "description": "Trading date in ISO-8601 form.",
            "schema": { "type": "string", "format": "date" },
            "example": "2026-07-17"
          }
        ],
        "responses": {
          "200": { "description": "Scrip table for that day.", "content": { "text/csv": { "schema": { "type": "string" } } } },
          "404": { "description": "Not a trading day, or outside the archived range." }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LatestPayload": {
        "type": "object",
        "description": "Dashboard payload for one trading day. Monetary fields are INR crore.",
        "properties": {
          "report_date": { "type": "string", "description": "Display date of the trading day described." },
          "net": { "type": "number", "description": "Combined net outstanding MTF book." },
          "net_prev": { "type": "number", "description": "Combined net on the previous trading day." },
          "book_total": { "type": "number", "description": "Combined book total; the denominator for every percentage-of-book figure." },
          "scrips_nse": { "type": "integer", "description": "Count of instruments funded on NSE." },
          "scrips_bse": { "type": "integer", "description": "Count of instruments funded on BSE." },
          "wk_change": { "type": "number", "description": "Change against the nearest trading day at or before seven calendar days earlier." },
          "mo_change": { "type": "number", "description": "Change against the nearest trading day at or before one calendar month earlier." },
          "top100": {
            "type": "array",
            "description": "Top 100 instruments by combined funded value, rank 1 first.",
            "items": { "$ref": "#/components/schemas/Top100Row" }
          }
        }
      },
      "Top100Row": {
        "type": "object",
        "properties": {
          "r": { "type": "integer", "description": "Rank by combined funded value." },
          "s": { "type": "string", "description": "Display ticker." },
          "n": { "type": "string", "description": "Instrument name." },
          "isin": { "type": "string", "description": "ISIN; the stable identity key across exchanges and ticker changes." },
          "cr": { "type": "number", "description": "Combined funded value." },
          "nse": { "type": "number", "description": "NSE portion of the funded value." },
          "bse": { "type": "number", "description": "BSE portion of the funded value." },
          "d": { "type": "number", "description": "Day-on-day change in combined funded value." },
          "p": { "type": "number", "description": "Share of the total combined book, as a percentage. Divided by the whole book, so the top 100 sum to well under 100." },
          "src": { "type": "string", "description": "Which exchanges funded this instrument.", "enum": ["N", "B", "N+B"] }
        }
      },
      "Snapshots": {
        "type": "object",
        "description": "Daily net series per exchange.",
        "properties": {
          "nse": { "type": "array", "items": { "$ref": "#/components/schemas/SeriesPoint" } },
          "bse": { "type": "array", "items": { "$ref": "#/components/schemas/SeriesPoint" } },
          "combined": { "type": "array", "items": { "$ref": "#/components/schemas/SeriesPoint" } }
        }
      },
      "SeriesPoint": {
        "type": "object",
        "properties": {
          "date": { "type": "string", "format": "date" },
          "net": { "type": "number", "description": "Net outstanding book on that date, INR crore." },
          "kind": { "type": "string", "description": "Granularity of the point.", "enum": ["day", "month"] }
        }
      },
      "ScripTrends": {
        "type": "object",
        "properties": {
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "r": { "type": "integer", "description": "Rank by combined funded value." },
                "s": { "type": "string", "description": "Display ticker." },
                "n": { "type": "string", "description": "Instrument name." },
                "isin": { "type": "string" },
                "cr": { "type": "number", "description": "Combined funded value." },
                "nse": { "type": "number" },
                "bse": { "type": "number" },
                "p": { "type": "number", "description": "Share of the total combined book, percent." },
                "w": {
                  "type": "object",
                  "description": "Change windows keyed 1d, 5d, 10d, 30d, 3m, 6m, 12m.",
                  "additionalProperties": {
                    "type": "object",
                    "properties": {
                      "c": { "type": "number", "description": "Change in INR crore over the window." },
                      "p": { "type": "number", "description": "Change over the window, percent." }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Stock": {
        "type": "object",
        "properties": {
          "ticker": { "type": "string" },
          "isin": { "type": "string" },
          "name": { "type": "string" },
          "sector": { "type": "string" },
          "latest": { "type": "object", "description": "Most recent day: combined/NSE/BSE book, share counts, rank, peak and trough." },
          "windows": { "type": "object", "description": "Change over 1d, 10d, 30d, 90d, 180d and 1y, each carrying both a book change and a share-count change." },
          "series": { "type": "array", "description": "Full daily history.", "items": { "type": "object" } }
        }
      }
    }
  }
}
