Automate Trades in Upstox Utilizing Free of Cost API in Python


For Instructions Follow the Video then go For Code Input:



import requests
api_key=open('api_key.txt','r').read().strip()
api_secret=open('api_secret.txt','r').read().strip()
uri='https://account.upstox.com/developer/apps'
code='ZnNMAG'
url='https://api-v2.upstox.com/login/authorization/token'
headers={
      'accept': 'application/json',
      'Api-Version': '2.0',
      'Content-Type': 'application/x-www-form-urlencoded'
      }
data={
    'code':code,
    'client_id':api_key,
    'client_secret':api_secret,
    'redirect_uri':uri,
    'grant_type':'authorization_code'
    }
response=requests.post(url,headers=headers,data=data)
access_token=response.json()['access_token']
print(access_token,file=open('access_token.txt','w'))
print(access_token)
access_token=open('access_token.txt','r').read().strip()
quote='https://api-v2.upstox.com/market-quote/quotes?symbol=NSE_EQ|INE848E01016'
headers={
  'accept': 'application/json',
 'Api-Version': '2.0',
 'Authorization': f'Bearer {access_token}'
  }
response=requests.get(quote,headers=headers)
print(response.json())


Fetch Top Gainers & Losers Symbol from NSE’s Website

Follow the Video Properly for Instructions then go for the Code Below.

Choose CMD and Go for Installation Type pip install nsetools and hit Enter.

Gainers are those stocks list which we derive after they outperform other stocks same as we do with Losers side but they are not performing side especially we do check this in intraday and if you want to check the list you can visit nseindia otherwise you can have trading account in aliceblue for better vision,trading and analysis via python API to open an account please follow the link and click Alice Blue.



from nsetools import Nse
from pprint import pprint
import pandas as pd
nse=Nse()
Gainers=nse.get_top_gainers()
Gainers=pd.DataFrame(Gainers)
Losers=nse.get_top_losers()
Losers=pd.DataFrame(Losers)
BUY=[x for x in Gainers['symbol']]
SELL=[x for x in Losers['symbol']]
for x in range(len(BUY)):
    print(BUY[x])
for x in range(len(SELL)):
    print(SELL[x])


If you want to Extract Historical Data from NSE’s Website Please Follow Link NSEpy Historical Data