Data feeds error for local csv file in basic code with out strategy
-
Hi guys,
I am trying to build first code but getting errors every time i try to connect data feeds, I tried different data feed methods and tried many other ways to connect but getting some or other kind of error every time, nothing seems to work. please help!
mentioned two methods I am trying to use in the code.
Code:
import backtrader as bt
import os
import sys
import datetimecerebro = bt.Cerebro()
#Method 1: YahooFinanceCSVData
modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
datapath = os.path.join(modpath, 'C:/Users/admin/xx/xx2/xx.csv')
data = bt.feeds.YahooFinanceCSVData(dataname=datapath, reverse=False)#Method 2: GenericCSVData
data = bt.feeds.GenericCSVData (dataname='filename.csv', dtformat=1)cerebro.adddata(data)
cerebro.run()
cerebro.plot()
<end>Data file's first string:
1623809640000,40124.02000000,40129.70000000,40100.00000000,40107.65000000,12.53749700,1623809699999,502950.08549781,339,4.72578400,189573.50347000,0Error:
Method 1:
ValueError: month must be in 1..12Method 2:
OSError: [Errno 22] Invalid argument -
If you just need the default stock data with Open, High, Low, and Close, then you can just use the following code.
data = bt.feeds.PandasData(dataname=yf.download("SPY", '2015-07-06', '2021-07-01', auto_adjust=False))
You can change the date and ticker to whatever suits you.
-
@rishabmah5 need to work on the file with given format of, opendatetime, OHLC, Volume, closingdatetime, aggregate-closeprice, openinterest, :(
-
@max-kat We need more information about your data file. Can you add in the first few rows including the header row? If no header, please provide details of each column separately .
-
@run-out when i open it in excel it is in one column with coma separated values without headers,
used this code to download the file from binance,
import config, csv
from binance.client import Client
client = Client(config.API_KEY, config.SECRET_KEY)
candles = client.get_historical_klines("BTCBUSD", Client.KLINE_INTERVAL_1MINUTE, "365 day ago UTC")
csvfile = open('1min.csv', 'w', newline='')
Klinewriter = csv.writer(csvfile,delimiter=',')for candlestick in candles:
Klinewriter.writerow(candlestick)
csvfile.close()