mirror of
https://github.com/wassname/libcryptomarket.git
synced 2026-09-09 11:25:52 +08:00
Add Poloniex error handling and upgrade to version 0.1.1
This commit is contained in:
@@ -4,4 +4,4 @@
|
||||
|
||||
__author__ = """Gavin Chan"""
|
||||
__email__ = 'gavincyi@gmail.com'
|
||||
__version__ = '0.1.0'
|
||||
__version__ = '0.1.1'
|
||||
|
||||
@@ -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()
|
||||
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()
|
||||
|
||||
@@ -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
|
||||
return data
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user