plotting ohlc in candlestick chart

nayana
hi, this is my code where im reading data from database and converting tick data into ohlc
and i am plotting that data in an chart.In chart im not getting timestamp in x axis its throwing me error can anyone help me in this..
thanks in advance





db=mysql.connector.connect(host='localhost',user='root',password='',database='algotrading')
data=pd.read_sql('select *from algotrading.ticks',con=db)
data=data.set_index(['timestamp'])
ticks=data.loc[:,['last_price']]
data=ticks['last_price'].resample('1min').ohlc().dropna()
print(data)


# print(data['timestamp'])

#with open('alogdata.csv','w',newline='')as csvfile:
# writer=csv.writer(csvfile)
# writer.writerow(v)
fig = go.Figure(data=[go.Candlestick(x=df['timestamp'],
open=df['open'],
high=df['high'],
low=df['low'],
close=df['close'])])

fig.show()
  • SRIJAN
    What's the error you are getting??
  • nayana
    fig = go.Figure(data=[go.Candlestick(x=data['timestamp'],
    KeyError: 'timestamp'
    im getting this error
  • SRIJAN
    SRIJAN edited December 2021
    The 'timestamp' key is not present in your dataframe. Use the correct key.
Sign In or Register to comment.