×

NSE Tools In Python

About NSE

NSE (National Stock Exchange) of India Limited is the advanced stock exchange of India. It is located in Mumbai, Maharastra and It was organized in 1992. It was organized as the first dematerialized electronic exchange in the country.

The nsetools is defined as the library that is used for getting real-time data from the National Stock Exchange of India. It is used in different kinds of projects which need to fetches live quotes for a specific stock or indexes and developing large data sets for performing data analytics.

Command-line interface applications can be also built for providing the live market details at a very fast speed and it can be much faster than any browser. The data accuracy is perfect as provided on http://www.nseindia.com.

We can easily install nsetools by using the following command 

pip install nsetools

Example of creating a Nse object

In this example, we are creating a Nse object which returns the driver class for National Stock Exchange.

Example –

# import nse from nse tools

from nsetools import Nse

# Now, creating a Nse object

nse = Nse()

# printing the Nse object

print(nse)

Output:

Driver Class for National Stock Exchange (NSE)

Example of getting information of a company

Here, we are going to retrieve the information of a specific company and display the buying price of company shares.

# Code for getting information

# of company shares

# import nse from nse tools

from nsetools import Nse

# creating a Nse object

nse = Nse()

# getting quote of the HDFC

quote = nse.get_quote('hdfc')

# printing the name of company

print(quote['companyName'])

# printing the buying price of company shares

print("Buy Price : " + str(quote['buyPrice1']))

Output:

HDFC

Buy Price: 2818.10

Example of getting average trade price

We can also get the average price of any company. In this example we are trying to get the average share price of a company.

Example –

# Code for getting information

# of company shares

# import nse from nse tools

from nsetools import Nse

# creating a Nse object

nse = Nse()

# getting quote of the HDFC

quote = nse.get_quote('hdfc')

# printing company name

print(quote['companyName'])

# printing the average price of company shares

print("Average Price : " + str(quote['averagePrice']))

Output:

HDFC

Average Price: 2833.94

Conclusion

In the above article, we have studied the nsetools module in Python. Also, we have seen how to get the information of a company shares.


Related Topics

_dict_ in Python

An unordered collection of data values known as a dictionary can be used in Python to store data values similar to a map. Dictionaries can also store a key: value...

6 minutes read.

File Explorer using Tkinter in Python

File Explorer: Users can control folders and files on a device using an application known as a file manager or file explorer. Customers can access, edit, copy, delete, and start moving files...

3 minutes read.

Working with JSON in Python

Python is an Object-Oriented high-level language. Python is designed to be highly beginner-friendly. Python has an English-like syntax, which is very easy to read. In this article, we are going...

4 minutes read.

How to Concat two Dataframes in Python

Using Pandas dataframe, we can concat two dataframes or series in Python. So let's take a brief introduction to what is Pandas in Python. Pandas is a library typically used for...

7 minutes read.

Python Dictionary pop() method

Python Dictionary pop() method The dictionary.pop() method in removes the specified item and returns an element from a dictionary having the given key. Syntax dictionary.pop(key[, default]) Parameter key – This argument signifies the key which is to...

2 minutes read.

Python setattr() function

Python setattr() function The setattr() function sets the value of the specified attribute of the specified object. Syntax setattr(object, name, value) Parameter object: This parameter represents any object. name: This parameter represents the name of the attribute you...

1 minute read.

Find Last Occurrence of Substring using Python

Introduction When planning to work with strings, we may need to determine whether a substring is present. This issue is rather typical, and there have been numerous discussions about how to...

3 minutes read.

Python range() function

Python range() function The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. Syntax range(stop)        or range(start, stop[, step]) Parameter start: It is...

1 minute read.

Python data science course

What is meant by Data Science? When processing raw, structured, and unstructured data utilizing various technologies, algorithms, and the scientific method, data science is a detailed study of the enormous quantity...

4 minutes read.

How to Open a file in python with Path

In this tutorial, we will see rather than the traditional way of opening a file by locating or navigating it from our desktops; we will learn how to open the...

2 minutes read.

GET and POST requests using Python

‘GET’ and ‘POST’ are two request methods of Hypertext Transfer Protocol (HTTP). What is HTTP? HTTP stands for Hypertext Transfer Protocol. It is a collection of protocols which makes communication between client...

4 minutes read.

EDA in Python

The EDA is the exploratory data analysis; the data scientists mainly use the EDA to understand the main features of the data quickly, the variables in python and the relationship...

6 minutes read.

Python maketrans() function

Introduction A static method is the string maketrans() one. It is used to make a one-to-one mapping between a string's character and its translation, i.e., to define the list of characters...

5 minutes read.

Calculator Program in Python

Simple Calculator Program in Python This example helps to learn how to create a simple calculator program to perform operations like addition, subtraction, multiplication, and division. Source Code The following is the source...

2 minutes read.

Convert List to Array in Python

What is List in Python? In Python, a list is a built-in data structure that stores a collection of items. The items in a list can be of any data type,...

3 minutes read.

Python Web Development projects

What is Python? Python is currently one of the most widely used computer programming languages. This isn't just an exaggeration; Python is the second-most famous programming language on the software development...

3 minutes read.

Installing Packages in Python

It's critical to understand that the term "package" here refers to a collection of software that must be installed (i.e. as a synonym for a distribution). It has nothing to...

6 minutes read.

Difference between Perl and Python

Control and presently utilized for a great many undertakings, including framework organization, web improvement, network programming, and GUI improvement, and the sky is the limit from there. About Perl? Perl is a...

4 minutes read.

List Iteration in Python

In this tutorial, we will learn how to iterate list in Python. List in Python A list is an ordered group of values which includes several kinds of values.A list is a mutable...

3 minutes read.

Python Pascal Triangle

Python Pascal Triangle Pascal triangle A pascal triangle is a number pattern of triangular array of the binomial coefficients. For designing a pascal triangle, we write a function in the program which...

5 minutes read.