def test__fetch_ohlcv_dataframe__no_data(self): backend = ExchangeBackend(ohlcvs={}, timeframe=MagicMock(), balances={}) with self.assertRaises(BadSymbol) as e: backend.fetch_ohlcv_dataframe('UNK/BTC', '1m') self.assertEqual(str(e.exception), 'ExchangeBackend: no prices for UNK/BTC')
def test__fetch_ohlcv_dataframe__not_avail_past_values(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) with self.assertRaises(BadRequest) as e: backend.fetch_ohlcv_dataframe(symbol=symbol, since=1483232330000) self.assertEqual( str(e.exception), 'ExchangeBackend: fetch_ohlcv: no ' 'date availabe at since')
def test__fetch_ohlcv_dataframe__access_future__timeframe(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) with self.assertRaises(BadRequest) as e: backend.fetch_ohlcv_dataframe( symbol=symbol, timeframe='2m', since=1483232610000, limit=10) self.assertEqual( str(e.exception), 'ExchangeBackend: fetch_ohlcv: since.ceil(timeframe) + limit' ' * timeframe needs to be in the past')
def test__fetch_ohlcv_dataframe__limit(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe(symbol=symbol, limit=3) pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [4, 8, 12], 'high': [5, 9, 13], 'low': [3, 7, 11], 'close': [8, 12, 16], 'volume': [100, 104, 108]}, dtype=float, index=pandas.date_range( '2017-01-01 1:01', '2017-01-01 1:03', 3, tz='UTC')))
def test__fetch_ohlcv_dataframe__since(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe(symbol=symbol, since=1483232790000) pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [28, 32, 36, 40, 44], 'high': [29, 33, 37, 41, 45], 'low': [27, 31, 35, 39, 43], 'close': [32, 36, 40, 44, 48], 'volume': [124, 128, 132, 136, 140]}, dtype=float, index=pandas.date_range( '2017-01-01 1:07', '2017-01-01 1:11', 5, tz='UTC')))
def test__fetch_ohlcv_dataframe__partial_data(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe( symbol=symbol, timeframe='3m', since=1483233000000, limit=3) pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [48.0, 60.0, 72.0], 'high': [57.0, 69.0, 77.0], 'low': [47.0, 59.0, 71.0], 'close': [60.0, 72.0, 80.0], 'volume': [444.0, 480.0, 340.0]}, dtype=float, index=pandas.date_range( '2017-01-01 01:12', '2017-01-01 01:18', 3, tz='UTC')))
def test__fetch_ohlcv_dataframe(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe(symbol=symbol) pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [4, 8, 12, 16, 20], 'high': [5, 9, 13, 17, 21], 'low': [3, 7, 11, 15, 19], 'close': [8, 12, 16, 20, 24], 'volume': [100, 104, 108, 112, 116]}, dtype=float, index=pandas.date_range( '2017-01-01 1:01', '2017-01-01 1:05', freq='1T', tz='UTC')))
def test__fetch_ohlcv_dataframe__resample_other_freq(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe(symbol=symbol, since=1483232590000, limit=3, timeframe='3m') pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [24, 36, 48], 'high': [33, 45, 57], 'low': [23, 35, 47], 'close': [36, 48, 60], 'volume': [372, 408, 444]}, dtype=float, index=pandas.date_range( '2017-01-01 1:06', '2017-01-01 1:12', 3, tz='UTC')))
def test__fetch_ohlcv_dataframe__resample(self): symbol = 'BTC/USD' backend = ExchangeBackend(ohlcvs={symbol: self.fetch_ohlcv_ohlcvs}, timeframe=self.fetch_ohlcv_timeframe, balances={}) result = backend.fetch_ohlcv_dataframe(symbol=symbol, since=1483232490000, limit=3, timeframe='4m') pandas.testing.assert_frame_equal( result, pandas.DataFrame( data={ 'open': [16, 32, 48], 'high': [29, 45, 61], 'low': [15, 31, 47], 'close': [32, 48, 64], 'volume': [472, 536, 600]}, dtype=float, index=pandas.date_range( '2017-01-01 1:04', '2017-01-01 1:12', 3, tz='UTC')))