UnboundLocalError in nse_quote_meta function

from nsepython import *
from alice_blue import *
import logging
import sys
import pandas as pd


# Debug information
# logger = logging.getLogger()
# logger.setLevel(logging.INFO)

def nse_custom_function_secfno(symbol,attribute="lastPrice"):
    # positions = nsefetch('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O')
    positions = nsefetch('https://www.nseindia.com/api/quote-equity?symbol='+symbol)
    endp = len(positions['priceInfo'])
    for x in range(0, endp):
        if(positions['priceInfo'][x]['symbol']==symbol.upper()):
            return positions['data'][x][attribute]

today_date = datetime.datetime.date(datetime.datetime.today())
Time = datetime.datetime.now()
Current_Time = Time.strftime("%H:%M")
# sys.stdout=open(str(today_date)+'_'+str(Current_Time) + ".txt","w")

print ("Golden Ratio Strategy")
print("today_date", today_date)
print("Current Time:",Current_Time)

# Get the Previous Day OHLC data
# Define a funciton to get the golden number and buyabove sell below data
# def goldennumber():
# define as global valriables
global buy_above
global sell_below

end_date = datetime.datetime.now().strftime("%d-%m-%Y")
end_date = str(end_date)

start_date = (datetime.datetime.now() - datetime.timedelta(days=365)).strftime("%d-%m-%Y")
start_date = str(start_date)

symbol = "TCS"
series = "EQ"

df = equity_history(symbol, series, start_date, end_date)
df = df.sort_values(by='mTIMESTAMP', key=pd.to_datetime,ascending=False) # CH_TIMESTAMP
# print(df)
# print(df.head())
# df.to_csv('gn.csv',index=False)


quote = nse_quote(symbol)
for i in quote['info']:
    print('============',i)

print()
meta = nse_quote_meta(symbol,"","-",0)
for i in meta:
    print('-----------',i)

previous_day_high = df['CH_TRADE_HIGH_PRICE'].iloc[0]
previous_day_low = df['CH_TRADE_LOW_PRICE'].iloc[0]
previous_day_close = df['CH_CLOSING_PRICE'].iloc[0]

range_high = previous_day_high # df['highPrice']
range_low = previous_day_low # bn_info['lowPrice']
opening_range = float(range_high) - float(range_low)

#Calculate the Golden Number
golden_number = ((float(previous_day_high) - float(previous_day_low)) + opening_range) * .618


#Get the trade entry values
buy_above = int((float(previous_day_close) + golden_number))
sell_below = int((float(previous_day_close) - golden_number))
print("Close Pice", previous_day_close)
print("Golden Number", str(golden_number))
print("Buy Above:" + str(buy_above))
print('Sell Below:' + str(sell_below))




# goldennumber()

print('Done')

below is error code i am getting:

Traceback (most recent call last):
File “/home/amol/PycharmProjects/nsepython/getmeta.py”, line 57, in
meta = nse_quote_meta(symbol,"","-",0)
File “/home/amol/.local/lib/python3.9/site-packages/nsepython/rahu.py”, line 273, in nse_quote_meta
metadata = i[‘metadata’]
UnboundLocalError: local variable ‘i’ referenced before assignment

Can you try -

meta = nse_quote_meta(symbol,"latest","Fut")

nse_quote_meta() does not work over equities. Its meta for Futures and Options only. Refer - NSEPython Documentation - #108 by dexter

1 Like

Understood, yes it works