title: Binance API: Store kline/candlestick data to .csv file
body: <p>I am trying to write some <code>.json</code> data from an API to a CSV file</p>
  <p><em><strong>My code:</strong></em></p>
  <pre class="lang-py prettyprint-override"><code>from binance.client import Client
  import config
  import pandas as pd
  import pandas_datareader as web
  from pandas_datareader import data as dreader
  
  
  client = Client(config.apiKey,config.apiSec)
  print(&quot;Logged in&quot;)
  
  symbol = 'BTCUSDT'
  
  klines = client.get_historical_klines(symbol, Client.KLINE_INTERVAL_1WEEK, &quot;1 Jan, 2017&quot;)
  
  
  print(klines)
  
  df = pd.read_json(klines)
  df.to_csv(r'path')
  </code></pre>
  <p><em><strong>Error:</strong></em></p>
  <blockquote>
  <p>Traceback (most recent call last):
  File &quot;\OneDrive\Knowledge\Python\Binance API new\BTC-price-get.py&quot;, line 19, in 
  df = pd.read_json(klines)
  File &quot;\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\util_decorators.py&quot;, line 199, in wrapper
  return func(*args, **kwargs)
  File &quot;\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\util_decorators.py&quot;, line 296, in wrapper
  return func(*args, **kwargs)
  File &quot;\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\json_json.py&quot;, line 593, in read_json
  filepath_or_buffer, _, compression, should_close = get_filepath_or_buffer(
  File &quot;\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\common.py&quot;, line 243, in get_filepath_or_buffer
  raise ValueError(msg)
  ValueError: Invalid file path or buffer object type: &lt;class 'list'&gt;
  PS \Python&gt;</p>
  </blockquote>