nse-bhavcopy-utils
v1.0.9
Published
This packages provides tools to fetch bhavcopy data from NSE India and converts it from CSV to JSON. Useful for financial data analysis, automation, and stock market tools.
Maintainers
Readme
NSE Bhavcopy Utils
This Node.js package fetches bhavdata (stock market data) from the National Stock Exchange of India (NSE) for a given date, parses the CSV file, and converts it into a structured JSON format.
It’s useful for financial analysis, automation, or building stock market tools that require historical data from NSE.
Features
- Fetches bhavdata CSV from NSE for a specific date.
- Converts CSV data into structured JSON.
- Automatically trims whitespaces and parses numbers to floats where applicable.
- Simple to use with asynchronous API.
Installation
To install the package, use npm:
npm install nse-bhavcopy-utilsUsage
Import the module:
const { fetchBhavcopyByDate } = require('nse-bhavdata-utils');Fetch Bhavdata by Date
You can pass a Date object or a string representing the date (in any valid format supported by JavaScript Date) to fetch bhavdata for that date.
const { fetchBhavcopyByDate } = require('nse-bhavdata-fetcher');
async function getBhavdata() {
const date = '2025-04-21'; // You can pass any date in string format or Date object
const data = await fetchBhavcopyByDate(date);
console.log(data); // Array of JSON objects with bhavdata
}
getBhavdata();How it Works
- Date Formatting: The function automatically formats the date into the
DDMMYYYYformat. - CSV Parsing: It fetches the
.csvfile from the NSE Bhavcopy archive for the specific date. - JSON Conversion: Each row in the CSV is parsed into a JSON object. Any numerical data is converted to
float. - Result: The result is an array of objects where each object represents a row from the CSV file.
Example Output:
[
{
"SYMBOL": "INFY",
"OPEN": 1200.5,
"CLOSE": 1215.75,
"TRADE_DATE": "2025-04-21",
...
},
{
"SYMBOL": "TCS",
"OPEN": 2800.5,
"CLOSE": 2830.75,
"TRADE_DATE": "2025-04-21",
...
}
]API
fetchBhavcopyByDate(date: string | Date): Promise<Object[]>
Fetches bhavdata for the given date and returns the data as an array of JSON objects.
- Arguments:
date: A date string (e.g.,'2025-04-21') or aDateobject.
- Returns: A promise that resolves to an array of JSON objects.
Dependencies
csv-parser: For parsing CSV data.stream: Native Node.js module to handle streams.
