@Nagasai_Harsha and @Vartika_Singh it’s important to note that once the API returns the response, any application-specific logic, such as porting results to a pandas DataFrame or other post-processing on your side, is outside the scope of our support.
But I can share a working example for converting historical response data to pandas dataframe.
- Convert the api response to string format
- Replace single quotes with double quotes to make it a valid JSON string
- Convert the string to python dictionary
- Create a dataframe object from the given dictionary.
import upstox_client
import json
import pandas as pd
from upstox_client.rest import ApiException
api_version = '2.0'
api_instance = upstox_client.HistoryApi()
instrument_key = 'NSE_EQ|INE669E01016'
interval = '30minute'
to_date = '2023-11-13'
from_date = '2023-11-12'
try:
api_response = api_instance.get_historical_candle_data1(instrument_key, interval, to_date, from_date, api_version)
string = str(api_response) # Convert the api response to string
string = string.replace("'", "\"") # Replace single quotes with double quotes to make it a valid JSON string
json_dict = json.loads(string) # convert the string to python dictionary
df = pd.DataFrame(json_dict['data']['candles'],
columns=['time_stamp', 'open', 'high', 'low', 'close', 'volume', 'open_interest'])
print(df.describe())
print(df.shape)
except ApiException as e:
print("Exception when calling HistoryApi->get_historical_candle_data: %s\n" % e)
Please feel free to ask any queries regarding the above code.
Hope this helps you