swapniljariwala / nsepy

Python Library to get publicly available data on NSE website ie. stock quotes, historical data, live indices
https://nsepy-xyz.web.app
Other
758 stars 377 forks source link

Issue with nse apis #244

Open sanathramesh opened 1 year ago

sanathramesh commented 1 year ago

NSE has moved its data from old website to the new one. The history apis fail to fetch any data

FaizanKhan06 commented 1 year ago

Having the same problem. Does anybody know till when can it be resolved

itsabinash commented 1 year ago

I was not able to fix the whole thing but I was able to fix Bhav copy downloading.

I replaced the urls of url.py KINDLY TAKE A BACKUP OF ORIGINAL FILE BEFORE DOING THIS.

Replace the content of url.py and "some" features of nsepy will work. This is happening because nse is migrating from old urls to newer ones and everything is not working even on their website.

# -*- coding: utf-8 -*-
"""
Created on Thu Nov 19 20:35:13 2015

@author: SW274998
"""

from nsepy.commons import URLFetch
from requests import Session
from functools import partial
from nsepy.constants import symbol_count, symbol_list

session = Session()
# headers = {
    # 'Host': 'archives.nseindia.com',
    # 'Referer': 'https://archives.nseindia.com/products/content/equities/equities/eq_security.htm'}

headers = {'Accept': '*/*',
           'Accept-Encoding': 'gzip, deflate, sdch, br',
           'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6',
           'Connection': 'keep-alive',
           'Host': 'archives.nseindia.com',
           'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
           'X-Requested-With': 'XMLHttpRequest'}

URLFetchSession = partial(URLFetch, session=session,
                          headers=headers)

NSE_SYMBOL_COUNT_URL = 'http://archives.nseindia.com/marketinfo/sym_map/symbolCount.jsp'

"""
---------------------------------EQUITY--------------------------------------
"""
symbol_count_url = URLFetchSession(
    url='http://archives.nseindia.com/marketinfo/sym_map/symbolCount.jsp')

def get_symbol_count(symbol):
    try:
        return symbol_count[symbol]
    except:
        cnt = symbol_count_url(symbol=symbol).text.lstrip().rstrip()
        symbol_count[symbol] = cnt
        return cnt

"""
#symbol=SBIN&segmentLink=3&symbolCount=1&series=EQ&dateRange=1month&fromDate=&toDate=&dataType=PRICEVOLUMEDELIVERABLE'
"""
equity_history_url_full = URLFetchSession(
    url='http://archives.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp')

"""
symbol="SBIN"
symbolCount=get_symbol_count(SBIN)
series="EQ"
fromDate="dd-mm-yyyy"
toDate="dd-mm-yyyy"
dd = equity_history_url(symbol='SBIN', series="EQ", fromDate="01-01-2017", toDate="01-01-2017")
"""
equity_history_url = partial(equity_history_url_full,
                             dataType='PRICEVOLUMEDELIVERABLE',
                             segmentLink=3, dateRange="")

"""
1. YYYY
2. MMM
3. ddMMMyyyy
"""
price_list_url = URLFetchSession(
    url='https://archives.nseindia.com/content/historical/EQUITIES/%s/%s/cm%sbhav.csv.zip')
    #'https://archives.nseindia.com/content/historical/EQUITIES/%s/%s/cm%sbhav.csv.zip')

"""
1. ddmmyyyy
"""
daily_volatility_url = URLFetchSession(
    url='http://archives.nseindia.com/archives/nsccl/volt/CMVOLT_%s.CSV')
#https://archives.nseindia.com/archives/nsccl/volt/CMVOLT_31032023.CSV

"""
1. ddmmyyyy
"""
daily_deliverypositions_url = URLFetchSession(
    url='https://archives.nseindia.com/archives/equities/mto/MTO_%s.DAT')

"""
1. ddmmyy
"""
pr_price_list_zipped_url = URLFetchSession(
    url='http://archives.nseindia.com/archives/equities/bhavcopy/pr/PR%s.zip')

"""
--------------------------INDICES---------------------------------------
"""
"""
1. indexType=index name
2. fromDate string dd-mm-yyyy
3. toDate string dd-mm-yyyy
"""
index_history_url = URLFetchSession(
    url='http://archives.nseindia.com/products/dynaContent/equities/indices/historicalindices.jsp')

"""
1. ddmmyyyy
"""
index_daily_snapshot_url = URLFetchSession(
    url='https://archives.nseindia.com/content/indices/ind_close_all_%s.csv')

"""
indexName=NIFTY%2050&fromDate=02-11-2015&toDate=19-11-2015&yield1=undefined&yield2=undefined&yield3=undefined&yield4=all
indexName = Index name
fromDate = from date dd-mm-yyyy
toDate = to Date dd-mm-yyyy
"""
index_pe_history_url = partial(
    URLFetchSession(
        url='http://archives.nseindia.com/products/dynaContent/equities/indices/historical_pepb.jsp?'),
    yield1="undefined",
    yield2="undefined",
    yield3="undefined",
    yield4="all")
"""
http://archives.nseindia.com/products/dynaContent/equities/indices/hist_vix_data.jsp?&fromDate=01-Nov-2015&toDate=19-Nov-2015
fromDate = 'dd-Mmm-yyyy'
toDate = 'dd-Mmm-yyyy'
"""
index_vix_history_url = URLFetchSession(
    url='http://archives.nseindia.com/products/dynaContent/equities/indices/hist_vix_data.jsp')

equity_symbol_list_url = URLFetchSession(
    url='https://archives.nseindia.com/content/equities/EQUITY_L.csv')

index_constituents_url = URLFetchSession(
    "https://archives.nseindia.com/content/indices/ind_%slist.csv")

"""
--------------------------DERIVATIVES---------------------------------------
"""
derivative_expiry_dates_url = URLFetchSession(
    url='http://archives.nseindia.com/products/resources/js/foExp.js')

"""
instrumentType=FUTIDX
symbol=NIFTY
expiryDate=26-11-2015
optionType=select
strikePrice=
dateRange=15days
fromDate= 01-Nov-2015
toDate=19-Nov-2015
segmentLink=9&
symbolCount=
"""
derivative_history_url = partial(
    URLFetchSession(
        url='http://archives.nseindia.com/products/dynaContent/common/productsSymbolMapping.jsp?',
        headers = {**headers, **{'Referer': 'https://archives.nseindia.com/products/content/derivatives/equities/historical_fo.htm'}}
        #headers = (lambda a,b: a.update(b) or a)(headers.copy(),{'Referer': 'https://archives.nseindia.com/products/content/derivatives/equities/historical_fo.htm'})
        ),
    segmentLink=9,
    symbolCount='')
"""
http://archives.nseindia.com/content/historical/DERIVATIVES/2015/NOV/fo18NOV2015bhav.csv.zip
1.year yyyy
2.Month MMM
3.date ddMMMyyyy

"""
derivative_price_list_url = URLFetchSession(
    url="http://archives.nseindia.com/content/historical/DERIVATIVES/%s/%s/fo%sbhav.csv.zip")

"""
--------------------------CURRENCY---------------------------------------
"""
"""
fromDate dd-mm-yyyy (from date)
toDate dd-mm-yyyy (to date)
"""
rbi_rate_history_url = URLFetchSession(
    "https://archives.nseindia.com/products/dynaContent/derivatives/currency/fxRbiRateHist.jsp")

urls.zip

FaizanKhan06 commented 1 year ago

can u change for the get history function for the normal equity close prices and the future data mainly Open Interest

Keval2124 commented 1 year ago

http://archives.nseindia.com/marketinfo/sym_map/symbolCount.jsp It is not working 404 error coming

pannet1 commented 1 year ago

trying this new url

Harsh-github-account commented 1 year ago

@pannet1 let us know if it works

Keval2124 commented 1 year ago

@pannet1 it does not work

alloc7260 commented 1 year ago

Use this insted : NSE-HISTORY-SCRAPER

pratik141 commented 1 year ago

created a new project for New NSE API

https://github.com/pratik141/nsedt

Soon add other APIs also