NSEpy
NSEpy
NSEpy
NSEpy Documentation
Introduction
Installation
Quick start
NSEpy Documentation
Introduction
NSEpy is a library to extract historical and realtime data from NSE’s website. This Library aims
to keep the API very simple.
Python is a great tool for data analysis along with the scipy stack and the main objective of
NSEpy is to provide analysis ready data-series for use with scipy stack. NSEpy can seamlessly
integrate with Technical Analysis library (Acronymed TA-Lib, includes 200 indicators like MACD,
https://nsepy.xyz 1/9
8/2/2020 NSEpy | NSEpy
RSI). This library would serve as a basic building block for automatic/semi-automatic algorithm
trading systems or backtesting systems for Indian markets.
Installation
$ pip install nsepy
Quick start
Here’s a simple example to get historical stock data for the month of January 2015.
In [1]: sbin
Out[1]: Symbol Series Prev Close Open High Low Last Close \
Date
2015-01-01 SBIN EQ 311.85 312.45 315.00 310.70 314.0 314.00
2015-01-02 SBIN EQ 314.00 314.35 318.30 314.35 315.6 315.25
2015-01-05 SBIN EQ 315.25 316.25 316.80 312.10 312.8 312.75
2015-01-06 SBIN EQ 312.75 310.00 311.10 298.70 299.9 299.90
2015-01-07 SBIN EQ 299.90 300.00 302.55 295.15 301.4 300.15
%Deliverble
Date
2015-01-01 0.3059
2015-01-02 0.4249
2015-01-05 0.4208
2015-01-06 0.4844
2015-01-07 0.3743
https://nsepy.xyz 3/9
8/2/2020 NSEpy | NSEpy
end=date(2015,1,10),
futures=True,
expiry_date=date(2015,1,29))
In [38]: stock_opt
Out[38]:
Symbol Expiry Open High Low Close Last \
Date
2015-01-01 SBIN 2015-01-29 315.10 317.95 313.40 316.65 317.00
2015-01-02 SBIN 2015-01-29 317.50 320.95 317.10 317.75 318.30
2015-01-05 SBIN 2015-01-29 318.00 318.75 314.10 315.00 315.05
2015-01-06 SBIN 2015-01-29 312.95 312.95 300.10 301.30 301.10
2015-01-07 SBIN 2015-01-29 301.95 304.55 297.35 302.25 303.50
2015-01-08 SBIN 2015-01-29 306.50 308.40 303.70 306.65 307.00
2015-01-09 SBIN 2015-01-29 306.75 309.25 301.05 304.75 304.15
Change in OI Underlying
Date
2015-01-01 358750 314.00
2015-01-02 -392500 315.25
2015-01-05 631250 312.75
2015-01-06 982500 299.90
2015-01-07 1335000 300.15
2015-01-08 -748750 304.85
2015-01-09 -252500 303.20
https://nsepy.xyz 4/9
8/2/2020 NSEpy | NSEpy
Usage-
symbol - Name of the index in capital (Refer this page for list of indices)
https://nsepy.xyz 5/9
8/2/2020 NSEpy | NSEpy
You will observe a lot of NaN values for many indeces like ‘NIFTY50 Equal wight index’, In those
cases just use ‘Close’ values
nifty_fut = get_history(symbol="NIFTY",
start=date(2015,1,1),
end=date(2015,1,10),
index=True,
futures=True,
expiry_date=date(2015,1,29))
nifty_opt = get_history(symbol="NIFTY",
start=date(2015,1,1),
end=date(2015,1,10),
index=True,
option_type='CE',
strike_price=8200,
expiry_date=date(2015,1,29))
India VIX is a volatility index which gives a measurement of market volatility based on NIFTY
options contract. This servers as important parameter in option pricing.
vix = get_history(symbol="INDIAVIX",
start=date(2015,1,1),
end=date(2015,1,10),
index=True)
month - Month of contract expiry starting from 1 for January and 12 for December
stock_opt = get_history(symbol="SBIN",
start=date(2015,1,1),
end=date(2015,1,10),
futures=True,
expiry_date=get_expiry_date(2015,1))
This will save price history of State Bank of India for the month of January 2017 as csv file with
name output.csv. Lets see the complete functionality using –help option.:
$ nsecli --help
Usage: nsecli history [OPTIONS]
Options:
https://nsepy.xyz 8/9
8/2/2020 NSEpy | NSEpy
Similar to stocks you can get Index data, just by adding –index flag -
Disclaimer: nsepy.xyz is a participant in the Amazon Associates Program, an affiliate advertising program designed to
provide a means for sites to earn advertising fees by advertising and linking to amazon.in.
https://nsepy.xyz 9/9