Refactoring to overcome flake8 complexity
This commit is contained in:
parent
644d846b79
commit
90ad21cfaf
@ -117,16 +117,8 @@ class Bittrex(Exchange):
|
|||||||
'last': float(data['result']['Last']),
|
'last': float(data['result']['Last']),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]:
|
def update_with_latest_ticker(self, pair: str) -> List[Dict]:
|
||||||
if tick_interval == 1:
|
# pair is in cache retrieve latest candle
|
||||||
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
|
|
||||||
sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval)
|
sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval)
|
||||||
if not sdata.get('result'):
|
if not sdata.get('result'):
|
||||||
raise ContentDecodingError('{message} params=({pair})'.format(
|
raise ContentDecodingError('{message} params=({pair})'.format(
|
||||||
@ -138,17 +130,27 @@ class Bittrex(Exchange):
|
|||||||
# check timestamp is newer ...
|
# check timestamp is newer ...
|
||||||
if (sdata['result'][0]['T'] > old_ticker['T']):
|
if (sdata['result'][0]['T'] > old_ticker['T']):
|
||||||
data['result'].append(sdata['result'][0])
|
data['result'].append(sdata['result'][0])
|
||||||
# avoid habinf to much data to analyze
|
# avoid having to much data to analyze
|
||||||
data['result'].pop(0)
|
data['result'].pop(0)
|
||||||
elif (sdata['result'][0]['T'] == old_ticker['T']):
|
elif (sdata['result'][0]['T'] == old_ticker['T']):
|
||||||
# if volume has changed, update the latest result with the new
|
# if volume has changed, update the latest result with the new
|
||||||
# one
|
# one
|
||||||
if (sdata['result'][0]['V'] > old_ticker['V']):
|
if (sdata['result'][0]['V'] > old_ticker['V']):
|
||||||
data['result'][-1] = sdata['result'][0]
|
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:
|
else:
|
||||||
data = _API_V2.get_candles(pair.replace('_', '-'), interval)
|
raise ValueError(
|
||||||
# Update the value in cache
|
'Cannot parse tick_interval: {}'.format(tick_interval))
|
||||||
_cache[pair] = data
|
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
|
# These sanity check are necessary because bittrex cannot keep their
|
||||||
# API stable.
|
# API stable.
|
||||||
if not data.get('result'):
|
if not data.get('result'):
|
||||||
@ -156,6 +158,9 @@ class Bittrex(Exchange):
|
|||||||
message='Got invalid response from bittrex',
|
message='Got invalid response from bittrex',
|
||||||
pair=pair))
|
pair=pair))
|
||||||
|
|
||||||
|
# Update the value in cache
|
||||||
|
_cache[pair] = data
|
||||||
|
|
||||||
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
|
for prop in ['C', 'V', 'O', 'H', 'L', 'T']:
|
||||||
for tick in data['result']:
|
for tick in data['result']:
|
||||||
if prop not in tick.keys():
|
if prop not in tick.keys():
|
||||||
|
Loading…
Reference in New Issue
Block a user