npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openchart-js

v0.1.2

Published

A Node.js library to download intraday and EOD historical data from NSE India

Downloads

37

Readme

OpenChart JS

OpenChart JS is a Node.js library for downloading intraday and EOD (End of Day) historical data from the NSE (National Stock Exchange of India) and NFO (NSE Futures and Options) exchanges.

Installation

You can install the library using npm:

npm install openchart-js

Usage

Import the Library

const NSEData = require('openchart-js');

Initialize the NSEData Class

const nse = new NSEData();

Download Master Data

Before fetching historical data or searching for symbols, download the master data:

await nse.download();

Fetch Historical Data

To fetch historical data for a symbol, use the historical method. Always specify start and end dates. You can use moment to get data from 30 days back.

Intraday Data

Fetch intraday data for TCS with a 5-minute interval, from 30 days ago until today:

const moment = require('moment');

const endDate = moment();
const startDate = moment().subtract(30, 'days');

const data = await nse.historical(
    'TCS',
    'NSE',
    startDate.toDate(),
    endDate.toDate(),
    '5m'
);
console.log(data);

EOD Data

Fetch end-of-day data for Nifty 50, from 365 days ago until today:

const moment = require('moment');

const endDate = moment();
const startDate = moment().subtract(365, 'days');

const data = await nse.historical(
    'Nifty 50',
    'NSE',
    startDate.toDate(),
    endDate.toDate(),
    '1d'
);
console.log(data);

NFO Data

Fetch historical data for a futures contract of 15min data, from 30 days ago until today:

const moment = require('moment');

const endDate = moment();
const startDate = moment().subtract(30, 'days');

const data = await nse.historical(
    'BANKNIFTY24OCTFUT',
    'NFO',
    startDate.toDate(),
    endDate.toDate(),
    '15m'
);
console.log(data);

Search for Symbols

NSE Exchange

Search for symbols like Nifty 50, TCS, RELIANCE in the NSE exchange.

const symbols = nse.search('RELIANCE', 'NSE');
console.log(symbols);

NFO Exchange

Search for symbols like NIFTY24OCTFUT, BANKNIFTY24OCTFUT, NIFTY24N2124800CE, NIFTY24N2124800PE in the NFO exchange.

const symbols = nse.search('BANKNIFTY24OCT', 'NFO');
console.log(symbols);

Exact Match Search

If you want to perform an exact match search, you can set exactMatch to true.

const symbolInfo = nse.search('BANKNIFTY24OCTFUT', 'NFO', true);
console.log(symbolInfo);

Supported Timeframes

console.log(nse.timeframes());
// Output: ['1m', '3m', '5m', '10m', '15m', '30m', '1h', '1d', '1w', '1M']

Methods

  • download(): Downloads NSE and NFO master data.
  • search(symbol, exchange, exactMatch = false): Searches for symbols in the specified exchange ('NSE' or 'NFO').
    • Returns an array containing all matching symbols.
  • symbolsearch(symbol, exchange): Searches for a symbol and returns the first match.
    • Used internally by the historical method.
  • historical(symbol, exchange, start, end, interval = '1d'): Fetches historical data for a symbol.
    • Uses the symbolsearch method to find the symbol, which returns the first match.
    • Always specify start and end dates when fetching data.
  • timeframes(): Returns an array of supported timeframes.

Notes

  • Ensure that you have a stable internet connection as the library fetches data from NSE servers.
  • The historical method uses symbolsearch, which returns the first matching symbol. If multiple symbols match your query, consider using an exact symbol name or modifying the historical method to accept a symbol code directly.
  • When fetching historical data, always specify start and end dates. You can use moment to calculate these dates.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.