Home  >  Article  >  Backend Development  >  Introduction to NSE tool module in Python

Introduction to NSE tool module in Python

王林
王林forward
2023-09-17 10:09:031289browse

Introduction to NSE tool module in Python

We know that NSE (National Stock Exchange of India Limited) is the leading stock exchange in India. It is located in Mumbai, Maharashtra. Founded in 1992, it was the first dematerialized exchange in the country.

Since NSE contains data that can be used for further analysis, there is a library in Python that can help. This library is called the "nsetools" library.

Purpose of NSE tool module

This library can be used for various projects that require real-time updates of specific indices, stocks, or the creation of larger data sets to further analyze this data. Certain CLI (Command Line Interface) applications can be designed using this library to help us quickly understand the live market.

NSE tool module functions

  • The "nsetools" library works immediately and efficiently without any setup.

  • This library helps developers get real-time data from NSE very fast.

  • It provides all stocks and indices traded on national stock exchanges.

  • The library itself has a feature that helps users differentiate between the top gainers, top losers and most active stocks across the stock exchange.

  • It also provides many useful APIs (Application Programming Interfaces) to help us verify stock symbols and index codes.

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

  • It has 100% unit test coverage.

Installation process of "nsetools" module

So far, we have discussed the purpose and functionality of this module. All these things are only beneficial if the module is installed on the required system. So, here's how to install the "nsetools" library:

Installing other modules in Python can be a complex task, but in the case of "nsetools", it is quite easy to install. All dependencies of this library are part of the standard distribution of the Python programming language.

First, go to the Python IDE’s terminal and enter the following:

“pip install nsetools”

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

After the "nsetools" library is installed, it is very important to update the library. Here is the command that helps us update the library:

“pip install nsetools -upgrade”

How to create an NSE object?

After importing the module into our system, all methods of the module can be used. NSE objects can be created using the Nse() function provided by the "nsetools" library. Here's how to create an NSE object in Python:

Example

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

The 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 that object.

Output

Output of code

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

Use the nsetools module to obtain the required information

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

Again, the first two lines of this code snippet are about importing the nsetools module and then using it to create an NSE object.

In the third line, we can observe that a variable named "quote" has been created and assigned to the company's quote. 'get_quote()'' is a function that comes with the 'nsetools' module, which is very helpful for obtaining the company's quotation.

Finally, we print the company name and average price in the last few lines of the code snippet.

The above is the detailed content of Introduction to NSE tool module in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete