-2
from pprint import  pprint
from nsetools import Nse
nse = Nse()
q = nse.get_quote('infy')
pprint(q[["totalBuyQuantity","total SellQuantity"]])

Here I'm not able to get my required field with Type Error: unhashable type: 'list'. How to get that plz ???

  • Does this answer your question? [How to get multiple dictionary values?](https://stackoverflow.com/questions/24204087/how-to-get-multiple-dictionary-values) – Pranav Hosangadi Aug 19 '22 at 17:24

1 Answers1

0

q is a dictionary here which contains following keys.

{'pricebandupper': 1741.2,
 'symbol': 'INFY',
 'applicableMargin': 14.5,
 'bcEndDate': None,
 'totalSellQuantity': 2701.0,
 'adhocMargin': None,
 'companyName': 'Infosys Limited',
 'marketType': 'N',
 'exDate': '31-MAY-22',
 'bcStartDate': None,
 'css_status_desc': 'Listed',
 'dayHigh': 1604.9,
 'basePrice': 1582.95,
 'securityVar': 11.0,
 'pricebandlower': 1424.7,
 'sellQuantity5': None,
 'sellQuantity4': None,
 'sellQuantity3': None,
 'cm_adj_high_dt': '17-JAN-22',
 'sellQuantity2': None,
 'dayLow': 1585.1,
 'sellQuantity1': 2701.0,
 'quantityTraded': 4739884.0,
 'pChange': 0.51,
 'totalTradedValue': 75687.89,
 'deliveryToTradedQuantity': 52.28,
 'totalBuyQuantity': None,
 'averagePrice': 1596.83,
 'indexVar': None,
 'cm_ffm': 584614.71,
 'purpose': 'ANNUAL GENERAL MEETING/DIVIDEND - RS 16 PER SHARE',
 'buyPrice2': None,
 'secDate': '19-Aug-2022 00:00:00',
 'buyPrice1': None,
 'high52': 1953.9,
 'previousClose': 1582.95,
 'ndEndDate': None,
 'low52': 1367.15,
 'buyPrice4': None,
 'buyPrice3': None,
 'recordDate': '01-JUN-22',
 'deliveryQuantity': 2477938.0,
 'buyPrice5': None,
 'priceBand': 'No Band',
 'extremeLossMargin': 3.5,
 'cm_adj_low_dt': '17-JUN-22',
 'varMargin': 11.0,
 'sellPrice1': 1597.1,
 'sellPrice2': None,
 'totalTradedVolume': 4739884.0,
 'sellPrice3': None,
 'sellPrice4': None,
 'sellPrice5': None,
 'change': 8.05,
 'surv_indicator': None,
 'ndStartDate': None,
 'buyQuantity4': None,
 'isExDateFlag': False,
 'buyQuantity3': None,
 'buyQuantity2': None,
 'buyQuantity1': None,
 'series': 'EQ',
 'faceValue': 5.0,
 'buyQuantity5': None,
 'closePrice': 1597.1,
 'open': 1585.3,
 'isinCode': 'INE009A01021',
 'lastPrice': 1591.0}

To get the values for the keys you have, you can do this

from nsetools import Nse

nse = Nse()
q = nse.get_quote('infy')
print(list( map(q.get, ["totalBuyQuantity","total SellQuantity"]) )) 

which gives you

[None, None]
Himanshu Poddar
  • 7,112
  • 10
  • 47
  • 93
  • Can you update your answer with entire script plz. Facing difficulty to do the same. – Brijesh Chaurasia Aug 19 '22 at 17:41
  • Sir can you help me if I want same data for multiple symbols (total about 200). What will be the script accordingly plz. Here is the list of all the symbols https://docs.google.com/spreadsheets/d/1ycM9PeE36QR45z_HHjYG0fbtC_R3RSMw5kgjEtj3IKI/edit?usp=drivesdk – Brijesh Chaurasia Aug 19 '22 at 18:11
  • Hi Brijesh, in that case you will have to loop through the symbols and get the key values in each case, I just logged out of my system, can you send out the requirements on my mail and I ll try to get back by Monday, since it's weekend tomorrow – Himanshu Poddar Aug 19 '22 at 18:19
  • My mail is in my profile – Himanshu Poddar Aug 19 '22 at 18:20