Search code examples
python-3.xfinancestock

Python, National Stock Exchange, Stock Market, nsepy, nsetools api


I am trying to make a Python program to get real-time stock/share prices of the National Stock Exchange. For this, I am using NSETOOLS API. Here is my code for that:

from nsetools import Nse
info = nse.get_quote('RELIANCE')
print(info)
print("Last Traded Price: ", info["lastPrice"])

But I am not getting the Last Traded Price of stock in real-time.

Please help me with that.

My targets are: 1) Getting Last Traded Price of the stock in real-time


Solution

  • Use while loop with time.sleep(seconds) Also, you will have to define nse, use this: nse = Nse()

    from nsetools import Nse
    import time 
    nse = Nse()
    info = nse.get_quote('RELIANCE')
    i = 1
    while i == 1:
    print(info)
    print("Last Traded Price: ", info["lastPrice"])
    time.sleep(5)