diff --git a/libcryptomarket/__init__.py b/libcryptomarket/__init__.py index 6d5350e..0a742f7 100644 --- a/libcryptomarket/__init__.py +++ b/libcryptomarket/__init__.py @@ -4,4 +4,4 @@ __author__ = """Gavin Chan""" __email__ = 'gavincyi@gmail.com' -__version__ = '0.1.0' +__version__ = '0.1.1' diff --git a/libcryptomarket/api/poloniex_api.py b/libcryptomarket/api/poloniex_api.py index 0a59ab6..899c9da 100644 --- a/libcryptomarket/api/poloniex_api.py +++ b/libcryptomarket/api/poloniex_api.py @@ -1,11 +1,9 @@ #!/bin/python import requests -from datetime import datetime -import logging - API_URL = "https://poloniex.com/public?command=" VALID_PERIODS = [300, 900, 1800, 7200, 14400, 86400] + def get_return_chart_data(currency_pair, period, start, end=None): """Return returnChartData. @@ -29,4 +27,8 @@ def get_return_chart_data(currency_pair, period, start, end=None): r = requests.get(url) r.raise_for_status() - return r.json() \ No newline at end of file + rjson = r.json() + if isinstance(rjson, dict) and 'error' in rjson.keys(): + raise ValueError("Query error from Poloniex API ({0})".format(rjson)) + + return r.json() diff --git a/libcryptomarket/historical.py b/libcryptomarket/historical.py index 79c7bcf..0d50d50 100644 --- a/libcryptomarket/historical.py +++ b/libcryptomarket/historical.py @@ -145,13 +145,10 @@ def _get_historical_prices_cryptocompare(symbol, exchange, period, def _get_historical_prices_poloniex(symbol, period, from_time, to_time): from libcryptomarket.api.poloniex_api import get_return_chart_data data = get_return_chart_data(symbol, period, from_time, to_time) - if len(data) == 0 or isinstance(data, dict): - raise ValueError("Poloniex data is not in a right format.\n{0}".format( - data)) - data = pd.DataFrame(data) - data['date'] = data['date'].map(lambda x: pd.Timestamp(datetime.fromtimestamp(x))) + data['date'] = data['date'].map( + lambda x: pd.Timestamp(datetime.fromtimestamp(x))) data.columns = "r_" + data.columns.str.lower() data = data.set_index(['r_date']) data.index.name = 'datetime' - return data \ No newline at end of file + return data diff --git a/setup.py b/setup.py index b5c1c5b..a136e67 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ """The setup script.""" from setuptools import setup, find_packages +from libcryptomarket import __version__ with open('README.md') as readme_file: readme = readme_file.read() @@ -28,7 +29,7 @@ test_requirements = [ setup( name='libcryptomarket', - version='0.1.0', + version=__version__, description="Library for cryptocurrency market information.", long_description=readme + '\n\n' + history, author="Gavin Chan", diff --git a/tests/test_cryptocompare_api.py b/tests/test_cryptocompare_api.py index 87fdda4..00018c4 100644 --- a/tests/test_cryptocompare_api.py +++ b/tests/test_cryptocompare_api.py @@ -145,7 +145,7 @@ def test_get_historical_prices_cryptocompare(monkeypatch): result = get_historical_prices(source='cryptocompare', period='minute', exchange='Poloniex', - symbol='LTCBTC') + symbol='LTC/BTC') expected_result = pd.DataFrame([ {