VarunS2002 / Python-NSE-Option-Chain-Analyzer

The NSE has a website which displays the option chain in near real-time. This program retrieves this data from the NSE site and then generates useful analysis of the Option Chain for the specified Index or Stock. It also continuously refreshes the Option Chain and visually displays the trend in various indicators useful for Technical Analysis.
GNU General Public License v3.0
391 stars 204 forks source link

www.nse1india.com will stop from August #1

Closed medknecth closed 3 years ago

medknecth commented 3 years ago

Varun, could you please help in modyfying the code to work with nse new website.

VarunS2002 commented 3 years ago

According to the rules of the new website, using scripts to scrape data is not allowed and they've enforced this by blocking scripts from accessing the site. They've also changed the way the values are calculated. So the new version is a work-in-progress but it might take a while.

medknecth commented 3 years ago

Thats Great, But I got your code to late, by the time nse is changing lay out. If I can be of any help please do let meknow.

VarunS2002 commented 3 years ago

Once I'm done, I'll update the code and close this issue so you'll know.

medknecth commented 3 years ago

Sir, I succeeded in getting data from new website and made the final df as in your code from my code. Now if I am doing modification in your code, getting stucked. Major change is won only tail left. If you allow I can share my code and with your small time our new code logic should be up. Thanks

VarunS2002 commented 3 years ago

You can share the code file here itself so we can test it.

VarunS2002 commented 3 years ago

Can you please drag and drop the .py file here.

VarunS2002 commented 3 years ago

Upload it is as a .txt file as .py file can't be uploaded I'm assuming

medknecth commented 3 years ago

MukeshChauhan.txt

medknecth commented 3 years ago

Upload it is as a .txt file as .py file can't be uploaded I'm assuming

Yes it was not allowed. Uploaded Txt File

VarunS2002 commented 3 years ago

Thanks for the code I'm working on an improved version.

medknecth commented 3 years ago

Great sir, I understand performance wise my code is not much stable but I believe as per new nse sites cookies authentication is must, and nseappid cookie can be used from code. I will be waiting for your time and modifying current code.

On Tue, 1 Sep 2020, 19:51 Varun Shanbhag, notifications@github.com wrote:

Thanks for the code I'm working on an improved version.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/VarunS2002/Python-NSE-Option-Chain-Analyzer/issues/1#issuecomment-684891323, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXNQSFIYVG5LAW7R5FS3U3SDT7PZANCNFSM4QO43EGA .

VarunS2002 commented 3 years ago

Great sir, I understand performance wise my code is not much stable but I believe as per new nse sites cookies authentication is must, and nseappid cookie can be used from code. I will be waiting for your time and modifying current code. On Tue, 1 Sep 2020, 19:51 Varun Shanbhag, @.***> wrote: Thanks for the code I'm working on an improved version. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <#1 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADXNQSFIYVG5LAW7R5FS3U3SDT7PZANCNFSM4QO43EGA .

Since your using the json data instead of scraping I tried this :

import requests, json

headers = {'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) "
                         "Chrome/84.0.4147.89 Safari/537.36"}

res = requests.get("https://www.nseindia.com/api/option-chain-indices?symbol=NIFTY", headers=headers)

with open("data.json", "w") as f:
    json.dump(res.json(), f)

I didn't have to create a cookie to do this. Although the function you wrote to convert the json data to a dataframe is very useful.

VarunS2002 commented 3 years ago

3.0_oop.txt Use this for the time being. Note that this is set to NIFTY and 3 Sep 2020. I'm working on restructuring the code and adding support for other indexes and expiry dates.

medknecth commented 3 years ago

Good Evening Sir, got delayed with office work. You code I tested today it was not so smooth as earlier one reason data from new website. It gave error two times after 15minutes or so ....else stop responding. But data was matching in real time. I tried to replicate same code by changing API url but it did not worked...am I missing some thing here.

VarunS2002 commented 3 years ago

The website was having issues today even the normal page for option chain wasn't loading properly. I guess this is why the old website is still live and working so the old program (2.0) works just fine. The new version

VarunS2002 commented 3 years ago

The new version is ready and is in testing. I'm ironing out the last bugs I can find. Will release it in a day or two.

medknecth commented 3 years ago

Thanks Senior. Also canI have personal email id to ask you some thing on market.

VarunS2002 commented 3 years ago

Thanks Senior. Also canI have personal email id to ask you some thing on market.

Oh no I do not know anything about the market you know more since you're using this program😅. I'm just an IT guy who did this for my boss who gave me the conditions and requirements.

medknecth commented 3 years ago

Same here I too an IT guy, but learned python because of NSE....so that I can see this code works. But with interest in market I got deeply involved and exploring more of python.

VarunS2002 commented 3 years ago

That's nice

VarunS2002 commented 3 years ago

I've committed the new version to the master branch. See if you can find any issues so I'll fix them and then draft a release

medknecth commented 3 years ago

Sir, Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\A967\Anaconda3\lib\tkinter__init.py", line 1705, in call return self.func(*args) File "C:\Users\A967\Anaconda3\lib\tkinter\init.py", line 749, in callit func(*args) File "", line 541, in main df, current_time, self.underlying_stock, self.points = self.get_dataframe() File "", line 360, in get_dataframe response, json_data = self.get_data() File "", line 53, in get_data json_data = response.json() File "C:\Users\A967\Anaconda3\lib\site-packages\requests\models.py", line 897, in json return complexjson.loads(self.text, **kwargs) File "C:\Users\A967\Anaconda3\lib\site-packages\simplejson\init__.py", line 525, in loads return _default_decoder.decode(s) File "C:\Users\A967\Anaconda3\lib\site-packages\simplejson\decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "C:\Users\A967\Anaconda3\lib\site-packages\simplejson\decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After 20 minutes same error, I think data is not available in continuous fashion from new website. Else the older one with old site works perfect as always.

VarunS2002 commented 3 years ago

Did the program crash because of this or did this just show up in the console?

medknecth commented 3 years ago

It shows up in the console, program just go silent and data stops updating.

VarunS2002 commented 3 years ago

I updated the code it should now ignore that error. I earlier added except condition for json decode but apparently anaconda is using a different package for that.

VarunS2002 commented 3 years ago

I have published the new release and updated the documentation. Link to the release. If you face any problems feel free to open a new issue👍. Also thanks for the help in the json to dataframe function.