Library to extract realtime and historical data from NSE website.EOD data like bhavcopy and option chain are also saved to directory. First run will create directories for storing the data and will download the index symbols.
This module is installed via pip:
pip install pynse
Python 3.6
There is only one class in the whole library Nse
.
The whole library is equipped with python's logging
moduele for debugging. If more debug information is needed, enable logging using the following code.
import logging
logging.basicConfig(level=logging.DEBUG)
from pynse import *
# path where data will be stored
datapath='C:/Users/goldFisher/pynse/'
nse=Nse(path=datapath)
make sure datapath is absolute otherwise it will create data folders in every run
nse.market_status()
nse.info('SBIN')
Get realtime quote for EQ, FUT and OPT. If no expiry date is provided for derivatives, returns date for nearest expiry.
for cash
nse.get_quote('RELIANCE')
for futures
nse.get_quote('TCS', segment=Segment.FUT, expiry=dt.date( 2020, 6, 30 ))
for options
nse.get_quote('HDFC', segment=Segment.OPT, optionType=OptionType.PE)
download bhavcopy from nse or read bhavcopy if already downloaded
nse.bhavcopy()
or
nse.bhavcopy(dt.date(2020,6,17))
download bhavcopy from nse or read bhavcopy if already downloaded
nse.bhavcopy_fno()
or
nse.bhavcopy_fno(dt.date(2020,6,17))
get pre open data from nse
nse.pre_open()
Downloads the option chain or reads if already downloaded. if req_date is not specified returns latest available option chain from nse website
This returns dictonary containing timestamp as str option chain as pd.Dataframe expiry_list as list
nse.option_chain('INFY')
or
nse.option_chain('INFY',expiry=dt.date(2020,6,30))
get FII and DII data from nse
nse.fii_dii()
get historical data from nse symbol index or symbol
nse.get_hist('SBIN')
or
nse.get_hist('NIFTY 50', from_date=dt.date(2020,1,1),to_date=dt.date(2020,6,26))
Get realtime index value
nse.get_indices(IndexSymbol.NiftyInfra)
or
nse.get_indices(IndexSymbol.Nifty50)
presently works only for SECURITIES IN F&O
nse.top_gainers(10)
or
nse.top_losers(10)
Update list of symbols.No need to run frequently, its only required when constituent of an index is changed or list of securities in fno are updates
nse.update_symbol_list()
© 2020 Anoop Jangra
This repository is licensed under MIT license. See LICENSE for details.