Ethereum: matplotlib chart showing candle data not only as a vertical line (no wick, high open and low close)


Here’s a step-by-step guide on how to create an Ethereum candle chart using matplotlib in Python:

import matplotlib.pyplot as plt

import matplotlib.dates as mdates

import numpy as np

import yfinance as yf

from datetime import datetime, timedelta








Ethereum: matplotlib chart not showing candle data as vertical line only (no wicks, open high low close)

Get the current time (will be displayed as the x-axis)

start_date = datetime.today().strftime('%Y-%m-%d')

end_date = (datetime.today() - timedelta(days=30)).strftime('%Y-%m-%d')


Define the API endpoint for Ethereum prices

apiEndpoint = "


Set the parameters for the API request

params = {

'symbol': 'ETH',

'interval': '1m',

'limit': 100,

Max number of data points to retrieve

'timeRange': start_date + ',' + end_date,

}


Send the API request and get the response

response = yf.get(apiEndpoint, params=params)


Convert the response to a pandas DataFrame

df = pd.DataFrame(response).T


Create the x-axis dates (index) from 1 to 100 (assuming we need at least 100 data points)

dates = np.arange(1, len(df.columns))


Set the date format for matplotlib

plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))


Plot the candle chart

plt.figure(figsize=(14,10))

for i in range(len(dates)-1):

plt.plot([i0.01, (i+1)0.01], [df.loc[i,'close'].mean(), df.loc[i+1,'close'].mean()], color='g')

if not (i == len(df.columns) - 2):

do not plot the last candle

plt.plot([i0.01, i0.01 + 0.01], [df.loc[i,'high'].mean(), df.loc[i+1,'high'].mean()], color='g')

elif (i == len(df.columns) - 2):

do not plot the first candle

plt.plot([i0.01, i0.01 + 0.02], [df.loc[i,'low'].mean(), df.loc[i+1,'low'].mean()], color='g')

plt.xlabel('Date')

plt.ylabel('Price (USD)')

plt.title("Ethereum Candle Chart")

plt.show()

To run this script, you need to have the required libraries installed (matplotlib, pandas and yfinance). You also need a Binance API key.

Please ensure that your Binance API endpoint is correctly set as per your API documentation.


Leave a Reply

Your email address will not be published. Required fields are marked *