generic csv data dtformat not correct?
Hey guys, my Issue is that I want to read a custom csv file and add the data but something goes wrong and no data is actually added I guess, resulting in the error
AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'
My Code for the custom data is the following:
datapath = os.path.join(modpath, 'datas\\Coinbase_BTCUSD_1h.csv') datef = '%Y-%m-%d %I-%p' data = bt.feeds.GenericCSVData( dataname=datapath, fromdate=datetime.datetime(2017, 7, 1, 11), todate=datetime.datetime(2020, 8, 14, 22), dtformat=datef, reverse=True, # specifying columns datetime=0, open=2, high=3, low=4, close=5, volume=7, openinterest=-1 )
The CSV file I am trying to read has the following format:
Date,Symbol,Open,High,Low,Close,Volume BTC,Volume USD 2020-08-14 10-PM,BTCUSD,11777.33,11797.52,11734.83,11797.52,298.79,3514421.22 2020-08-14 09-PM,BTCUSD,11774.77,11794.63,11714.1,11777.33,674.78,7933568.87 2020-08-14 08-PM,BTCUSD,11815.28,11838.65,11751.54,11774.77,719.56,8482977.35
If I try to convert the the time string manually using
test = datetime.datetime.strptime('2020-08-14 10-PM', '%Y-%m-%d %I-%p') print(test)
I get the time I would expect.
Any help would be really appreciated, also do you have some tips for debugging? How can I read out the values of the data while debugging (I am using PyCharm), it just seems like it is an infinitely recursive list, I just want to access the data that has been read so I can confirm what the mistake is in the future.
Thank you all in advance :)
vladisld last edited by
I've run your code and it seems the dtformat is defined correctly - just try to use the correct
todateinterval (like 2017/7/1 - 2020/8/15 ).
The error you are seeing is raised during the plotting and probably related to the fact that indeed no data was loaded for the requested time period.
@vladisld Yes you are right, my mistake was that I was using a reversed csv file and for GenericCSVData the reverse=True does not do anything. Then the csv file gets read assuming that the next row will be a later timestamp and ignores everything if the first line is too late to be considered. Might be wring with that but that's my explanation I came up with.
Anyway I tried and reversed the csv file manually and now it works, thank you.
But still, for further workings: do you have a trick for debugging? When I load it in a pandas dataframe for example it is really easy to read out the data, but where is the data stored in the GenericCSVData object? I am curious to find out, is it present in the line buffers?