0

I want to get NSE stocks only. I m using to get multiple stocks quotes with a symbol in python.

code:

from nsetools import Nse

nse = Nse()

def get_current(stock):
    return nse.get_quote(stock)

for i in stocks:
        data = get_current(i)

This doesn't help. please help

Sandeep Sharma
  • 639
  • 2
  • 9
  • 34

1 Answers1

5

You need to fetch a list of quotes. Something like this perhaps:

from nsetools import Nse
nse = Nse()
stocks = ['INDUSINDBK', 'SHREECEM']
data = [nse.get_quote(stock) for stock in stocks]

Edit: to just get last price per symbol, you can do:

symbol2price = {stock:nse.get_quote(stock)['lastPrice'] for stock in stocks}

which would then contain the symbols mapping to the last price, like so:

>>> symbol2price
{'INDUSINDBK': 510.25, 'SHREECEM': 21598.0}
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147