mirror of
https://github.com/wassname/libcryptomarket.git
synced 2026-09-09 11:25:52 +08:00
Merge pull request #1 from wassname/master
Fix for cryptocompare and logging
This commit is contained in:
@@ -5,3 +5,6 @@
|
||||
__author__ = """Gavin Chan"""
|
||||
__email__ = 'gavincyi@gmail.com'
|
||||
__version__ = '0.1.0'
|
||||
__all__ = ['api']
|
||||
|
||||
from . import api
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#!/bin/python
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
API_URL = "https://min-api.cryptocompare.com/data/"
|
||||
MAX_QUERY_LIMIT = 2000
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CryptocompareCoinlist:
|
||||
"""Cryptocompare coinlist.
|
||||
@@ -51,7 +54,7 @@ class CryptocompareHisto:
|
||||
def get_coinlist():
|
||||
"""Return general info for all coins available.
|
||||
"""
|
||||
url = API_URL + "coinlist"
|
||||
url = API_URL + "all/coinlist"
|
||||
|
||||
return requests.get(url).json()
|
||||
|
||||
@@ -83,4 +86,14 @@ def get_histo(period, fsym, tsym, e, limit=None, toTs=None):
|
||||
if toTs is not None:
|
||||
params["toTs"] = toTs
|
||||
|
||||
return requests.get(url, params=params).json()
|
||||
r = requests.get(url, params=params)
|
||||
|
||||
# Raise html error status
|
||||
r.raise_for_status()
|
||||
|
||||
# The api raises a 200 for a warning, but passes a message
|
||||
rjson = r.json()
|
||||
if rjson.get("Message", None):
|
||||
logger.warning('api returned message %r, for url %r', rjson["Message"], r.url)
|
||||
|
||||
return rjson
|
||||
|
||||
@@ -42,7 +42,7 @@ def get_historical_prices(source='cryptocompare', symbol=None, exchange=None,
|
||||
# Parse from (first 3) and to (last 3) symbol from the parameter
|
||||
# symbol.
|
||||
from_sym = symbol[:3]
|
||||
to_sym = symbol[3:6]
|
||||
to_sym = symbol[3:]
|
||||
|
||||
func = partial(get_histo, period=period, fsym=from_sym, tsym=to_sym,
|
||||
e=exchange)
|
||||
@@ -85,6 +85,9 @@ def get_historical_prices(source='cryptocompare', symbol=None, exchange=None,
|
||||
else:
|
||||
data += func()['Data']
|
||||
|
||||
if len(data) == 0:
|
||||
return data
|
||||
|
||||
data = pd.DataFrame([CryptocompareHisto(**e).__dict__ for e in data])
|
||||
# Filter only valid time range
|
||||
if from_time is not None and to_time is not None:
|
||||
|
||||
Reference in New Issue
Block a user