After hours of installing and re-installing different dependancies I finally got it to work. I has lots of warnings and errors but the chart actually loads.
So I am wondering how I can add volumes to the current code listed below.
import requests
import pandas as pd
import plotly.graph_objects as go
historical = requests.get('
https://ftx.com/api/markets/BTC-PERP/candles?resolution=3600&start_time=1609462800').json()
historical = pd.DataFrame(historical['result'])
historical.drop(['startTime'], axis = 1, inplace=True)
historical.head()
historical['time'] = pd.to_datetime(historical['time'], unit='ms')
historical.set_index('time', inplace=True)
historical['20 SMA'] = historical.close.rolling(20).mean()
historical.tail()
fig = go.Figure(data=[go.Candlestick(x = historical.index,
open = historical['open'],
high = historical['high'],
low = historical['low'],
close = historical['close'],
),
go.Scatter(x=historical.index, y=historical['20 SMA'], line=dict(color='purple', width=1))])
fig.show()
I found a similar plotly code and tried to rewrite it to work with FTX API however I am getting errors.
Loading this code works for AAPL
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
# data
df = pd.read_csv('
https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# include candlestick with rangeselector
fig.add_trace(go.Candlestick(x=df['Date'],
open=df['AAPL.Open'], high=df['AAPL.High'],
low=df['AAPL.Low'], close=df['AAPL.Close']),
secondary_y=True)
# include a go.Bar trace for volumes
fig.add_trace(go.Bar(x=df['Date'], y=df['AAPL.Volume']),
secondary_y=False)
fig.layout.yaxis2.showgrid=False
fig.show()
So I rewrote it as best as I could to match the first code such as,
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
# data
df = pd.read_csv('
https://ftx.com/api/markets/BTC-PERP/candles?resolution=3600&start_time=1609462800')
# Create figure with secondary y-axis
fig = make_subplots(specs=[[{"secondary_y": True}]])
# include candlestick with rangeselector
fig.add_trace(go.Candlestick(x=df['startTime'],
open=df['open'], high=df['high'],
low=df['low'], close=df['close']),
secondary_y=True)
# include a go.Bar trace for volumes
fig.add_trace(go.Bar(x=df['startTime'], y=df['volume']),
secondary_y=False)
fig.layout.yaxis2.showgrid=False
fig.show()
However I get some error 403. I am pretty close and wondering if someone can look over my code and correct where my error is.