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

@ -79,13 +79,12 @@ def analyze_ticker(pair: str) -> DataFrame:
add several TA indicators and buy signal to it
:return DataFrame with ticker data and indicator data
"""
data = get_ticker_history(pair)
dataframe = parse_ticker_dataframe(data)
if dataframe.empty:
logger.warning('Empty dataframe for pair %s', pair)
return dataframe
ticker_hist = get_ticker_history(pair)
if not ticker_hist:
logger.warning('Empty ticker history for pair %s', pair)
return DataFrame()
dataframe = parse_ticker_dataframe(ticker_hist)
dataframe = populate_indicators(dataframe)
dataframe = populate_buy_trend(dataframe)
return dataframe
@ -98,7 +97,6 @@ def get_buy_signal(pair: str) -> bool:
:return: True if pair is good for buying, False otherwise
"""
dataframe = analyze_ticker(pair)
if dataframe.empty:
return False

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