and every time we use that access token every time we run a script,we wont need to Login Every Time.
Refer Below for Login Basics and Initial Setup
github Link: https://github.com/kishorekumarganta/How-to-setup-Finvasia-Shoonya-Api-Login-and-Generate-Session
Firstly we need to get the NorenAPI.py file from the C Drive
NorenApi.py Path in C Drive to Get: C:\Users\gkk_I\AppData\Local\Programs\Python\Python310\Lib\site-packages\NorenRestApiPy
We Used API_Helper.py to Tweak NORENAPI
Open API_Helper.py
Try to Find Below Code in API_Helper.py file
class ShoonyaApiPy(NorenApi):
def __init__(self):
NorenApi.__init__(self, host='https://shoonyatrade.finvasia.com/NorenWClientTP/', websocket='wss://shoonyatrade.finvasia.com/NorenWSTP/', eodhost='https://shoonya.finvasia.com/chartApi/getdata/')
global api
api = self
Copy The Below from API_Helper.py host='https://shoonyatrade.finvasia.com/NorenWClientTP/', websocket='wss://shoonyatrade.finvasia.com/NorenWSTP/', eodhost='https://shoonya.finvasia.com/chartApi/getdata/'
Try to Find Below Code in NorenApi.py file
def __init__(self, host, websocket, eodhost):
self.__service_config['host'] = host
self.__service_config['websocket_endpoint'] = websocket
self.__service_config['eoddata_endpoint'] = eodhost
Replace Code in NorenApi.py file with copied data from API_Helper.py
def __init__(self):
self.__service_config['host'] = 'https://shoonyatrade.finvasia.com/NorenWClientTP/'
self.__service_config['websocket_endpoint'] = 'wss://shoonyatrade.finvasia.com/NorenWSTP/'
self.__service_config['eoddata_endpoint'] = 'https://shoonya.finvasia.com/chartApi/getdata/'
Try to Find Below Code in NorenApi.py file
self.__username = userid
self.__accountid = userid
self.__password = password
self.__susertoken = resDict['susertoken']
Below it in the same Indentation Write below Code:
self.__username = userid
self.__accountid = userid
self.__password = password
self.__susertoken = resDict['susertoken']
#our Additional Code Follows here
#Here, we are Storing the Super token we got in shoonyakey.txt file
f=open("shoonyakey.txt",'w')
f.write(resDict['susertoken'])
f.close()
Try to Find Below Code
self.__username = userid
self.__accountid = userid
self.__password = password
self.__susertoken = resDict['susertoken']
#reportmsg(self.__susertoken)
#our Additional Code Follows here
#Here, we are Storing the Super token we got in shoonyakey.txt file
f=open("shoonyakey.txt",'w')
f.write(resDict['susertoken'])
f.close()
return resDict
Also at start
import config
After the above code, we have to define a function token_setter()
def token_setter(self):
token=open("shoonyakey.txt",'r').read().rstrip()
self.__susertoken=token
#after login we set our token directly,so we also to define our username and password
self.__username=config.user
self.__password=config.pwd
self.__accountid=config.user
from NorenApi import NorenApi
import config
shoonya=NorenApi()
#We set the Object
shoonya.login(config.user,config.pwd,config.factor2,config.vc,config.app_key,config.imei)
#check Config FIle for whether we defined these there are not with same names
# from NorenApi
#def login(self, userid, password, twoFA, vendor_code, api_secret, imei):
#REmember to define the Credentials same like Above in Config File.
once we run above File we will get shoonyakey.txt file auto generated and has written the code auto inside it i.e token
Code is Uploaded in files
your Username and Password Must Enter in NorenAPI File Directly, also Update credntials in config during execution
def set_token(self):
enctoken=open("shoonyakey.txt",'r').read().rstrip()
self.__susertoken=enctoken
#print("enctoken")
#after login we set our token directly,so we also to define our username and password
self.__username='FA47965'
self.__password='abcd@123'
self.__accountid='FA47965'
def set_session(self, userid, password, usertoken):
self.__username = 'FA47965'
self.__accountid = 'FA47965'
self.__password = 'abcd@123'
self.__susertoken = usertoken
Ganta Kishore Kumar
Copyright (C) of API belong to API Owners.