Beispiel #1
0
 def test_limit(self):
     """
     When a limit is provided, historical data should only have that many
     elements (at most)
     """
     cc = CryptoCompare()
     result = cc.get_historical('BTC', 'USD', limit=25)
     # for some reason CryptoCompare returns limit + 1 points
     self.assertEqual(len(result), 25 + 1)
Beispiel #2
0
 def test_to_ts(self):
     """
     When timestamp limit is provided, historical data should only be before
     that limit
     """
     cc = CryptoCompare()
     ts = int(time.time()) - 1000
     result = cc.get_historical('BTC',
                                'USD',
                                period=Period.MINUTE,
                                to_ts=ts)
     for e in result:
         self.assertLessEqual(e['time'], ts)
Beispiel #3
0
 def test_specific_exchange(self):
     """Requesting historical data from a specific exchange should work"""
     cc = CryptoCompare()
     result = cc.get_historical('BTC', 'USD', exchange='Kraken')
     self.assertIsInstance(result[0]['close'], numbers.Real)
Beispiel #4
0
 def test_specific_period(self):
     """Historical data should follow specified period"""
     cc = CryptoCompare()
     result = cc.get_historical('BTC', 'USD', period=Period.MINUTE)
     for a, b in zip(result[:-1], result[1:]):
         self.assertEqual(b['time'] - a['time'], 60)
Beispiel #5
0
 def test_btc_usd(self):
     """Get historical data for BTC/USD should work"""
     cc = CryptoCompare()
     result = cc.get_historical('BTC', 'USD')
     self.assertIsInstance(result[0]['close'], numbers.Real)
Beispiel #6
0
from cryptocompare import CryptoCompare, CryptoCompareApiError, Period

BASE = 'ETH'
QUOTE = 'USD'

cc = CryptoCompare()

# prices need to be read in a loop because of cryptocompare's historical prices
# points limit
points = []
ts = None
while True:
    try:
        data = cc.get_historical(BASE,
                                 QUOTE,
                                 period=Period.MINUTE,
                                 limit=100000,
                                 to_ts=ts)
    except CryptoCompareApiError:
        break

    # first price is the oldest one, remove one to not include that point again
    ts = data[0]['time']
    print("Got historical data from {} ({} points)".format(ts, len(data)))

    data.extend(points)
    points = data

closes = [p['close'] for p in points]
datetimes = [datetime.datetime.fromtimestamp(p['time']) for p in points]