[Feature Request] Historical Delivery and Quote of Stocks

this solves live needs, however I do think we need the historical too based on the date range input



Should I make it standalone API or make it just a part of the previous historical API. Also, from where on Earth you have stumbled upon this part.

1 Like

Hmm…I will take that second question as compliment :slight_smile:
quest to get volume delivery data per and for a stock, from nseindia lead to that search api (of course using browser dev tools etc helped)

to your first question, I think, since it is a different end point, it is better to have a seperate standalone method for it, so it does not affect any functionality for the existing methods. Its will be a healthy new addition to the growing feature list of nsepython module overall.


Will add in next feature request.

hi @dexter

does this depend on the fix of nsefetch() before the solution is made available?

I am busy writing Gann Square of Nine book. Check → Gann Square of Nine - Artem Kalashnikov - Google Docs

My deadline was 4 months ago. Once I finish it, NSEPython Upgrade is the next task. Because I need it for my copy-trading startup’s backup module.

Expect it to be done by maximum tomorrow.

1 Like

No worries, I am assured you will help with it :slight_smile:

@dexter, just checking if this made into the 2.1 release (or is being cooked?)


Nothing is cooked. Clean slated all stuff at once.

gotcha … thanks for the new package release… appreciate it!

I tried this morning after fetching the latest package of nsepython on my local node

21372137>pip show nsepython | grep -iE 'name|version'
Name: nsepython
Version: 2.1

21372137>python -V
Python 3.10.8

21372137>python -i
Python 3.10.8 (main, Dec 11 2022, 09:35:50) [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nsepython import nsefetch
>>> x=nsefetch("https://www.nseindia.com/api/historical/securityArchives?from=30-07-2022&to=30-07-2023&symbol=HDFCBANK&dataType=priceVolumeDeliverable&series=ALL")
Traceback (most recent call last):
  File "/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib/python3.10/site-packages/nsepython/rahu.py", line 45, in nsefetch
    output2 = requests.get(payload2,headers=headers).json()
  File "lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I have to intentionally and manually go to my chrome browser, establish the connection to the above url and then try again in the same python console and after which it works.

At this point, I am not sure if there is anything I could do but really appreciate your insight and possibly a working approach to this.

thanks again @dexter

No clue. Python when you are running is running standable. If you are visiting the site in chrome, it is storing that cookies in chrome which you are not accessing at all from local computer.

Exactly, so why does python is able to establish and get the connection after the browser connect. Is the connection thread from the program or the host, I am confused, but I will need to check more on this too.

Interesting this, even the params have to match (browser first and then python console) otherwise nsefetch() gets json decode errors.
Is it HTTP/SSL :thinking:

Hey @dexter ,

is there any way I could see live total number of trades executed on any particular stock

Thats called Volume. A stock’s volume is the number of shares traded in a given period .

Volume is everywhere in most API EndPoints.


Incidentally, this lead to a different rabbit hole of SSL world but then I realized I was getting 401 so it cannot be SSL but instead the headers and urls. So, I had to pay attention to the error code and the url stuff, the errors were screaming but needed the listening ears.

Normally, I would have words for the changes, but you have been very helpful these days to many people and a sort of have also become my go to person, as a friend, so I will just call out what I see as is: You, my friend, are losing empathy for the folks in local mode :frowning:

Here are the fixing changes. This will fix it.

--- ../../lib/python3.10/site-packages/nsepython/rahu.py.bak	2023-08-23 23:48:17.000000000 +0530
+++ ../../lib/python3.10/site-packages/nsepython/rahu.py	2023-08-23 23:53:24.000000000 +0530
@@ -36,15 +36,13 @@
             output = requests.get(payload,headers=headers).json()
             try: # Follow Praty's hack as mentioned here at https://forum.unofficed.com/t/solution-equity-history-function-doesnt-work/1197
-                output = requests.session().get(payload,headers=headers).json()
+                output = requests.session().get(payload, headers=headers).json()
             except: #Mimick FrontPage Visit
-                payload2 = "https://www.nseindia.com"
-                output2 = requests.get(payload2,headers=headers).json()
-                output = requests.get(payload,headers=headers).json()
+                landing_url = "https://www.nseindia.com"
+                landing_url_output = s.get(landing_url, headers=headers)
+                # assuming the landing url returned OK content response and hail Mary!
+                output = s.get(payload, headers=headers).json()
         return output

Please take this stub forward and patch it as you see fit, but you know :wink:
I have already got my local file patched and am able to get going but would appreciate the main release to contain the fix (I would rather not maintain any local mods).

thank you again!



I have updated it like a dumb fuck. My code


payload2 = "https://www.nseindia.com"
output2 = requests.get(payload2,headers=headers).json()

output = requests.get(payload,headers=headers).json()

made no sense. I never called the sessions back at the first place. Wait 1 min.

Fixed and updated. Thanks a lot for quick pointout that I had fixed nothing. I don’t use local version so I don’t test it.

Took 90 seconds to upload the new version. Took 120 seconds to reply you here. If I was up to making excuses, then I wouldn’t what I am.

Well, the main landing page does not return json output so you have no necessary need of calling json() method on it.

btw, I do not see it on github yet, may be it takes time to update?

Not that. Different thing.

Yes. Slightly First the package gets updated. Then GitHub. Check now.