GithubHelp home page GithubHelp logo

vsjha18 / nsetools Goto Github PK

View Code? Open in Web Editor NEW
770.0 770.0 410.0 870 KB

Realtime Data From National Stock Exchange (India)

Home Page: http://nsetools.readthedocs.io

License: MIT License

Python 100.00%

nsetools's People

Contributors

abhijitmamarde avatar altendky avatar arkits avatar howdyauthors avatar skyrocknroll avatar swapniel99 avatar vsjha18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsetools's Issues

cant install nsetools

I am trying to install nsetools on my macbook. I used command pip install nsetools . I received the error "file "", line1 invalid syntax". I am using Python 2.7.0

AttributeError: 'NoneType' object has no attribute 'group'

Hi All,
Since from last friday(11/Jan/2019) I am getting the below error. Earlier my code was working perfect, any idea how to fix it. Thanks!

File "C:\Python36\lib\site-packages\nsetools\nse.py", line 161, in get_quote
buffer = match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

option market data

hi

is it possible to have option data for different strikes in nifty?

New feature: Fetching Option chain data

Have recently came across one requirement of, fetching option chain data from nse site via python, and naturally I first check whether it was already available in nsetools! Since it was not there, I coded the same. Now I want to add/contribute it to nsetools.

But, it uses BeautifulSoup and hence would break one of the nsetools main feature, which is not depending on any other third party package. But if you can still allow to make this distinction (or loose this restriction going forward) I would more than happy to add this/integrate this feature to nsetools.

If you are okay, would need to work out a little more to make it generalise (have worked only for nifty for now) and to add basic unit test.

Do let me know your thoughts on this!

ValueError while fetching fno lot sizes

nse.get_fno_lot_sizes()
Traceback (most recent call last):
  File "/anaconda3/envs/securitymaster/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-1622ec023583>", line 1, in <module>
    nse.get_fno_lot_sizes()
  File "/anaconda3/envs/securitymaster/lib/python3.6/site-packages/nsetools/nse.py", line 88, in get_fno_lot_sizes
ValueError: invalid literal for int() with base 10: ''

php Port

Hi,

I am trying to get this working in PHP. I am new to PHP and beginer in python. The reason I am porting it to PHP is because Python based hosting needs VPS which is more expensive than shared hosting which usually comes with PHP.

I have done this


> <?php
> 
> $get_quote_url = "http://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?";
> 
> $headers = array();
> $headers[] = 'Accept:*/*';
> $headers[] = 'Accept-Language: en-US,en;q=0.5';
> $headers[] = 'Host: nseindia.com';
> $headers[] = 'Referer: http://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=INFY&illiquid=0';
> $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0';
> $headers[] = 'X-Requested-With: XMLHttpRequest';
> 
> $illiquid = "0";
> $code = "HIKAL";
> $query_string = 'symbol=' . urlencode($code) . '&illiquid=' . urlencode($illiquid);
> $request_url = $get_quote_url. $query_string;
> 
> 
> 
> $cookie = tmpfile();
> $userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31' ;
> 
> $ch = curl_init($request_url);
> curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
> 
> $options = array(
>     CURLOPT_CONNECTTIMEOUT => 20 , 
>     CURLOPT_USERAGENT => $userAgent,
>     CURLOPT_AUTOREFERER => true,
>     CURLOPT_FOLLOWLOCATION => true,
>     CURLOPT_RETURNTRANSFER => true,
>     CURLOPT_COOKIEFILE => $cookie,
>     CURLOPT_COOKIEJAR => $cookie ,
>     CURLOPT_SSL_VERIFYPEER => 0 ,
>     CURLOPT_SSL_VERIFYHOST => 0
> );
> 
> curl_setopt_array($ch, $options);
> $kl = curl_exec($ch);
> curl_close($ch);
> echo $kl;
> 
> ?>

Do you think I am structuring the request like you do in Python or am I missing something ?

Corporate Action Data

Along with bhavcopy, we also need corporate action data. To adjust historical prices according to splits and bonuses.

Not getting quotes using python 2.7.8

I've tried this using the code below, in Spyder 2 with python 2.7.8 as apart of Anaconda distribution. OS is Win8 64bit. The last line, i.e getting quotes throws an error. I had installed nsetool using pip.

from nsetools import Nse
nse = Nse()
print nse
q = nse.get_quote('infy')

This throws the following error

Traceback (most recent call last):
File "", line 1, in
File "D:\Anaconda\lib\site-packages\nsetools\nse.py", line 109, in get_quote
response = self.clean_server_response(ast.literal_eval(match.group(1))['data'][0])
File "D:\Anaconda\lib\ast.py", line 80, in literal_eval
return _convert(node_or_string)
File "D:\Anaconda\lib\ast.py", line 63, in _convert
in zip(node.keys, node.values))
File "D:\Anaconda\lib\ast.py", line 62, in
return dict((_convert(k), _convert(v)) for k, v
File "D:\Anaconda\lib\ast.py", line 60, in _convert
return list(map(_convert, node.elts))
File "D:\Anaconda\lib\ast.py", line 63, in _convert
in zip(node.keys, node.values))
File "D:\Anaconda\lib\ast.py", line 62, in
return dict((_convert(k), _convert(v)) for k, v
File "D:\Anaconda\lib\ast.py", line 79, in _convert
raise ValueError('malformed string')
ValueError: malformed string

Getting Adjusted Price

Currently, the API doesn't provide Adjusted Close price data for any NSE symbol(as it pulls the data from NSE website directly). Yahoo finance provides Adj. Close price for all nse symbols. Is it possible to integrate to support Adj Close px ?

Attribute error in get_quote

/usr/local/lib/python3.5/dist-packages/nsetools/nse.py in get_quote(self, code, as_json)
ast can raise SyntaxError, let's catch only this error
try:
     buffer = match.group(1)
     buffer = js_adaptor(buffer)
     response = self.clean_server_response(ast.literal_eval(buffer)['data'][0])
AttributeError: 'NoneType' object has no attribute 'group'

How do I address this, it appears randomly after few iterations (interval 2mins). Thanks.

Failed to download data in Ubuntu machine

Hi,

I have observed a strange behavior, when I used this library in my Ubuntu machine during 11.00pm to 11.00am, (India time) I failed to get any data with below code -

q = nse.get_quote('infy')

But, if I try the same in my Mac and during the same time, I get perfect result -

>>> q = nse.get_quote('infy')
>>> q
{'sellPrice3': None, 'dayHigh': 720.7, 'sellPrice1': 702.1, 'totalSellQuantity': 1839.0, 'sellPrice5': None, 'css_status_desc': 'Listed', 'ndEndDate': None, 'applicableMargin': 12.5, 'marketType': 'N', 'previousClose': 721.05, 'bcEndDate': None, 'totalTradedVolume': 11112042.0, 'priceBand': 'No Band', 'secDate': '12-Dec-2019 00:00:00', 'exDate': '23-OCT-19', 'sellQuantity4': None, 'sellQuantity5': None, 'cm_ffm': 257125.48, 'pChange': u'-2.63', 'open': 718.5, 'securityVar': 7.18, 'sellQuantity2': None, 'sellQuantity3': None, 'closePrice': 702.1, 'pricebandupper': 793.15, 'extremeLossMargin': 5.0, 'sellPrice4': None, 'sellQuantity1': 1839.0, 'buyPrice4': None, 'buyPrice5': None, 'low52': 615.1, 'deliveryToTradedQuantity': 42.31, 'buyPrice1': None, 'buyPrice2': None, 'buyPrice3': None, 'buyQuantity1': None, 'recordDate': '24-OCT-19', 'buyQuantity3': None, 'buyQuantity2': None, 'buyQuantity5': None, 'buyQuantity4': None, 'isExDateFlag': False, 'totalBuyQuantity': None, 'lastPrice': 702.1, 'companyName': 'Infosys Limited', 'bcStartDate': None, 'symbol': 'INFY', 'deliveryQuantity': 4701874.0, 'sellPrice2': None, 'purpose': 'INTERIM DIVIDEND - RS 8 PER SHARE', 'indexVar': None, 'varMargin': 7.5, 'change': u'-18.95', 'surv_indicator': None, 'quantityTraded': 11112042.0, 'isinCode': 'INE009A01021', 'adhocMargin': None, 'high52': 847.0, 'pricebandlower': 648.95, 'faceValue': 5.0, 'series': 'EQ', 'dayLow': 699.55, 'basePrice': 721.05, 'ndStartDate': None, 'totalTradedValue': 78453.24, 'averagePrice': 706.02, 'cm_adj_high_dt': '06-SEP-19', 'cm_adj_low_dt': '23-OCT-19'}

Both are working fine during other time i.e. from 11.00 am to 11.00pm

Has anybody observed similar situation? Is there any solution to this peculiar problem?

Thanks for any pointer.

NSE Data is no longer able to access since last week

I am trying to fetch the live data of stocks.I think because a new nse website is launched the old website data cannot be fetched.Can any one help me out. I am getting the following result when I print the nse stockcodes.

{'', '<meta name="viewport" content="width=device-width': ' initial-scale=1.0', '', ' var dom': 'doc', ' win.addEventListener("load"': ' boomerangSaveLoadTime', ' win.attachEvent("onload"': ' boomerangSaveLoadTime);', ' where.parentNode.insertBefore(iframe': ' where);', ' window.headerData = {"marketStatus":{"marketState":[{"market":"Capital Market"': '"marketStatus":"Close"', ' <script>(function(w': 'd', '
new Date().getTime()': "event:'gtm.js'});var f=d.getElementsByTagName(s)[0]", ' j=d.createElement(s)': "dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=", " 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j": 'f);', ' })(window': 'document', '

YOU ARE ON THE NEW NSE WEBSITE': ' ACCESS THE OLD WEBSITE ON THE URL www1.nseindia.com OR CLICK HERE
', ' title="NSE India': ' National Stock Exchange">', ' ', ' 12': '256.80', '

Live Analysis of top gainers/losers': ' most active securities/contracts', '

Browse NSE products under Cash': ' derivatives', '

Important information': ' reference material and latest announcements for corporates

', ' href="/trade/deposits-networth-requirements-for-membership">Fees': '
Deposits & Networth', '

Important Information': ' reference
materials and latest announcements for members.

', '

Browse Exchange circulars': ' press release and media articles.

', '

Dashboard for end of day reports download':
' quick market snapshot and important announcements.

', ' Multiple file Download ', ' Multiple file Download ', ' Multiple file Download ', '

As on 1st Jan 2019': ' 16:00 IST

', '

As on 1st Jan 2019': ' 16:00 IST

'}

Error : "code must be string"

Following errors was reported while i was trying to extract data for "INFY".

url = self.build_url_for_quote(code)

For this line of code :

q = nse.get_quote("INFY"), i can provide more information, if you need, anyone else doesn't seem to be having same error.

Getting Lot Sizes

nse.get_fno_lot_sizes() is not returning the desired output. Anything is broken or NSE changed anything from their side?

Not able to use nsetools on mac

I am not able to use nsetools on Mac OS X 10.11.6.

  • Installed nsetools as shown below:-
sudo pip install nsetools
Password:
The directory '/Users/debraj/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/debraj/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nsetools
 Downloading nsetools-1.0.5.tar.gz
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from nsetools)
Installing collected packages: nsetools
 Running setup.py install for nsetools ... done
Successfully installed nsetools-1.0.5
  • On trying to use nsetools I am getting the below error:-
python
Python 2.7.11 (default, Jan 22 2016, 16:30:50) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nsetools import Nse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/nsetools/__init__.py", line 25, in <module>
    from .nse import Nse
  File "/Library/Python/2.7/site-packages/nsetools/nse.py", line 26, in <module>
    import six
ImportError: No module named six

Even though six is already installed as shown below:-

sudo -H pip install six
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

Unable to import nsetools

I had installed nsetools using this command: pip install nsetools

But I'm getting this error
$ python -c "from nsetools import Nse"
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named nsetools

urllib.error.HTTPError: HTTP Error 403: Forbidden

Issue in nse.get_quote('infy'). Can you check it?
Traceback (most recent call last):
File "nse.py", line 466, in
print(n.get_quote('infy'))
File "nse.py", line 154, in get_quote
if self.is_valid_code(code):
File "nse.py", line 140, in is_valid_code
stock_codes = self.get_stock_codes()
File "nse.py", line 119, in get_stock_codes
res = self.opener.open(req)
File "/usr/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

ImportError: cannot import name Nse

Received the following stacktrace while running code from API Walkthrough

Traceback (most recent call last):
File "nsetools.py", line 1, in
from nsetools import Nse
File "/home/g/c/nsetools/nsetools.py", line 1, in
from nsetools import Nse
ImportError: cannot import name Nse

>>> from nsetools import Nse
>>> nse = Nse()
>>> print nse

get_quote gets stuck

I am using get_quote in a loop. It gets stuck after few calls and hangs.
It works for small loops, but for anything above 50 calls in loop is an issue. Also, this doesnt always happen.

Please suggest workaround

Negative percent change shows as None

On retrieving the quotes using nse.get_quotes() whenever a company has a negative percentage change in stock price, the key pChange has a value of None

The example below tries to show the problem:

from nsetools import Nse

nse = Nse()

top_loser_list = nse.get_top_losers()
 
loser_quote_list = []
for item in top_loser_list:
    loser_quote_list.append(
        nse.get_quote(item['symbol'])
    )

count = 0
for quote in loser_quote_list:
    if quote['pChange'] is None:
        count += 1

if len(loser_quote_list) == count:
    print('Problem?')

The same problem does not occur when a company is gaining (i.e. the percentage change is positive)

Lagged Data

Hi,
I matched with yahoo finance and Kite of zerodha . I think there is lag in prices
So can you confirm me this is rolled up if then how many minutes

Change in fegex format for dict.

Removed the starting curly brace as nseindia has removed the extra '{'.

Current Regex: r'\{<div\s+id="responseDiv"\s+style="display:none">\s+(\{.*?\{.*?\}.*?\})',*

Updated Regex: r'<div\s+id="responseDiv"\s+style="display:none">\s+(\{.*?\{.*?\}.*?\})',

Fetching quote in batches

the get_quote function only takes in one code which in my usecase results in multiple network calls with latency, making my application painfully slow. It would be ideal if multiple codes could be specified once and the network calls done in batch to reduce latency.

Error for Stock Symbol - OMNITECH

The get_quote function is working great with most Stock Symbols, for example:

from nsetools import Nse
nse=Nse()
nse.get_quote('SANCO',as_json=True)
'{"sellPrice3": null, "sellPrice2": null, "sellPrice1": 117.45, "adhocMargin": null, "sellPrice5": null, "sellPrice4": null, "ndEndDate": null, "series": "EQ", "marketType": "N", "previousClose": 111.9, "priceBand": 5.0, "secDate": "25NOV2016", "cm_adj_low_dt": "22-NOV-16", "totalTradedValue": 46.68, "sellQuantity4": null, "sellQuantity5": null, "securityVar": null, "pChange": 2.77, "open": 110.0, "cm_ffm": null, "sellQuantity2": null, "sellQuantity3": null, "closePrice": 115.8, "pricebandupper": 117.45, "extremeLossMargin": 5.0, "sellQuantity1": 50.0, "buyPrice4": 108.25, "buyPrice5": 106.35, "low52": 101.0, "faceValue": 10.0, "isExDateFlag": false, "buyPrice2": 113.0, "applicableMargin": 48.3, "buyQuantity1": 1000.0, "recordDate": null, "buyQuantity3": 5.0, "buyQuantity2": 800.0, "buyQuantity5": 200.0, "buyQuantity4": 100.0, "buyPrice1": 114.0, "bcEndDate": null, "totalBuyQuantity": 2105.0, "lastPrice": 115.0, "companyName": "Sanco Industries Limited", "bcStartDate": null, "symbol": "SANCO", "buyPrice3": 108.35, "deliveryQuantity": 40157.0, "change": 3.1, "purpose": null, "indexVar": 25.0, "varMargin": 43.3, "deliveryToTradedQuantity": 99.43, "totalSellQuantity": 50.0, "quantityTraded": 40386.0, "isinCode": "INE782L01012", "css_status_desc": "Listed", "high52": 117.4, "totalTradedVolume": 40386.0, "dayHigh": 117.4, "dayLow": 109.05, "ndStartDate": null, "pricebandlower": 106.35, "averagePrice": 115.59, "cm_adj_high_dt": "25-NOV-16", "exDate": null}'

But it errors out for Symbol - OMNITECH:

nse.get_quote('OMNITECH',as_json=True)
Traceback (most recent call last):
File "", line 1, in
File "/home/vagrant/.local/lib/python2.7/site-packages/nsetools/nse.py", line 130, in get_quote
raise Exception('ill formatted response')
Exception: ill formatted response

derivatives LTP

Please help. I wish to get last traded price OR quotation using GET_QUOTE
for FUTURE and OPTION Segment.
i.e. Price for NIFTY 27-DEC-2018 FUT STOCK

Please advice.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.