📌  相关文章
📜  nsetools (1)

📅  最后修改于: 2023-12-03 14:44:47.766000             🧑  作者: Mango

nsetools - Python library for fetching live NSE (National Stock Exchange) stock data

Introduction

nsetools is a Python library that can be used to fetch live stock data from the National Stock Exchange (NSE) of India. The library was built with the goal of providing an easy to use and efficient tool for programmers to access the live market data in order to build their own trading algorithms or applications.

Features
  • Fetch live stock prices and volumes for all stocks listed on the NSE.
  • Get the current status of the market, including the opening price, closing price, volume and turnover.
  • Retrieve data for historical stock prices, volumes and turnovers.
  • Search for stocks using their ticker symbol, company name or sector.
  • Get the top gainers and losers for the day.
  • Receive notifications when a particular stock reaches a certain price using the nsetools CLI.
Installation

nsetools can be easily installed using pip, the Python package installer. Simply run the following command in your terminal:

pip install nsetools
How to use
# Import the nsetools library
from nsetools import Nse

# Create an instance of the Nse class
nse = Nse()

# Get the current status of the market
market_status = nse.get_market_status()
print(market_status)
# Output:
# 'The market has closed'

# Search for a stock using its ticker symbol
stock_info = nse.get_stock_quote('TCS')
print(stock_info)
# Output:
# {'averagePrice': 3141.15,
#  'basePrice': 3128.85,
#  'closePrice': 3136.45,
#  'dayHigh': 3166.0,
#  'dayLow': 3120.0,
#  'deliveryQuantity': 1377569.0,
#  'deliveryToTradedQuantity': 59.58,
#  'extremeLossMargin': 5.0,
#  'faceValue': 1.0,
#  'high52': 3477.0,
#  'indexVar': None,
#  'lastPrice': 3137.0,
#  'ltP': 3137.0,
#  'lowerBand': 2662.02,
#  'marketType': 'N',
#  'open': 3130.0,
#  'pChange': 0.27,
#  'previousClose': 3128.85,
#  'priceBand': 10.0,
#  'pricebandlower': 2825.0,
#  'pricebandupper': 3432.7,
#  'purpose': 'ANNUAL GENERAL MEETING/ DIVIDEND - RS 15 PER SHARE',
#  'quantityTraded': 2315478.0,
#  'securityVar': 18.34,
#  'surv_indicator': None,
#  'symbol': 'TCS',
#  'totalBuyQuantity': None,
#  'totalSellQuantity': None,
#  'totalTradedValue': 72776.53,
#  'totalTradedVolume': 2315478.0,
#  'upperBand': 3597.68,
#  'varMargin': 18.34}

# Get the top gainers for the day
top_gainers = nse.get_top_gainers()
print(top_gainers)
# Output:
# [{'symbol': 'BAJAJ-AUTO', 'series': 'EQ', 'openPrice': 4146.5, 'highPrice': 4302.95, 'lowPrice': 4120.0, 'ltp': 4291.0, 'previousPrice': 4168.45, 'netPrice': 2.77, 'tradedQuantity': 690746, 'turnoverInLakhs': 29306.49},
#  {'symbol': 'NTPC', 'series': 'EQ', 'openPrice': 99.4, 'highPrice': 102.0, 'lowPrice': 99.2, 'ltp': 102.0, 'previousPrice': 99.5, 'netPrice': 2.51, 'tradedQuantity': 15381772, 'turnoverInLakhs': 15318.54},
#  {'symbol': 'TECHM', 'series': 'EQ', 'openPrice': 966.0, 'highPrice': 989.0, 'lowPrice': 966.0, 'ltp': 984.0, 'previousPrice': 961.25, 'netPrice': 2.37, 'tradedQuantity': 4235353, 'turnoverInLakhs': 40947.0}]

Conclusion

nsetools is a powerful library that can be used to access real-time stock data from the NSE of India with Python. The library is well-documented and easy to use, making it a great tool for developers who want to build their own trading algorithms or applications.