Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'priceBand' in getQuote #36

Closed
vignesh-r2 opened this issue Mar 6, 2023 · 5 comments · Fixed by #37
Closed

KeyError: 'priceBand' in getQuote #36

vignesh-r2 opened this issue Mar 6, 2023 · 5 comments · Fixed by #37

Comments

@vignesh-r2
Copy link

vignesh-r2 commented Mar 6, 2023

>>> from bsedata.bse import BSE
>>> bse = BSE(update_codes=True)
>>> bse.getQuote("516072")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/bsedata/bse.py", line 61, in getQuote
    return quote.quote(scripCode)
  File "/usr/local/lib/python3.7/site-packages/bsedata/quote.py", line 106, in quote
    if res['priceBand'] != '':
KeyError: 'priceBand'

the package seems to be raising this new error.

@genos186
Copy link

Yeah faced the same issue.
If u want company stock data, u can another library called nsetools.
nsetools is capable of fetching real-time live data of the given stock, as such:

from nsetools import Nse
n=Nse().get_quote('INFY')
print(n)

The output generated is, as such:

{'pricebandupper': 1628.4,
 'symbol': 'INFY',
 'applicableMargin': 13.48,
 'bcEndDate': None,
 'totalSellQuantity': None,
 'adhocMargin': None,
 'companyName': 'Infosys Limited',
 'marketType': 'N',
 'exDate': '27-OCT-22',
 'bcStartDate': None,
 'css_status_desc': 'Listed',
 'dayHigh': 1474.3,
 'basePrice': 1480.4,
 'securityVar': 9.98,
 'pricebandlower': 1332.4,
 'sellQuantity5': None,
 'sellQuantity4': None,
 'sellQuantity3': None,
 'cm_adj_high_dt': '17-MAR-22',
 'sellQuantity2': None,
 'dayLow': 1457.65,
 'sellQuantity1': None,
 'quantityTraded': 3699580.0,
 'pChange': '-0.44',
 'totalTradedValue': 54300.22,
 'deliveryToTradedQuantity': 71.9,
 'totalBuyQuantity': 610.0,
 'averagePrice': 1467.74,
 'indexVar': None,
 'cm_ffm': 538738.92,
 'purpose': 'INTERIM DIVIDEND - RS 16.50 PER SHARE',
 'buyPrice2': None,
 'secDate': '10-Mar-2023 00:00:00',
 'buyPrice1': 1471.55,
 'high52': 1923.3,
 'previousClose': 1480.4,
 'ndEndDate': None,
 'low52': 1355.0,
 'buyPrice4': None,
 'buyPrice3': None,
 'recordDate': '28-OCT-22',
 'deliveryQuantity': 2660153.0,
 'buyPrice5': None,
 'priceBand': 'No Band',
 'extremeLossMargin': 3.5,
 'cm_adj_low_dt': '26-SEP-22',
 'varMargin': 9.98,
 'sellPrice1': None,
 'sellPrice2': None,
 'totalTradedVolume': 3699580.0,
 'sellPrice3': None,
 'sellPrice4': None,
 'sellPrice5': None,
 'change': '-6.45',
 'surv_indicator': None,
 'ndStartDate': None,
 'buyQuantity4': None,
 'isExDateFlag': False,
 'buyQuantity3': None,
 'buyQuantity2': None,
 'buyQuantity1': 610.0,
 'series': 'EQ',
 'faceValue': 5.0,
 'buyQuantity5': None,
 'closePrice': 1471.55,
 'open': 1460.0,
 'isinCode': 'INE009A01021',
 'lastPrice': 1473.95}

@sdabhi23
Copy link
Owner

@genos186 nsetools gets data from NSE, which is a completely different stock exchange. Been able to reproduce this, looks like BSE has removed priceband data from their website probably. Will push a new release in a few days

@Kavinilavuj05
Copy link

Hi Team,
I'm facing similar issue while fetching the stock price and market price of bse datas from money control

KeyError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_17308\3051095457.py in
----> 1 q = b.getQuote('534976')

~\Anaconda3\lib\site-packages\bsedata\bse.py in getQuote(self, scripCode)
59 :raises InvalidStockException: Raised for stocks which have been suspended or no longer trading on BSE
60 """
---> 61 return quote.quote(scripCode)
62
63 def getIndices(self, category):

~\Anaconda3\lib\site-packages\bsedata\quote.py in quote(scripCode)
104 continue
105
--> 106 if res['priceBand'] != '':
107 for tbody in soup('tbody'):
108 try:

KeyError: 'priceBand'

Please let me know what is the reason and how we can fix this issue?

Its bit urgent

@sdabhi23
Copy link
Owner

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

@Kavinilavuj05
Copy link

Thank u so much
Its working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants