A comprehensive package and API server for accessing equity/index details and historical data from the National Stock Exchange of India. This project provides both an NPM package for direct integration and a full-featured GraphQL/REST API server.
π Documentation | π Examples
- π¦ NPM Package - Direct integration into your Node.js projects
- π GraphQL API - Modern GraphQL interface with Apollo Server
- π REST API - Comprehensive REST endpoints with Swagger documentation
- π» CLI Tool - Command-line interface for quick data access
- π³ Docker Support - Containerized deployment
- π CORS Configuration - Configurable cross-origin resource sharing
- π Real-time Data - Live market data and historical information
- π Multiple Data Types - Equity, Index, Commodity, and Options data
npm install stock-nse-indiaimport { NseIndia } from "stock-nse-india";
const nseIndia = new NseIndia();
// Get all stock symbols
const symbols = await nseIndia.getAllStockSymbols();
console.log(symbols);
// Get equity details
const details = await nseIndia.getEquityDetails('IRCTC');
console.log(details);
// Get historical data
const range = {
start: new Date("2020-01-01"),
end: new Date("2023-12-31")
};
const historicalData = await nseIndia.getEquityHistoricalData('IRCTC', range);
console.log(historicalData);# Clone and setup
git clone https://github.com/hi-imcodeman/stock-nse-india.git
cd stock-nse-india
npm install
# Start the server
npm startπ Server URLs:
- Main App: http://localhost:3000
- GraphQL Playground: http://localhost:3000/graphql
- API Documentation: http://localhost:3000/api-docs
- Node.js: Version 18 or higher
- npm: Version 8 or higher (comes with Node.js 18+)
npm install stock-nse-india
# or
yarn add stock-nse-indianpm install -g stock-nse-indiagit clone https://github.com/hi-imcodeman/stock-nse-india.git
cd stock-nse-india
npm install
npm startThe project now includes a powerful GraphQL API for flexible data querying:
# Get equity information
query GetEquity {
equities(symbolFilter: { symbols: ["IRCTC", "RELIANCE"] }) {
symbol
details {
info {
companyName
industry
isFNOSec
}
metadata {
listingDate
status
}
}
}
}
# Get indices data
query GetIndices {
indices(filter: { filterBy: "NIFTY" }) {
key
index
last
variation
percentChange
}
}The API includes schemas for:
- Equity - Stock information, metadata, and details
- Indices - Market index data and performance
- Filters - Flexible query filtering options
Comprehensive REST endpoints with automatic Swagger documentation:
GET /- Market statusGET /api/marketStatus- Market status informationGET /api/glossary- NSE glossaryGET /api/equity/:symbol- Equity detailsGET /api/equity/:symbol/historical- Historical dataGET /api/indices- Market indicesGET /api-docs- Interactive API documentation
Visit http://localhost:3000/api-docs for complete interactive API documentation powered by Swagger UI.
# Get help
nseindia --help
# Get market status
nseindia
# Get equity details
nseindia equity IRCTC
# Get historical data
nseindia historical IRCTC
# Get indices information
nseindia index
# Get specific index details
nseindia index "NIFTY AUTO"- Real-time data - Live market information
- Historical analysis - Historical price data
- Index tracking - Market index performance
- Interactive charts - ASCII-based data visualization
# Pull and run from Docker Hub
docker run --rm -d -p 3001:3001 imcodeman/nseindia
# Or build locally
docker build -t nseindia . && docker run --rm -d -p 3001:3001 nseindia:latestImage: imcodeman/nseindia
Registry: Docker Hub
- Main App: http://localhost:3001
- GraphQL: http://localhost:3001/graphql
- API Docs: http://localhost:3001/api-docs
# Server Configuration
PORT=3000
HOST_URL=http://localhost:3000
NODE_ENV=development
# CORS Configuration
CORS_ORIGINS=https://myapp.com,https://admin.myapp.com
CORS_METHODS=GET,POST,OPTIONS
CORS_HEADERS=Content-Type,Authorization,X-Requested-With
CORS_CREDENTIALS=true- Origins: Comma-separated list of allowed domains
- Methods: HTTP methods (default: GET,POST,PUT,DELETE,OPTIONS)
- Headers: Allowed request headers
- Credentials: Enable/disable credentials (default: true)
- Localhost: Always allowed for development
getAllStockSymbols()- Get all NSE stock symbolsgetData()- Generic data retrievalgetDataByEndpoint()- Get data by specific NSE API endpoints
getEquityDetails(symbol)- Get equity informationgetEquityHistoricalData(symbol, range)- Historical price datagetEquityIntradayData(symbol)- Intraday trading datagetEquityOptionChain(symbol)- Options chain datagetEquityCorporateInfo(symbol)- Corporate informationgetEquityTradeInfo(symbol)- Trading statistics
getEquityStockIndices()- Get all market indicesgetIndexHistoricalData(index, range)- Index historical datagetIndexIntradayData(index)- Index intraday datagetIndexOptionChain(index)- Index options data
getCommodityOptionChain(symbol)- Commodity options data
getGainersAndLosersByIndex(index)- Top gainers and losersgetMostActiveEquities()- Most actively traded stocks
# Clone repository
git clone https://github.com/hi-imcodeman/stock-nse-india.git
cd stock-nse-india
# Install dependencies
npm install
# Development mode with auto-reload
npm run start:dev
# Build project
npm run build
# Run tests
npm test
# Generate documentation
npm run docsnpm start- Start production servernpm run start:dev- Development mode with auto-reloadnpm run build- Build TypeScript to JavaScriptnpm test- Run test suite with coveragenpm run docs- Generate TypeDoc documentationnpm run lint- Run ESLint
# Run all tests
npm test
# Run tests with coverage
npm test -- --coverage
# Run specific test file
npm test -- utils.spec.ts- π API Reference - Complete API documentation
- π Examples - Code examples and use cases
- π Interfaces - TypeScript interface definitions
- ποΈ Modules - Module documentation
We welcome contributions! Please see our contributing guidelines and feel free to submit issues and pull requests.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- π Website: https://hi-imcodeman.github.io/stock-nse-india
- π¦ NPM: https://www.npmjs.com/package/stock-nse-india
- π³ Docker Hub: https://hub.docker.com/r/imcodeman/nseindia
- π Issues: https://github.com/hi-imcodeman/stock-nse-india/issues
β Star this repository if you find it helpful!
