Top Gainers API

The Api print(nse_get_top_gainers()) provides only 5 stocks. Is it possible to make it to 30. Can this made variable so that you can fetch number of stocks as per your requirement ? By the way thanks for your time & efforts.


def nse_get_top_losers():
    positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
    df = pd.DataFrame(positions['data'])
    df = df.sort_values(by="pChange")
    return df.head(5)

def nse_get_top_gainers():
    positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
    df = pd.DataFrame(positions['data'])
    df = df.sort_values(by="pChange" , ascending = False)
    return df.head(5)

See the df.head(5) thing?

Change that according to whatever you want.