From 4f29e16a5023f4d9a287a3c14ba66acc01ec27d6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Sat, 9 Dec 2017 13:58:59 +0100 Subject: [PATCH] Self building our ticker history by updating using the latest ticker and checking the ticker consistency --- freqtrade/exchange/bittrex.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/freqtrade/exchange/bittrex.py b/freqtrade/exchange/bittrex.py index aa74cba80..fbf098767 100644 --- a/freqtrade/exchange/bittrex.py +++ b/freqtrade/exchange/bittrex.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) _API: _Bittrex = None _API_V2: _Bittrex = None _EXCHANGE_CONF: dict = {} - +_cache: dict = dict() class Bittrex(Exchange): """ @@ -22,6 +22,7 @@ class Bittrex(Exchange): BASE_URL: str = 'https://www.bittrex.com' PAIR_DETAIL_METHOD: str = BASE_URL + '/Market/Index' + def __init__(self, config: dict) -> None: global _API, _API_V2, _EXCHANGE_CONF @@ -98,6 +99,7 @@ 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' @@ -105,9 +107,27 @@ class Bittrex(Exchange): interval = 'fiveMin' else: raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval)) - - data = _API_V2.get_candles(pair.replace('_', '-'), interval) - + if pair in _cache.keys(): + # pair is in cache retriev lastest candle + sdata = _API_V2.get_latest_candle(pair.replace('_', '-'), interval) + if not sdata.get('result'): + raise ContentDecodingError('{message} params=({pair})'.format( + message='Got invalid response from bittrex', + pair=pair)) + data = _cache[pair] + #this is the latest results we had + old_ticker = data['result'][-1]; + #check timestamp is newer ... + if (sdata['result'][0]['T'] > old_ticker['T']) : + data['result'].append(sdata['result'][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] + else : + data = _API_V2.get_candles(pair.replace('_', '-'), interval) + # Update the value in cache + _cache[pair] = data # These sanity check are necessary because bittrex cannot keep their API stable. if not data.get('result'): raise ContentDecodingError('{message} params=({pair})'.format(