sdabhi23 / bsedata

Python library for extracting real-time data from Bombay Stock Exchange (India)
https://bsedata.readthedocs.io/en/latest/
MIT License
100 stars 48 forks source link

Error on getQuote #47

Closed rakeshranjan-iitd closed 6 months ago

rakeshranjan-iitd commented 9 months ago

When I am calling function getQuote with script code 590116 ex: objBSE.getQuote('590116'). I am getting an error:


InvalidStockException Traceback (most recent call last) Cell In[14], line 1 ----> 1 objBSE.getQuote('590116')

File ~/Library/Python/3.9/lib/python/site-packages/bsedata/bse.py:61, in BSE.getQuote(self, scripCode) 55 def getQuote(self, scripCode): 56 """ 57 :param scripCode: A stock code 58 :returns: A dictionary which contain details about the stock 59 :raises InvalidStockException: Raised for stocks which have been suspended or no longer trading on BSE 60 """ ---> 61 return quote.quote(scripCode)

File ~/Library/Python/3.9/lib/python/site-packages/bsedata/quote.py:53, in quote(scripCode) 51 if error_text_element is not None: 52 error_text=error_text_element.text ---> 53 raise InvalidStockException(status=error_text) 54 try: 55 if span['class'][0] == 'srcovalue':

InvalidStockException: Inactive stock

Currently, I am using this library. If you will allow, I can contribute to this library.

sdabhi23 commented 9 months ago

I don't mind you contributing to the library, but I see nothing wrong in the error. The stock has clearly been inactive since 2016. Please explain what the issue is here.

https://m.bseindia.com/StockReach.aspx?scripcd=590116

soumyadipghorai commented 6 months ago

I think the issue is in the following piece of code. As the stock has been inactive since 2016 the value of updt_diff.days would be -2648 as of today. that's why it throws the error. and for the same reason it gives the same error for all the inactive stocks.

Although I don't know the reason behind putting that condition, but removing the condition might fix the bug it seems.

updt_date = soup.find("span", id="strongDate").text.split('-')[1].strip()
updt_diff = dt.strptime(updt_date, "%d %b %y | %I:%M %p") - dt.now()
if updt_diff.days < -7:
    error_text=""
    error_text_element=soup.find("td", id="tdDispTxt")
    if error_text_element is not None:
        error_text=error_text_element.text
    raise InvalidStockException(status=error_text)
sdabhi23 commented 6 months ago

Hey @soumyadipghorai that's the expected behaviour. We don't want to return data for inactive stocks because correct data won't be available.

I am closing this issue and locking it now as it is attracting invalid comments now.