@author: rich ''' from data_loader import DataLoader import datetime from datetime import timedelta from filedata_reader import FileDataReader if __name__ == '__main__': # get hostory and future data from coinbase at starttime ticker = 'BTC-USD' start_time_str = '2018-10-31 00:00:00.000000' start_time = datetime.datetime.strptime(start_time_str, '%Y-%m-%d %H:%M:%S.%f') livetrade = False data = DataLoader(ticker, start_time, livetrade) end_time_str = '2018-10-31 04:30:00.000000' end_time = datetime.datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S.%f') granularity = 60 history_df = data.getHistoryRange(start_time, end_time, granularity) print('history', history_df.tail()) filedata = FileDataReader() print(filedata.data.loc['2018-10-31'].head())
# all_data is read in as minute BTC OHLCV # starts at 20150801 00:00:00 to close to real time # run data gatherer to get data from eof till now-5H # get 6 months at a time #granularity = 21600 # in seconds; 86400 = 1 Day #num_points = 728 #728 = 6 mos, w 6H int granularity = 300 # in seconds; 86400 = 1 Day num_points = 160000 # try to make it 180 days duration = granularity * num_points end_time = start_time + timedelta(seconds=duration) range_df = all_data.getHistoryRange(start_time, end_time, granularity) print('num points returned:', len(range_df)) # add time as a column outside of the index for the plotter #print (range_df.head(20)) print('nan count:', range_df.isna().sum()) #plot = Plotter.showOHLCPlot(range_df) target_df = pd.DataFrame(index=range_df.index) target_df['target'] = 0 last_time = range_df.index[-1] print('last time is:', last_time)
class TestPlotter(unittest.TestCase): def setUp(self): ticker = 'BTC-USD' start_time_str = '2015-01-01 12:00:00.000000' self.start_time = datetime.datetime.strptime(start_time_str, '%Y-%m-%d %H:%M:%S.%f') live_data = False self.data = DataLoader(ticker, self.start_time, live_data) def tearDown(self): pass @unittest.skip("demonstrating skipping") def testAllPlots(self): print ("does this even run?") return(True) history = {} history = self.data.getAllHistory(self.start_time) for granularity in self.data.GRANULARITY: df = history[granularity] plot = Plotter.showPlot(df) assert(True) @unittest.skip("demonstrating skipping") def testDayPlot(self): granularity = 86400 end_time_str = '2016-01-01 12:00:00.000000' end_time = datetime.datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S.%f') duration = granularity * 300 start_time = end_time - timedelta(seconds=duration) range_df = self.data.getHistoryRange(start_time, end_time, granularity) range_df['time'] = range_df.index print (range_df.head(20)) plot = Plotter.showPlot(range_df) assert(True) def testFuturePercentPlot(self): granularity = 43200 start_time_str = '2016-01-01 12:00:00.000000' start_time = datetime.datetime.strptime(start_time_str, '%Y-%m-%d %H:%M:%S.%f') duration = granularity * 60 end_time = start_time + timedelta(seconds=duration) range_df = self.data.getHistoryRange(start_time, end_time, granularity) # add time as a column outside of the index for the plotter #print (range_df.head(20)) new_df = range_df.loc[:,['open']] #plot = Plotter.showOHLCPlot(range_df) base_price = new_df['open'].iloc[0] new_df['open'] = ((new_df['open'] - base_price) / base_price) * 100 print ('base price is:', base_price) new_df['target'] = 0 new_df.at['2016-01-20 00:00:00','target'] = 1 new_df.at['2016-01-21 00:00:00','target'] = 2 print ('new_df:', new_df.head(20)) plot2 = Plotter.showSinglePlot(new_df) assert(True)