0

Hello I am trying to plot the chart of some crypto currencies. I am trying to plot the chart BTC/USD but it does not work. Here is my code :

from urllib.request import Request, urlopen
import json
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import datetime as dt    
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates

url = "https://api.binance.com/api/v1/klines?symbol=BTCTUSD&interval=1h"
reponse = urlopen(url)
data = json.load(reponse)
df = pd.DataFrame(data)
df.columns = ['open_time', 'o', 'h', 'l',
              'c', 'v', 'close_time',
              'qav', 'num_trades', 'taker_base_', 'taker_quote_vol',
              'ignore']
df['close_time'] = pd.to_datetime(df['close_time'], unit='ms')
df['close_time'] = df['close_time'].apply(mdates.date2num)
df['o'] = df['o'].astype('float')
df['h'] = df['h'].astype('float')
df['l'] = df['l'].astype('float')
df['c'] = df['c'].astype('float')
df['v'] = df['v'].astype('float')
ax1 = plt.subplot2grid((1,1), (0,0))
ohlc = [df['close_time'], df['o'], df['h'], df['l'], df['c'], df['v']]
candlestick_ohlc(ax1, ohlc)

But when I try to execute this code I get this nothing just a white screen but without chart it is very strange !

Could you help me please ?

Thank you very much !

  • It seems one of your variables that you think is in float/int format is actually a string. (If you post the full the error we could catch which line it is) – Juan C Jun 04 '19 at 19:54
  • There is no `height = open - close` in your posted code? Since you seem to be new to Stack Overflow, please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Sheldore Jun 04 '19 at 19:54
  • No there is no because height is a variable which is in the library mpl_finance – Peter Jackson Jun 04 '19 at 20:02
  • most of the values (i.e. everything except open time, close time and number of trades) in the json returned from the api are strings. you need to convert these to numbers before calculations – buran Jun 04 '19 at 20:04

0 Answers0