Jugaad Data

Introduction

Jugad data is a library to download historical data for Indian stock market.

Features

Road map

Exchange Segment Supported?
NSE Stocks Yes
NSE Stocks F&O Yes
NSE Index Yes
NSE Index F&O Yes

Installation

pip install jugaad-data

Download bhav copy

As csv from command line

Download today’s bhavcopy (works only after market hours once bhavcopy is ready)

$ jdata bhavcopy -d /path/to/dir

Download bhavcopy for a specific date

$ jdata bhavcopy -d /path/to/dir -f 2020-01-01

Download all bhavcopies between date range

$ jdata bhavcopy -d /path/to/dir -f 2020-01-01 -t 2020-01-30

Download full bhavcopies with delivery trade quantity

$ jdata bhavcopy -d /path/to/dir -f 2020-01-01 -t 2020-01-30 --full

Download index bhavcopies

$ jdata bhavcopy -d /path/to/dir -f 2020-01-01 -t 2020-01-30 --idx

Download derivatives bhavcopies between date range

$ jdata bhavcopy -d /path/to/dir -f 2020-01-01 -t 2020-01-30 --fo

Please note - it skips weekends but it will show as failed download on holidays at the end

From python code

from datetime import date
from jugaad_data.nse import bhavcopy_save, full_bhavcopy_save, bhavcopy_fo_save, bhavcopy_index_save

bhavcopy_save(date(2020,1,1), "/path/to/directory")
full_bhavcopy_save(date(2020,1,1), "/path/to/directory")
bhavcopy_fo_save(date(2020,1,1), "/path/to/directory")
bhavcopy_index_save(date(2020,1,1), "/path/to/directory")

Download historical stock data

As CSV file from command line

$ jdata stock -s SBIN -f 2020-01-01 -t 2020-01-31 -o SBIN-Jan.csv

List of options-

Options:
  -s, --symbol TEXT  Stock symbol  [required]
  -f, --from TEXT    From date - yyyy-mm-dd  [required]
  -t, --to TEXT      From date - yyyy-mm-dd  [required]
  -S, --series TEXT  Series - EQ, BE etc.  [default: EQ]
  -o, --output TEXT  Full path for output file
  --help             Show this message and exit.

From python code

from datetime import date
from jugaad_data.nse import stock_csv, stock_df, stock_raw

# Download as csv file
stock_csv(symbol="SBIN", from_date=date(2020,1,1),
            to_date=date(2020,1,30), series="EQ", output="/path/to/file.csv")

# Download as pandas dataframe
df = stock_df(symbol="SBIN", from_date=date(2020,1,1),
            to_date=date(2020,1,30), series="EQ")

# Download raw json as received from NSE server
j = stock_raw(symbol="SBIN", from_date=date(2020,1,1),
            to_date=date(2020,1,30), series="EQ")

You will need to install pandas separately for downloading as pandas dataframe

Download historical F&O data

Download historical data for both futures and options of stocks and indices

As CSV file from command line

Refer instrument types1 for more details on -i option

Download stock futures data for SBIN with expiry on 30 Jan 2020

  $ jdata derivatives -s SBIN -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i FUTSTK -o file_name.csv

Download index futures data for NIFTY with expiry on 30 Jan 2020

  $ jdata derivatives -s NIFTY -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i FUTIDX -o file_name.csv

Download stock Call options data for SBIN with expiry on 30 Jan 2020 and at strike price of 300

  $ jdata derivatives -s SBIN -f 2020-01-01 -t 2020-01-30 -e 2020-01-30 -i OPTSTK -p 330 --ce -o file_name.csv

Download index Put options data for “NIFTY” with expiry on 23 Jan 2020 and at strike price of 11000

  $ jdata derivatives -s NIFTY -f 2020-01-01 -t 2020-01-23 -e 2020-01-23 -i OPTIDX -p 11000 --pe -o file_name.csv

List of all options

Options:
  -s, --symbol TEXT  Stock/Index symbol  [required]
  -f, --from TEXT    From date - yyyy-mm-dd  [required]
  -t, --to TEXT      To date - yyyy-mm-dd  [required]
  -e, --expiry TEXT  Expiry date - yyyy-mm-dd  [required]
  -i, --instru TEXT  FUTSTK - Stock futures, FUTIDX - Index Futures, OPTSTK -
                     Stock Options, OPTIDX - Index Options  [required]

  -p, --price TEXT   Strike price (Only for OPTSTK and OPTIDX)
  --ce / --pe        --ce for call and --pe for put (Only for OPTSTK and
                     OPTIDX)

  -o, --output TEXT  Full path of output file
  --help             Show this message and exit.

From python code

from datetime import date
from jugaad_data.nse import derivatives_csv, derivatives_df, derivatives_raw

# Download as csv with stock futures example
derivatives_csv(symbol="SBIN", from_date=date(2020,1,1), to_date=date(2020,1,30),
            expiry_date=date(2020,1,30), instrument_type="FUTSTK",
            output="/path/to/file.csv")

# Download as pandas dataframe with SBIN options as example 
df = derivatives_df(symbol="SBIN", from_date=date(2020,1,1), to_date=date(2020,1,30)
            expiry_date=date(2020,1,30), instrument_type="OPTSTK", 
            option_type="CE", strike_price=300)

# Download raw json as received from NSE server with NIFTY futures as example
j = stock_raw(symbol="NIFTY", from_date=date(2020,1,1), to_date=date(2020,1,30),
            expiry_date=date(2020,1,30), instrument_type="FUTIDX")

You will need to install pandas separately for downloading as pandas dataframe

Download historical index data

As CSV file from command line

$ jdata index -s "NIFTY 50" -f 2020-01-01 -t 2020-01-31 -o SBIN-Jan.csv

List of options-

Options:
  -s, --symbol TEXT  Stock symbol  [required]
  -f, --from TEXT    From date - yyyy-mm-dd  [required]
  -t, --to TEXT      From date - yyyy-mm-dd  [required]
  -o, --output TEXT  Full path for output file
  --help             Show this message and exit.

From python code

from datetime import date
from jugaad_data.nse import index_csv, index_df, index_raw

# Download as csv file
index_csv(symbol="NIFTY 50", from_date=date(2020,1,1),
            to_date=date(2020,1,30), output="/path/to/file.csv")

# Download as pandas dataframe
df = index_df(symbol="NIFTY 50", from_date=date(2020,1,1),
            to_date=date(2020,1,30))

# Download raw json as received from NSE server
j = index_raw(symbol="NIFTY 50", from_date=date(2020,1,1),
            to_date=date(2020,1,30))

Please refer nseindices.com for list of all indices You will need to install pandas separately for downloading as pandas dataframe

API Refernce

stock_csv

stock_csv(symbol, from_date, to_date, series, output)

Arguments-

Returns

stock_df

stock_df(symbol, from_date, to_date, series)

Arguments-

Returns

Remarks

stock_raw

stock_raw(symbol, from_date, to_date, series, output)

Arguments-

Returns

derivatives_csv

def derivatives_csv(symbol, from_date, to_date, expiry_date, instrument_type, option_type. strike_price output)

Arguments-

Returns-

Remarks-

derivatives_df

def derivatives_df(symbol, from_date, to_date, expiry_date, instrument_type, option_type. strike_price)

Arguments-

Returns-

Remarks-

derivatives_raw

def derivatives_raw(symbol, from_date, to_date, expiry_date, instrument_type, option_type. strike_price)

Arguments-

Returns-

Remarks-

Repository

https://github.com/jugaad-py/jugaad-data


  1. Available instrument types

    • FUTSTK - Stock futures
    • FUTIDX - Index futures
    • OPTSTK - Stock options
    • OPTIDX - Index options
    ↩︎