Upstox Python API-Algorithmic Trading-Programmatic Trading-Automate Trade-Stock Market

Follow the Video Above for Proper Instruction then go for the Link and Code:


Open Online Upstox Trading Acoount : http://upstox.com/open-account/?f=36K0


Upstox API Document:https://upstox.com/developer/api/v1/docs/


To be able to use these APIs you need to create an App in the Developer Console : https://developer.upstox.com


Upstox Python Github : https://upstox.github.io/upstox-python/


url where you need to set api key and url to retrieve the code from browser : https://api.upstox.com/index/dialog/authorize?apiKey={your_api_key}&redirect_uri={your_redirect_uri}&response_type=code



To retrieve the access token follow blow algorithm in python:



from upstox_api.api import *
import csv
api_key=open('api_key.txt','r').read()
api_secret=open('api_secret.txt','r').read()
code=open('code.txt','r').read()
url='http://upstox.com:3000'
s=Session(api_key)
s.set_redirect_uri(url)
s.set_api_secret(api_secret)
s.set_code(code)
access_token=s.retrieve_access_token()
with open('access_token.txt','w') as csvfile:
    wr=csv.writer(csvfile)
    wr.writerow([access_token])
    print(access_token)

To retrieve the instruments with just follow of api key and access token:



from upstox_api.api import *
import pandas as pd
api_key=open('api_key.txt','r').read()
access_token=open('access_token.txt','r').read().strip()
u=Upstox(api_key,access_token)
instruments=u.get_master_contract('NSE_FO')
instruments=pd.DataFrame(instruments)
print(instruments)