Introduction to NSE Tools Module in Python


We know that NSE (National Stock Exchange of India Limited) is the leading stock exchange of India. It is situated in Mumbai, Maharashtra. It was established back in 1992 as the first ever dematerialized exchange of the country.

As NSE contains data which can be used for further analysis, there is a library in Python which can help with just that. The library is known as 'nsetools' library.

Uses of the NSE tools Module

This library can be used in various projects which requires live updates of a certain index, stock or to create even larger sets of data for further analysis of that data. Certain CLI (Command Line Interface) apps can be designed using this library to help us know more about the live market at a very high speed.

Features of the NSE Tools Module

  • The 'nsetools' library works instantly and effectively without any setup at all.

  • This library helps developers to get real time data from the NSE at a very fast speed.

  • It provides all the stocks and indices traded on the National Stock Exchange.

  • This library brings in itself a feature which helps the user to differentiate between the top gainers, top losers and the most active of the overall stock exchange.

  • It also delivers many helpful APIs (Application Programming Interfaces) to help us authenticate a stock code and an index code.

  • The library returns data in JSON format, making the job of reading the data way easier.

  • It has a 100 % Unit test coverage.

Installation Process of the 'nsetools' Module

As of now, we discussed the uses and features of the module. All these things can be beneficial only if the module is installed on the desired systems. So, here is how to install the 'nsetools' library:

It may be a complex task to install other modules in Python, but in the case of 'nsetools', it is quite easy to install. All the dependencies of the library are part of the standard distribution packages of the Python programming language.

Firstly, go to the terminal of the Python IDE and type the following:

“pip install nsetools”

Here, we use the pip installer to install the 'nsetools' library into our system.

Updating the library is important after the installation of the 'nsetools' library is complete. Here is the command which will help us to update the library:

“pip install nsetools -upgrade”

How to create an NSE object?

After importing the module into our systems, all the methods of the module can be used. An NSE object can be created using the Nse() function offered by the “nsetools” library. Here is how to create an NSE object in Python:

Example

from nsetools import Nse  
nse_obj = Nse()  
print("NSE Object:", nse_obj)

First line of the code snippet is about importing the Nse function from the nsetools library. The second line shows us creating an NSE object and the third line is about printing the value of the object.

Output

The output of the code

NSE object: Driver Class for National Stock Exchange (NSE)

Obtaining required information using the nsetools module

from nsetools import Nse
nse_obj = Nse()
quote = nse_obj.get_quote('sbin')
print(quote['companyName'])
print(quote[“averagePrice”])

Similarly, the first two lines of this code snippet is about importing the nsetools module and then creating an NSE object with it.

In the third line, we can observe that a variable named 'quote' has been created to assign it to the quotation of the company. 'get_quote()'' is a function which comes with the 'nsetools' module, helps a lot to obtain the quotation of the company.

Lastly, we print the company name and the average price in the last lines of the snippet.

Updated on: 03-Aug-2023

624 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements