CRYPTOCURRENCY

Ethereum: matplotlib chart does not display candlestick data only as a vertical line (no wicks, open high, close low)

Here is a step-by-step guide on how to create an Ethereum candlestick 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 (displayed as 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

parameters = {

'symbol': 'ETH',

'interval': '1m',

'limit': 100,

Maximum number of data points to retrieve

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

}


Send an 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 x-axis dates (index) from 1 to 100 (assuming we need at least 100 data points)

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


Set the date format for matplotlib

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


Draw a candlestick chart

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

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

plt.plot([i۰.۰۱, (i+1)۰.۰۱], [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([i۰.۰۱, i۰.۰۱ + ۰.۰۱], [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([i۰.۰۱, i۰.۰۱ + ۰.۰۲], [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 must have the required libraries (matplotlib, pandas, and yfinance) installed. You also need a Binance API key.

Make sure your Binance API endpoint is set up correctly according to your API documentation.

Ethereum Pool Mining Linux.html

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *