Ruby gem for retrieving stock market data from the NSE (National Stock Exchange) of India.
MIT License
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.
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
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
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
The gem uses an api_endpoints.yml
file located in the config directory. This file maps API names to their respective endpoint URLs.
all_indices:
path: "allIndices"
description: "Fetches data of all available indices."
Please refer to the api_endpoints.yml file for the actual endpoint routing information.
To get started with contributing to NseData, follow these steps:
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
Install dependencies:
After navigating to the project directory, install the required gems using Bundler:
bundle install
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
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.
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.
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
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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the NseData project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the code of conduct.