sanitize get_ticker_history (fixes #100)

This commit is contained in:
gcarq
2017-11-13 19:54:09 +01:00
parent bab59fbacd
commit 81f7172c4a
4 changed files with 15 additions and 10 deletions

View File

@@ -129,7 +129,7 @@ def get_ticker(pair: str) -> dict:
@cached(TTLCache(maxsize=100, ttl=30))
def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List:
def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List[Dict]:
return _API.get_ticker_history(pair, tick_interval)

View File

@@ -88,7 +88,7 @@ class Bittrex(Exchange):
'last': float(data['result']['Last']),
}
def get_ticker_history(self, pair: str, tick_interval: int):
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
if tick_interval == 1:
interval = 'oneMin'
elif tick_interval == 5:
@@ -97,6 +97,13 @@ class Bittrex(Exchange):
raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval))
data = _API_V2.get_candles(pair.replace('_', '-'), interval)
# This sanity check is necessary because bittrex returns nonsense sometimes
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
for tick in data['result']:
if prop not in tick.keys():
logger.warning('Required property {} not present in response'.format(prop))
return []
if not data['success']:
raise RuntimeError('{message} params=({pair})'.format(
message=data['message'],

View File

@@ -74,7 +74,7 @@ class Exchange(ABC):
"""
@abstractmethod
def get_ticker_history(self, pair: str, tick_interval: int) -> List:
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
"""
Gets ticker history for given pair.
:param pair: Pair as str, format: BTC_ETC