Skip to content

Latest commit

 

History

History
181 lines (135 loc) · 5.83 KB

README.md

File metadata and controls

181 lines (135 loc) · 5.83 KB

NseData

Gem Version

Table of Contents

NseData is a Ruby gem designed to interact with the National Stock Exchange (NSE) of India's API, providing an easy-to-use interface for developers to retrieve stock market data. The gem offers a high-level API for most users and a lower-level API for advanced users who need more control over the interactions.

Features

  • Fetch stock market data from multiple NSE APIs
  • High-level and low-level API interfaces
  • Simple and clear error handling for HTTP requests
  • Ruby 3.1 and 3.2 support with a test matrix across different OS
  • Easy integration with CI/CD and coverage tools

Installation

Add this line to your application's Gemfile:

gem 'nse_data'

And then execute:

bundle install

Or install it yourself as:

gem install nse_data

Available Methods

  • fetch_all_indices
  • fetch_circulars
  • fetch_equity_master
  • fetch_glossary
  • fetch_holiday_clearing
  • fetch_holiday_trading
  • fetch_index_names
  • fetch_latest_circulars
  • fetch_market_data_pre_open
  • fetch_market_status
  • fetch_market_turnover
  • fetch_merged_daily_reports_capital
  • fetch_merged_daily_reports_debt
  • fetch_merged_daily_reports_derivatives

Usage

High-Level Interface

The high-level interface is designed to be simple and user-friendly. You can instantiate an object and call the available methods:

require 'nse_data'

puts NseData.list_all_endpoints # Returns all the available APIs in the library
puts NseData.fetch_all_indices # Returns the response.body of allIndices endpoint of NSE

Low-Level API

For advanced users, the lower-level APIManager class offers more control over requests:

require 'nse_data'

api_manager = NseData::APIManager.new
response = api_manager.fetch_data('index_names')
puts response.body # Returns index names in JSON format

where index_names is the name of the API routing to the path of https://www.nseindia.com/api/index-names

Configuration

The gem uses an api_endpoints.yml file located in the config directory. This file maps API names to their respective endpoint URLs.

Example

  all_indices:
    path: "allIndices"
    description: "Fetches data of all available indices."

APIs Available

  • all_indices: Fetches data of all available indices.
  • circulars: Provides a list of circulars.
  • equity_master: Fetches equity master data.
  • glossary: Fetches glossary content.
  • holiday_clearing: Fetches clearing holiday data.
  • holiday_trading: Fetches trading holiday data.
  • index_names: Fetches names of all indices.
  • latest_circulars: Provides the latest circulars.
  • market_data_pre_open: Fetches market pre-open data for all securities.
  • market_status: Fetches the current status of the market.
  • market_turnover: Fetches turnover data for the market.
  • merged_daily_reports_capital: Fetches merged daily reports for capital.
  • merged_daily_reports_debt: Fetches merged daily reports for debt.
  • merged_daily_reports_derivatives: Fetches merged daily reports for derivatives.

Please refer to the api_endpoints.yml file for the actual endpoint routing information.

Development

To get started with contributing to NseData, follow these steps:

  1. Clone the repository:

    First, clone the repository to your local machine and navigate to the project directory:

    git clone https://github.com/ahasunos/nse_data.git
    cd nse_data
    
  2. Install dependencies:

    After navigating to the project directory, install the required gems using Bundler:

    bundle install

Running Tests

The project uses RSpec for testing. Before submitting any changes, make sure to run the test suite to ensure that everything works as expected:

bundle exec rspec

Code Style and Linting

To maintain consistent code quality and style, the project uses RuboCop for linting. Before submitting a pull request, ensure that your code adheres to the project's style guidelines by running RuboCop:

bundle exec rubocop

If RuboCop identifies any issues, it will provide suggestions for how to fix them.

Debugging

NseData::Config::Logger

The NseData::Config::Logger class is part of the NseData gem, providing configurable logging capabilities for your application. By default, it logs to a temporary file in the system's temporary directory, but it can be customized to suit your needs.

Usage

By default, the Logger class logs to a temporary file. You can configure it as follows:

NseData.configure do |config|
  custom_logger = Logger.new($stdout)
  config.logger = custom_logger
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ahasunos/nse_data. For major changes, please open an issue first to discuss what you would like to change.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the NseData project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the code of conduct.