Skip to main content

Overview

The Dhan ScanX API provides comprehensive market data for all NSE equity stocks in a single request. This endpoint returns fundamental metrics, technical indicators, and metadata for approximately 2,775 stocks, making it the foundation for building a master ISIN mapping file. Source File: fetch_dhan_data.py

Endpoint Details

URL
string
required
https://ow-scanx-analytics.dhan.co/customscan/fetchdt
Method
string
required
POST
Content-Type
string
required
application/json

Request Headers

{
  "Content-Type": "application/json",
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
  "Accept": "application/json, text/plain, */*",
  "Origin": "https://scanx.dhan.co",
  "Referer": "https://scanx.dhan.co/"
}

Request Payload

data.sort
string
default:"Mcap"
Field to sort results by (e.g., “Mcap”, “Volume”, “Ltp”)
data.sorder
string
default:"desc"
Sort order - “asc” or “desc”
data.count
integer
default:"5000"
Number of results to return. Use 5000 to fetch all stocks in one call.
data.fields
array
required
Array of field names to retrieve. See available fields below.
data.params
array
required
Filter parameters. Default filters for NSE equities:
  • {"field": "OgInst", "op": "", "val": "ES"} - Equity stocks
  • {"field": "Exch", "op": "", "val": "NSE"} - NSE exchange
data.pgno
integer
default:"0"
Page number (0-indexed). Use 0 to fetch all with count=5000.

Available Fields

The API supports extensive field selection. Key fields include: Identifiers:
  • Isin - ISIN code
  • Sym - Trading symbol
  • DispSym - Display name
  • Sid - Security ID (required for advanced indicators)
  • FnoFlag - F&O availability flag
Fundamental Metrics:
  • Mcap - Market capitalization
  • Pe - Price to Earnings ratio
  • Pb - Price to Book ratio
  • Roe - Return on Equity
  • ROCE - Return on Capital Employed
  • Eps - Earnings per Share
  • DivYeild - Dividend Yield
Technical Indicators:
  • DaySMA50CurrentCandle - 50-day SMA
  • DaySMA200CurrentCandle - 200-day SMA
  • DayRSI14CurrentCandle - 14-day RSI
  • DayBbUpper_Sub_BbLower - Bollinger Band width
Price Data:
  • Ltp - Last traded price
  • Open - Opening price
  • High5yr, High3Yr, High1Yr, High1Wk - Historical highs
  • PricePerchng1year, PricePerchng3year, PricePerchng5year - Price change %
Volume & Financial:
  • volume - Trading volume
  • Revenue - Revenue
  • Year1RevenueGrowth - YoY revenue growth
  • NetProfitMargin - Net profit margin
  • EBIDTAMargin - EBITDA margin

Example Request

curl -X POST https://ow-scanx-analytics.dhan.co/customscan/fetchdt \
  -H "Content-Type: application/json" \
  -H "Origin: https://scanx.dhan.co" \
  -H "Referer: https://scanx.dhan.co/" \
  -d '{
    "data": {
      "sort": "Mcap",
      "sorder": "desc",
      "count": 5000,
      "fields": [
        "Isin", "DispSym", "Mcap", "Pe", "DivYeild", "Revenue",
        "Year1RevenueGrowth", "NetProfitMargin", "Ltp", "Roe",
        "Sym", "Sid", "FnoFlag"
      ],
      "params": [
        {"field": "OgInst", "op": "", "val": "ES"},
        {"field": "Exch", "op": "", "val": "NSE"}
      ],
      "pgno": 0,
      "sorder": "desc",
      "sort": "Mcap"
    }
  }'

Response Structure

data
array
Array of stock objects containing requested fields

Example Response

{
  "data": [
    {
      "Isin": "INE002A01018",
      "Sym": "RELIANCE",
      "DispSym": "Reliance Industries Ltd.",
      "Sid": "11536",
      "Mcap": 1750000.0,
      "Pe": 25.3,
      "Pb": 2.1,
      "Roe": 9.2,
      "Ltp": 2598.5,
      "DivYeild": 0.31,
      "FnoFlag": 1,
      "volume": 5234567
    }
  ]
}

Output Files

The script generates two critical files:

1. dhan_data_response.json

Raw market data containing all requested fields for ~2,775 stocks (varies by market conditions).

2. master_isin_map.json

Master mapping file used by all other pipeline scripts:
[
  {
    "Symbol": "RELIANCE",
    "ISIN": "INE002A01018",
    "Name": "Reliance Industries Ltd.",
    "Sid": "11536",
    "FnoFlag": 1
  }
]

Implementation Details

Configuration

  • Page Size: 5000 records per request
  • Total Results: ~2,775 stocks (entire NSE equity market)
  • Pagination: Not required - single request fetches all data
  • Timeout: Default request timeout
  • Headers: Requires Origin and Referer headers for CORS

Error Handling

The script includes comprehensive error handling:
try:
    response = requests.post(url, json=payload, headers=headers)
    response.raise_for_status()
    data = response.json()
except Exception as e:
    print(f"Error fetching data: {e}")
    if 'response' in locals():
        print(f"Response status: {response.status_code}")
        print(f"Response text: {response.text[:500]}")

Use Cases

  1. Master ISIN Mapping: Build the foundation file used by all other EDL pipeline scripts
  2. Market Screening: Filter stocks by fundamental or technical criteria
  3. Bulk Data Export: Extract comprehensive market data in a single API call
  4. F&O Universe: Identify F&O eligible stocks via FnoFlag field
  5. Index Constituents: Filter by idxlist field for index membership

Dependencies

This endpoint is a prerequisite for:
  • Fundamental Data API (requires ISIN)
  • Company Filings API (requires ISIN)
  • Announcements API (requires ISIN)
  • Advanced Indicators API (requires Sid)
  • Market News API (requires ISIN)
  • OHLCV Data API (requires Sid)

Notes

  • The Sid (Security ID) field is required for fetching advanced indicators and OHLCV data
  • Response includes nested CorpAct arrays for corporate actions (use dedicated Corporate Actions API for comprehensive data)
  • Field names are case-sensitive
  • Some fields may return null for stocks where data is unavailable
  • The API rate limiting is lenient for this endpoint as it’s designed for bulk fetches

Build docs developers (and LLMs) love