Refactoring to overcome flake8 complexity

This commit is contained in:
Jean-Baptiste LE STANG 2017-12-31 17:34:29 +01:00
parent 644d846b79
commit 90ad21cfaf

View File

@ -117,16 +117,8 @@ class Bittrex(Exchange):
'last': float(data['result']['Last']),
}
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
if tick_interval == 1:
interval = 'oneMin'
elif tick_interval == 5:
interval = 'fiveMin'
else:
raise ValueError(
'Cannot parse tick_interval: {}'.format(tick_interval))
if pair in _cache.keys():
# pair is in cache retriev lastest candle
def update_with_latest_ticker(self, pair: str) -> List[Dict]:
# pair is in cache retrieve latest candle
sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval)
if not sdata.get('result'):
raise ContentDecodingError('{message} params=({pair})'.format(
@ -138,17 +130,27 @@ class Bittrex(Exchange):
# check timestamp is newer ...
if (sdata['result'][0]['T'] > old_ticker['T']):
data['result'].append(sdata['result'][0])
# avoid habinf to much data to analyze
# avoid having to much data to analyze
data['result'].pop(0)
elif (sdata['result'][0]['T'] == old_ticker['T']):
# if volume has changed, update the latest result with the new
# one
if (sdata['result'][0]['V'] > old_ticker['V']):
data['result'][-1] = sdata['result'][0]
return data
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
if tick_interval == 1:
interval = 'oneMin'
elif tick_interval == 5:
interval = 'fiveMin'
else:
data = _API_V2.get_candles(pair.replace('_', '-'), interval)
# Update the value in cache
_cache[pair] = data
raise ValueError(
'Cannot parse tick_interval: {}'.format(tick_interval))
if pair in _cache.keys():
_cache[pair] = self.update_with_latest_ticker(pair)
else:
_cache[pair] = _API_V2.get_candles(pair.replace('_', '-'), interval)
# These sanity check are necessary because bittrex cannot keep their
# API stable.
if not data.get('result'):
@ -156,6 +158,9 @@ class Bittrex(Exchange):
message='Got invalid response from bittrex',
pair=pair))
# Update the value in cache
_cache[pair] = data
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
for tick in data['result']:
if prop not in tick.keys():