sanitize get_ticker_history (fixes #100)
This commit is contained in:
parent
bab59fbacd
commit
81f7172c4a
@ -79,13 +79,12 @@ def analyze_ticker(pair: str) -> DataFrame:
|
|||||||
add several TA indicators and buy signal to it
|
add several TA indicators and buy signal to it
|
||||||
:return DataFrame with ticker data and indicator data
|
:return DataFrame with ticker data and indicator data
|
||||||
"""
|
"""
|
||||||
data = get_ticker_history(pair)
|
ticker_hist = get_ticker_history(pair)
|
||||||
dataframe = parse_ticker_dataframe(data)
|
if not ticker_hist:
|
||||||
|
logger.warning('Empty ticker history for pair %s', pair)
|
||||||
if dataframe.empty:
|
return DataFrame()
|
||||||
logger.warning('Empty dataframe for pair %s', pair)
|
|
||||||
return dataframe
|
|
||||||
|
|
||||||
|
dataframe = parse_ticker_dataframe(ticker_hist)
|
||||||
dataframe = populate_indicators(dataframe)
|
dataframe = populate_indicators(dataframe)
|
||||||
dataframe = populate_buy_trend(dataframe)
|
dataframe = populate_buy_trend(dataframe)
|
||||||
return dataframe
|
return dataframe
|
||||||
@ -98,7 +97,6 @@ def get_buy_signal(pair: str) -> bool:
|
|||||||
:return: True if pair is good for buying, False otherwise
|
:return: True if pair is good for buying, False otherwise
|
||||||
"""
|
"""
|
||||||
dataframe = analyze_ticker(pair)
|
dataframe = analyze_ticker(pair)
|
||||||
|
|
||||||
if dataframe.empty:
|
if dataframe.empty:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ def get_ticker(pair: str) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
@cached(TTLCache(maxsize=100, ttl=30))
|
@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)
|
return _API.get_ticker_history(pair, tick_interval)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class Bittrex(Exchange):
|
|||||||
'last': float(data['result']['Last']),
|
'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:
|
if tick_interval == 1:
|
||||||
interval = 'oneMin'
|
interval = 'oneMin'
|
||||||
elif tick_interval == 5:
|
elif tick_interval == 5:
|
||||||
@ -97,6 +97,13 @@ class Bittrex(Exchange):
|
|||||||
raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval))
|
raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval))
|
||||||
|
|
||||||
data = _API_V2.get_candles(pair.replace('_', '-'), 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']:
|
if not data['success']:
|
||||||
raise RuntimeError('{message} params=({pair})'.format(
|
raise RuntimeError('{message} params=({pair})'.format(
|
||||||
message=data['message'],
|
message=data['message'],
|
||||||
|
@ -74,7 +74,7 @@ class Exchange(ABC):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@abstractmethod
|
@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.
|
Gets ticker history for given pair.
|
||||||
:param pair: Pair as str, format: BTC_ETC
|
:param pair: Pair as str, format: BTC_ETC
|
||||||
|
Loading…
Reference in New Issue
Block a user