AFTER LOGGING IN , AND FETCHING SYUMBOL QUOTE , IT IS GIVING RESPONSE 400
CODE
url = ‘https://api-v2.upstox.com/market-quote/quotes’
headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Authorization’: f’Bearer {access_token}’
}
params = {
‘symbol’: ‘NSE_EQ|INE848E01016,NSE_FO|43286’
}
response = make_request(‘GET’, url, headers=headers, params=params)
response
AFTER RUNNING THIS CODE <Response [400]> ERROR IS COMING
AND ALSO AFTER RUNNING
symboldf[symboldf.tradingsymbol ==‘HDFC’]
NO SYMBOL OF STOCK IS COMING
The NSE_FO|43286 symbol provided is not valid for instrument keys.
Additionally, please provide the source from which you are obtaining the symbol NSE_FO|43286. Ideally, it should be sourced from the instrument files available here: Instruments | Upstox Developer API
Your symbol NSE_EQ|INE848E01016 is correct. However, the current structure requires that all symbols must be valid, or else it will result in a 400 bad request error. We plan to address this issue in an upcoming release by ignoring invalid symbols and providing data only for those that are valid according to the list.
after entring correct symbol , still encountering error
import requests
import pandas as pd
Your access token obtained from the previous OAuth 2.0 flow
API endpoint URL for fetching historical data
url = ‘https://api.upstox.com/historical/ohlc’
Headers for the API request
headers = {
‘accept’: ‘application/json’,
‘Api-Version’: ‘2.0’,
‘Authorization’: f’Bearer {access_token}’
}
Parameters for fetching historical data
params = {
‘symbol’: ‘NSE_EQ|INE0LF301013’, # Your desired symbol
‘exchange_token’: ‘10491’, # Your exchange token
‘start_date’: ‘01-01-2022’, # Desired start date in DD-MM-YYYY format
‘end_date’: ‘31-12-2022’, # Desired end date in DD-MM-YYYY format
‘interval’: ‘15MINUTE’ # Desired interval for the historical data
}
Make the API request
response = requests.get(url, headers=headers, params=params)
Check if request was successful
if response.status_code == 200:
historical_data = response.json()
# Convert to DataFrame for easier data manipulation
df = pd.DataFrame(historical_data)
print(df)
else:
print(“Failed to retrieve data:”, response.status_code, response.text)
Failed to retrieve data: 403 {“message”:“‘’ not a valid key=value pair (missing equal-sign) in Authorization header: 'Bearer.”}
The url used here https://api.upstox.com/historical/ohlc
is of Upstox version v1.
We strongly advise you to transition your code to Upstox version v2, as Upstox API V1 has been deprecated state and is no longer actively maintained.
Please inform us if you encounter an issue in version v2.