sdabhi23 / bsedata

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

Error while Fetching data from BSE #14

Closed srinathpriya closed 1 year ago

srinathpriya commented 4 years ago

I am using the below code to fetch data from BSE but I am getting error. Not sure the reason for the error need help. Thanks

=======================CODE============================== from pprint import pprint from bsedata.bse import BSE b = BSE() print (b)

b.getQuote('541151') pprint(b) =========================ERROR=================================== Driver Class for Bombay Stock Exchange (BSE) Traceback (most recent call last): File "D:\Data\BSE Test.py", line 9, in b.getQuote('541151') File "C:\Users\srinath\AppData\Local\Programs\Python\Python38\lib\site-packages\bsedata\bse.py", line 60, in getQuote return quote.quote(scripCode) File "C:\Users\srinath\AppData\Local\Programs\Python\Python38\lib\site-packages\bsedata\quote.py", line 96, in quote if res['priceBand'] != '': KeyError: 'priceBand'

genos186 commented 1 year ago

Hey, I'm facing the same issue as u, how did u resolve it? pls let me know, thanks in advance

sdabhi23 commented 1 year ago

@genos186 can you please share the scrip code you are getting the issue for? If you can also share a stacktrace and open a new issue, it would be great!

genos186 commented 1 year ago
q=b.getQuote('500002') 
print(q)

The scrip code used is for ABB company, which is an active company. For the above piece of code, I'm getting error as follows:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-7-af34d2740b49> in <module>
----> 1 q=b.getQuote('534976')
      2 pprint(q)

1 frames
/usr/local/lib/python3.8/dist-packages/bsedata/quote.py in quote(scripCode)
    104             continue
    105 
--> 106     if res['priceBand'] != '':
    107         for tbody in soup('tbody'):
    108             try:

KeyError: 'priceBand'
SourabhKG commented 1 year ago

any solution for this

adith7801 commented 1 year ago

Please provide a solution for this issue. Stuck because of this and please let me know if there are any alternative to get the value of securityID key

genos186 commented 1 year ago

If u guys want BSE data then, we would have to fix the source code of the bse library, currently no solution for that. But if u guys want stock details of NSE stocks that consist of the same stocks, then u can use nsetools

adith7801 commented 1 year ago

Hi @genos186, Just to confirm once again, i need the securityID key (For info, listed below a Screenshot). Please suggest me any other way to find that key. image

genos186 commented 1 year ago

In nsetools library, u can use the function called get_stock_codes(), where the "symbol" column is similar to "securityID" in bsedata library.

from nsetools import Nse
import pandas as pd

nse=Nse()
stocks=pd.Series(nse.get_stock_codes())
stocks

Output:

SYMBOL                                 NAME OF COMPANY
20MICRONS                           20 Microns Limited
21STCENMGM    21st Century Management Services Limited
360ONE                             360 ONE WAM LIMITED
3IINFOLTD                          3i Infotech Limited
                                ...                   
ZOTA                          Zota Health Care LImited
ZUARI                     Zuari Agro Chemicals Limited
ZUARIIND                      ZUARI INDUSTRIES LIMITED
ZYDUSLIFE                   Zydus Lifesciences Limited
ZYDUSWELL                       Zydus Wellness Limited
Length: 1869, dtype: object

For ur example of V-mart company from nsetools, we get the same security code but with different key name called 'SYMBOL':

stocks[stocks=='V-Mart Retail Limited'].index[0]

Output:

'VMART'
sdabhi23 commented 1 year ago

just published a new version on pypi, which should fix this issue. please upgrade to the latest version.