@imdr/nse-stock-history
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

nse-stock-history

Description

The stockHistory function fetches historical stock data from NSE India for a given stock symbol and time period. The data can include various metrics such as closing prices, opening prices, high, low, and volume.

Function Signature

declare const stockHistory: ({ symbol, startTimestamp, endTimestamp, resolution, onlyClose }: StockHistoryOptions) => Promise<ResponseMapperResult>;

Features

  • Fetch historical stock data for a given symbol.
  • Customize the resolution of the data (e.g., minute, hour, day, week, month).
  • Retrieve only the closing prices if needed.
  • Flexible time range selection.

Installation

To use the Stock History Fetcher, simply install it via npm:

npm i @imdr/nse-stock-history

API

Types

ResponseMapperResult

type ResponseMapperResult = {
    t: number[];
    c: number[];
    o?: number[];
    h?: number[];
    l?: number[];
    v?: number[];
};
  • t: Array of timestamps.
  • c: Array of closing prices.
  • o (optional): Array of opening prices.
  • h (optional): Array of high prices.
  • l (optional): Array of low prices.
  • v (optional): Array of trading volumes.

Resolution

type Resolution = 1 | 3 | 5 | 10 | 15 | 30 | 60 | "4h" | "1d" | "1w" | "1m";
  • 1, 3, 5, 10, 15, 30, 60: Minute resolutions.
  • "4h": Four-hour resolution.
  • "1d": Daily resolution.
  • "1w": Weekly resolution.
  • "1m": Monthly resolution.

StockHistoryOptions

type StockHistoryOptions = {
    symbol: string;
    resolution: Resolution;
    startTimestamp: number;
    endTimestamp: number;
    onlyClose?: boolean;
};
  • symbol: The stock symbol to fetch data for.
  • resolution: The desired resolution of the data.
  • startTimestamp: The start of the time range (timestamp example: 1609459200000 ).
  • endTimestamp: The end of the time range (timestamp example: 1612137600000).
  • onlyClose (optional): If true, only the closing prices will be fetched.

Usage

Here is an example of how to use the stockHistory function:

import stockHistory from 'your-library-path';

const options = {
  symbol: 'RELIANCE',
  resolution: '1d',
  startTimestamp: 1609459200000, // January 1, 2021
  endTimestamp: 1612137600000, // January 31, 2021
  onlyClose: false,
};

stockHistory(options)
  .then(data => {
    console.log('Historical Stock Data:', data);
  })
  .catch(error => {
    console.error('Error fetching stock history:', error);
  });

Notes

  • Ensure that the symbol provided is a valid NSE India stock symbol.
  • The startTimestamp should be less than the endTimestamp.
  • The resolution should be one of the allowed values.

License

This project is licensed under the MIT License.

Contact

If you have any questions or need further assistance, please contact the project maintainer at [dineshrawataias@gmail.com].

/@imdr/nse-stock-history/

    Package Sidebar

    Install

    npm i @imdr/nse-stock-history

    Weekly Downloads

    0

    Version

    1.0.10

    License

    ISC

    Unpacked Size

    25.6 kB

    Total Files

    6

    Last publish

    Collaborators

    • imdr